[Piglit] [PATCH 2/4] framework/backends/junit.py: Split _set_xml_err method
Dylan Baker
dylan at pnwbakers.com
Fri Aug 5 00:02:40 UTC 2016
This method had multiple side effects and a return, this was
non-optimal, but it did reduce some if treeing. But to write a good
subtest handler class this needs to be split into two separate methods.
---
framework/backends/junit.py | 50 ++++++++++++++++++++++----------------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/framework/backends/junit.py b/framework/backends/junit.py
index cc9675e..d1b77d0 100644
--- a/framework/backends/junit.py
+++ b/framework/backends/junit.py
@@ -87,41 +87,57 @@ class JUnitWriter(object):
err.text = data.err
err.text += '\n\npid: {}\nstart time: {}\nend time: {}\n'.format(
data.pid, data.time.start, data.time.end)
- res = None
if data.result in ['fail', 'dmesg-warn', 'dmesg-fail']:
if expected_result == "failure":
err.text += "\n\nWARN: passing test as an expected failure"
- res = etree.SubElement(element, 'skipped',
- message='expected failure')
elif expected_result == 'error':
err.text += \
"\n\nERROR: Test should have been crash but was failure"
+ elif data.result in ['crash', 'timeout']:
+ if expected_result == "error":
+ err.text += "\n\nWARN: passing test as an expected crash"
+ elif expected_result == 'failure':
+ err.text += \
+ "\n\nERROR: Test should have been failure but was crash"
+ elif expected_result != "pass":
+ err.text += "\n\nERROR: This test passed when it "\
+ "expected {0}".format(expected_result)
+
+ @staticmethod
+ def _make_result(element, result, expected_result):
+ """Adds the skipped, failure, or error element."""
+ res = None
+ if result in ['fail', 'dmesg-warn', 'dmesg-fail']:
+ if expected_result == "failure":
+ res = etree.SubElement(element, 'skipped',
+ message='expected failure')
+ elif expected_result == 'error':
res = etree.SubElement(element, 'failure',
message='expected crash, but got '
'failure')
else:
res = etree.SubElement(element, 'failure')
- elif data.result in ['crash', 'timeout']:
+ elif result in ['crash', 'timeout']:
if expected_result == "error":
- err.text += "\n\nWARN: passing test as an expected crash"
res = etree.SubElement(element, 'skipped',
message='expected crash')
elif expected_result == 'failure':
- err.text += \
- "\n\nERROR: Test should have been failure but was crash"
res = etree.SubElement(element, 'error',
message='expected failure, but got '
'error')
else:
res = etree.SubElement(element, 'error')
-
elif expected_result != "pass":
- err.text += "\n\nERROR: This test passed when it "\
- "expected {0}".format(expected_result)
res = etree.SubElement(element, 'failure')
+ # Add relevant result value, if the result is pass then it doesn't
+ # need one of these statuses
+ elif result == 'skip':
+ res = etree.SubElement(element, 'skipped')
- return res
+ # Add the piglit type to the failure result
+ if res is not None:
+ res.attrib['type'] = six.text_type(result)
def __call__(self, f, name, data):
classname, testname = self._make_names(name)
@@ -161,7 +177,7 @@ class JUnitWriter(object):
if lname in self._expected_crashes:
expected_result = "error"
- res = self._set_xml_err(element, data, expected_result)
+ self._set_xml_err(element, data, expected_result)
# Add stdout
out = etree.SubElement(element, 'system-out')
@@ -170,15 +186,7 @@ class JUnitWriter(object):
# Prepend command line to stdout
out.text = data.command + '\n' + out.text
- res = None
- # Add relevant result value, if the result is pass then it doesn't
- # need one of these statuses
- if data.result == 'skip':
- res = etree.SubElement(element, 'skipped')
-
- # Add the piglit type to the failure result
- if res is not None:
- res.attrib['type'] = str(data.result)
+ self._make_result(element, data.result, expected_result)
else:
etree.SubElement(element, 'failure', message='Incomplete run.')
--
git-series 0.8.7
More information about the Piglit
mailing list