[Piglit] [PATCH 08/26] framework/summary.py: split diff generating code into toplevel function
Dylan Baker
baker.dylan.c at gmail.com
Fri Sep 11 15:55:34 PDT 2015
This is groundwork for later patches in this series.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/summary.py | 26 +++++++++++++++++---------
framework/tests/summary_tests.py | 21 ++++++++++++++++++++-
2 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/framework/summary.py b/framework/summary.py
index 14c502d..985ee3d 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -612,15 +612,8 @@ class Summary:
def change_printer(func):
counts = [''] # There can't be changes from nil -> 0
- for prev, cur in itertools.izip(self.results[:-1], self.results[1:]):
- count = 0
- for name in self.tests['all']:
- try:
- if func(prev.tests[name].result, cur.tests[name].result):
- count += 1
- except KeyError:
- pass
- counts.append(str(count))
+ counts.extend([str(len(e)) for e in find_diffs(
+ self.results, self.tests['all'], func)])
return print_template.format(*counts)
print(template.format(
@@ -653,3 +646,18 @@ class Summary:
printer(self.tests['incomplete'])
elif mode == 'summary':
print_summary()
+
+
+def find_diffs(results, tests, comparator):
+ """Generate diffs between two or more sets of results."""
+ diffs = []
+ for prev, cur in itertools.izip(results[:-1], results[1:]):
+ names = set()
+ for name in tests:
+ try:
+ if comparator(prev.tests[name].result, cur.tests[name].result):
+ names.add(name)
+ except KeyError:
+ pass
+ diffs.append(names)
+ return diffs
diff --git a/framework/tests/summary_tests.py b/framework/tests/summary_tests.py
index 51ec392..94fbbc6 100644
--- a/framework/tests/summary_tests.py
+++ b/framework/tests/summary_tests.py
@@ -30,7 +30,7 @@ except ImportError:
import json
import nose.tools as nt
-import framework.summary as summary
+from framework import summary, results
import framework.tests.utils as utils
from framework.backends.json import piglit_encoder
@@ -125,3 +125,22 @@ class TestSubtestHandling(object):
def subtest_not_skip_notrun(self):
"""summary.Summary: skips are not changed to notruns"""
nt.eq_(self.summ.status['fake-tests']['is_skip'], 'skip')
+
+
+def test_find_diffs_():
+ """summary.find_diffs: calculates correct set of diffs"""
+ res1 = results.TestrunResult()
+ res1.tests['foo'] = results.TestResult('pass')
+ res1.tests['bar'] = results.TestResult('fail')
+ res1.tests['oink'] = results.TestResult('crash')
+ res1.tests['bonk'] = results.TestResult('warn')
+
+ res2 = results.TestrunResult()
+ res2.tests['foo'] = results.TestResult('fail')
+ res2.tests['bar'] = results.TestResult('pass')
+ res2.tests['oink'] = results.TestResult('crash')
+
+ diffs = summary.find_diffs([res1, res2],
+ {'foo', 'bar', 'oink', 'bonk'},
+ lambda x, y: x != y)
+ nt.eq_(diffs, [{'foo', 'bar'}])
--
2.5.1
More information about the Piglit
mailing list