From a0792fddc02e2565ac33d1521c2d355a2e0023f4 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 8 Apr 2013 18:07:51 -0700 Subject: [PATCH] Make subunit2html compatible with subunit>=0.0.11. * modules/jenkins/files/slave_scripts/subunit2html.py: Python subunit ByteStreamToStreamResult takes an argument of non_subunit_name and not non_subunit_input. Correct the argument name. Use argparse to parse the command line arguments and add a new -2 options that specifies subunit version 2 format logs should be read in. Otherwise read in version 1 subunit format. This commit makes the second file name arg to subunit2html a required argument and it is no longer optional. run-tox.sh already supplies both file name arguments so this shouldn't break Jenkins. Change-Id: I90804d4d12d77a544451c1647a137dc4b3b38f17 Reviewed-on: https://review.openstack.org/26430 Reviewed-by: Jeremy Stanley Reviewed-by: Monty Taylor Approved: James E. Blair Reviewed-by: James E. Blair Tested-by: Jenkins --- .../files/slave_scripts/subunit2html.py | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/modules/jenkins/files/slave_scripts/subunit2html.py b/modules/jenkins/files/slave_scripts/subunit2html.py index 5b59d884a1..b61fdf3c63 100755 --- a/modules/jenkins/files/slave_scripts/subunit2html.py +++ b/modules/jenkins/files/slave_scripts/subunit2html.py @@ -39,8 +39,8 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ +import argparse import datetime -import sys import traceback import unittest from xml.sax import saxutils @@ -690,25 +690,28 @@ class HtmlOutput(unittest.TestResult): def main(): - if len(sys.argv) < 2: - print "Need at least one argument: path to subunit log." - exit(1) - subunit_file = sys.argv[1] - if len(sys.argv) > 2: - html_file = sys.argv[2] - else: - html_file = 'results.html' + parser = argparse.ArgumentParser() + parser.add_argument("subunit_file", + help="Path to input subunit file.") + parser.add_argument("html_file", + help="Path to output html file.") + parser.add_argument("-2", "--subunitv2", action="store_true", + help="Input log file is in subunit version 2 format.") + args = parser.parse_args() - result = HtmlOutput(html_file) - stream = open(subunit_file, 'rb') - try: - # Use subunit v2 if the library supports it. - # NB: This trivial config will not passthrough non-test output - # - a difference to subunit v1's default. - suite = subunit.ByteStreamToStreamResult( - stream, non_subunit_input='stdout') - result = testtools.StreamToExtendedDecorator(result) - except AttributeError: + result = HtmlOutput(args.html_file) + stream = open(args.subunit_file, 'rb') + if args.subunitv2: + try: + # Use subunit v2 if the library supports it. + # NB: This trivial config will not passthrough non-test output + # - a difference to subunit v1's default. + suite = subunit.ByteStreamToStreamResult( + stream, non_subunit_name='stdout') + result = testtools.StreamToExtendedDecorator(result) + except AttributeError: + suite = subunit.ProtocolTestCase(stream) + else: suite = subunit.ProtocolTestCase(stream) result.startTestRun() suite.run(result)