~maas-committers/maas/trunk

« back to all changes in this revision

Viewing changes to src/maastesting/yui3.py

  • Committer: Blake Rouse
  • Date: 2017-06-22 18:36:11 UTC
  • Revision ID: blake.rouse@canonical.com-20170622183611-8dgbwu0rejwqn3vs
Remove all code from the bzr branch. Document that Git should be used instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012-2015 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Helpers for dealing with YUI3."""
5
 
 
6
 
__all__ = [
7
 
    "extract_tests",
8
 
    "gen_failed_test_messages",
9
 
    "get_failed_tests_message",
10
 
    ]
11
 
 
12
 
 
13
 
def extract_tests(results):
14
 
    """Extract tests from a YUI3 test result object.
15
 
 
16
 
    See `TestSuite-Level Events`_ for details of the test result object form.
17
 
 
18
 
    .. _TestSuite-Level Events:
19
 
      http://yuilibrary.com/yui/docs/test/#testsuite-level-events
20
 
 
21
 
    """
22
 
    accumulator = {}
23
 
    _extract_tests(results, accumulator)
24
 
    return accumulator
25
 
 
26
 
 
27
 
def _extract_tests(results, accumulator, *stack):
28
 
    """Helper for `extract_tests`."""
29
 
    if isinstance(results, dict):
30
 
        if results["type"] == "test":
31
 
            name = ".".join(reversed(stack))
32
 
            accumulator[name] = results
33
 
        else:
34
 
            for name, value in results.items():
35
 
                _extract_tests(value, accumulator, name, *stack)
36
 
 
37
 
 
38
 
def gen_failed_test_messages(results):
39
 
    """Yield test failure messages from the given results.
40
 
 
41
 
    @param results: See `extract_tests`.
42
 
    """
43
 
    for name, test in extract_tests(results).items():
44
 
        if test["result"] != "pass":
45
 
            yield "%s: %s" % (name, test["message"])
46
 
 
47
 
 
48
 
def get_failed_tests_message(results):
49
 
    """Return a complete error message for the given results.
50
 
 
51
 
    @param results: See `extract_tests`.
52
 
    """
53
 
    messages = gen_failed_test_messages(results)
54
 
    return "\n\n".join(sorted(messages))