~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/__init__.py

  • Committer: Curtis Hovey
  • Date: 2011-06-07 17:15:05 UTC
  • mto: This revision was merged to the branch mainline in revision 13229.
  • Revision ID: curtis.hovey@canonical.com-20110607171505-sd0ortosvmwhu501
Use iterate over the json-dict to report the test results.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
import time
75
75
import unittest
76
76
 
 
77
import simplejson
 
78
 
77
79
import html5browser
78
80
 
79
81
from bzrlib import trace
939
941
        page = client.load_page(html_path)
940
942
        if page.return_code == page.CODE_FAIL:
941
943
            return
942
 
        markup = page.content
 
944
        # Data is a dict (type=report)
 
945
        # with 1 or more dicts (type=testcase)
 
946
        # with 1 for more dicts (type=test).
 
947
        report = simplejson.loads(page.content)
 
948
        if report.get('type', None) != 'complete':
 
949
            # Did not get a report back.
 
950
            return
943
951
        self._yui_results = {}
944
 
        # Maybe testing.pages should move to lp to avoid circular imports.
945
 
        from canonical.launchpad.testing.pages import find_tags_by_class
946
 
        entries = find_tags_by_class(
947
 
            markup, 'yui3-console-entry-TestRunner')
948
 
        for entry in entries:
949
 
            category = entry.find(
950
 
                attrs={'class': 'yui3-console-entry-cat'})
951
 
            if category is None:
952
 
                continue
953
 
            result = category.string
954
 
            if result not in ('pass', 'fail'):
955
 
                continue
956
 
            message = entry.pre.string
957
 
            test_name, ignore = message.split(':', 1)
958
 
            self._yui_results[test_name] = dict(
959
 
                result=result, message=message)
 
952
        for key, value in report['results'].items():
 
953
            if isinstance(value, dict) and value['type'] == 'testcase':
 
954
                testcase_name = key
 
955
                test_case = value
 
956
                for key, value in test_case.items():
 
957
                    if isinstance(value, dict) and value['type'] == 'test':
 
958
                        test_name = '%s.%s' % (testcase_name, key)
 
959
                        test = value
 
960
                        self._yui_results[test_name] = dict(
 
961
                            result=test['result'], message=test['message'])
960
962
 
961
963
    def checkResults(self):
962
964
        """Check the results.