This adds code in framework/summary.py and framework/core.py to make use of the status classes in status.py. This makes comparisons between statuses much simpler and cleaner
Signed-off-by: Dylan Baker <[email protected]> --- framework/core.py | 18 ++++++++++- framework/summary.py | 85 +++++++++++++--------------------------------------- 2 files changed, 38 insertions(+), 65 deletions(-) diff --git a/framework/core.py b/framework/core.py index 150a70c..24b2145 100644 --- a/framework/core.py +++ b/framework/core.py @@ -39,6 +39,7 @@ from textwrap import dedent from threads import ConcurrentTestPool from threads import synchronized_self import threading +import status __all__ = ['Environment', 'checkDir', @@ -211,7 +212,22 @@ if 'PIGLIT_SOURCE_DIR' not in os.environ: class TestResult(dict): - pass + def __init__(self, *args): + dict.__init__(self, *args) + + # Replace the result with a status object + if self['result'] == 'skip': + self['result'] = status.Skip() + elif self['result'] == 'pass': + self['result'] = status.Pass() + elif self['result'] == 'warn': + self['result'] = status.Fail() + elif self['result'] == 'crash': + self['result'] = status.Warn() + elif self['result'] == 'fail': + self['result'] = status.Crash() + else: + raise KeyError class GroupResult(dict): diff --git a/framework/summary.py b/framework/summary.py index 1cdbab7..8ae7796 100644 --- a/framework/summary.py +++ b/framework/summary.py @@ -28,6 +28,7 @@ from json import loads from mako.template import Template import core +from status import Skip, Pass, Warn, Fail, Crash __all__ = [ 'Summary', @@ -290,7 +291,7 @@ class Summary: # Since skip is the "lowest" status for HTML generation, if # there is another status it will replace skip - currentStatus.append('skip') + currentStatus.append(Skip()) def closeGroup(group_name): # We're done with this group, record the number of pass/total @@ -304,32 +305,10 @@ class Summary: stack[-1] = (parent_pass + nr_pass, parent_total + nr_total) # Add the status back to the group hierarchy - if status_to_number(currentStatus[-2]) < \ - status_to_number(currentStatus[-1]): + if currentStatus[-2] < currentStatus[-1]: currentStatus[-2] = currentStatus[-1] status[group_name] = currentStatus.pop() - def status_to_number(status): - """ - like status_to_number in the constructor, this function - converts statuses into numbers so they can be comapared - logically/mathematically. The only difference between this and - init::status_to_number is the values assigned. The reason for - this is that here we are looking for the 'worst' status, while - in init::status_to_number we are looking for regressions in - status. - """ - if status == 'skip': - return 1 - elif status == 'pass': - return 2 - elif status == 'warn': - return 3 - elif status == 'fail': - return 4 - elif status == 'crash': - return 5 - openGroup('fake') openGroup('all') @@ -354,15 +333,14 @@ class Summary: # Add the current test (pass_so_far, total_so_far) = stack[-1] - if summary.tests[fulltest]['result'] == 'pass': + if summary.tests[fulltest]['result'] == 2: pass_so_far += 1 - if summary.tests[fulltest]['result'] != 'skip': + if summary.tests[fulltest]['result'] != 1: total_so_far += 1 stack[-1] = (pass_so_far, total_so_far) # compare the status - if status_to_number(summary.tests[fulltest]['result']) > \ - status_to_number(currentStatus[-1]): + if summary.tests[fulltest]['result'] > currentStatus[-1]: currentStatus[-1] = summary.tests[fulltest]['result'] # Work back up the stack closing groups as we go until we reach the @@ -411,60 +389,39 @@ class Summary: file is provided), and for JUnit and text which only need a limited subset of these lists """ - def find_regressions(status): - """ - Helper function to convert named statuses into number, since number - can more easily be compared using logical/mathematical operators. - The use of this is to look for regressions in status. - """ - if status == 'pass': - return 1 - elif status == 'warn': - return 2 - elif status == 'fail': - return 3 - elif status == 'skip': - return 4 - elif status == 'crash': - return 5 - elif status == 'special': - return 0 - for test in self.tests['all']: status = [] for each in self.results: try: - status.append(find_regressions(each.tests[test]['result'])) + status.append(each.tests[test]['result']) except KeyError: - status.append(find_regressions("special")) + status.append(0) if 'changes' in lists: # Check and append self.tests['changes'] - # A set cannot contain duplicate entries, so creating a set - # out the list will reduce it's length to 1 if all entries - # are the same, meaning it is not a change - if len(set(status)) > 1: - self.tests['changes'].append(test) + for i in xrange(len(status) -1): + if status[i] != status[i +1]: + self.tests['changes'].append(test) if 'problems' in lists: - # If the result contains a value other than 1 (pass) or 4 + # If the result contains a value other than 2 (pass) or 1 # (skip) it is a problem. Skips are not problems becasuse # they have Their own page. - if [i for e in [2, 3, 5] for i in status if e is i]: + if [i for i in status if i not in [Pass(), Skip()]]: self.tests['problems'].append(test) if 'skipped' in lists: # Find all tests with a status of skip - if 4 in status: + if Skip() in status: self.tests['skipped'].append(test) if 'fixes' in lists: # Find both fixes and regressions, and append them to the # proper lists for i in xrange(len(status) - 1): - if status[i] < status[i + 1] and status[i] != 0: + if status[i] == Pass() and status[i + 1] != Pass(): self.tests['regressions'].append(test) - if status[i] > 1 and status[i + 1] == 1: + if status[i] != Pass() and status[i + 1] == Pass(): self.tests['fixes'].append(test) # Remove duplicate entries from the status lists @@ -483,7 +440,7 @@ class Summary: self.totals = {'pass': 0, 'fail': 0, 'crash': 0, 'skip': 0, 'warn': 0} for test in self.results[-1].tests.values(): - self.totals[test['result']] += 1 + self.totals[str(test['result'])] += 1 def generateHTML(self, destination, exclude): """ @@ -610,13 +567,13 @@ class Summary: if diff: for test in self.tests['changes']: print "%(test)s: %(statuses)s" % {'test': test, 'statuses': - ' '.join([i.tests.get(test, {'result': 'skip'}) - ['result'] for i in self.results])} + ' '.join(map(str, [i.tests.get(test, {'result': Skip()}) + ['result'] for i in self.results]))} else: for test in self.tests['all']: print "%(test)s: %(statuses)s" % {'test': test, 'statuses': - ' '.join([i.tests.get(test, {'result': 'skip'}) - ['result'] for i in self.results])} + ' '.join(map(str, [i.tests.get(test, {'result': Skip()}) + ['result'] for i in self.results]))} # Print the summary print "summary:" -- 1.8.1.5 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
