diff options
| author | Jonathan Lange <jml@mumak.net> | 2012-03-27 11:52:50 +0100 |
|---|---|---|
| committer | Jonathan Lange <jml@mumak.net> | 2012-03-27 11:52:50 +0100 |
| commit | efa4dc4ef3965c2b9b8d9867e9a80def71e452cd (patch) | |
| tree | 178cad5309c91125ff9b25a9a732f9905867af00 | |
| parent | 273101fd8d7abf9cd492df4c2c6c5b17c83cce99 (diff) | |
| download | subunit-git-efa4dc4ef3965c2b9b8d9867e9a80def71e452cd.tar.gz | |
Factor out JUnitXML
| -rwxr-xr-x | filters/subunit2csv | 6 | ||||
| -rwxr-xr-x | filters/subunit2junitxml | 42 | ||||
| -rw-r--r-- | python/subunit/filters.py | 16 |
3 files changed, 13 insertions, 51 deletions
diff --git a/filters/subunit2csv b/filters/subunit2csv index 74b7944..0357b1d 100755 --- a/filters/subunit2csv +++ b/filters/subunit2csv @@ -14,14 +14,10 @@ # limitations under that license. # -# XXX: This is almost exactly the same as subunit2junitxml. The only -# difference is that we instantiate 'CsvResult' rather than 'JUnitXmlResult'. -# Consider factoring this out into a common script helper. - """Turn a subunit stream into a CSV""" from subunit.filters import main from subunit.test_results import CsvResult -main(CsvResult) +main(CsvResult, __doc__) diff --git a/filters/subunit2junitxml b/filters/subunit2junitxml index bea795d..18d170e 100755 --- a/filters/subunit2junitxml +++ b/filters/subunit2junitxml @@ -16,11 +16,10 @@ """Filter a subunit stream to get aggregate statistics.""" -from optparse import OptionParser + import sys -import unittest +from subunit.filters import main -from subunit import DiscardStream, ProtocolTestCase try: from junitxml import JUnitXmlResult except ImportError: @@ -28,38 +27,5 @@ except ImportError: "http://pypi.python.org/pypi/junitxml) is required for this filter.") raise -parser = OptionParser(description=__doc__) -parser.add_option("--no-passthrough", action="store_true", - help="Hide all non subunit input.", default=False, dest="no_passthrough") -parser.add_option("-o", "--output-to", - help="Output the XML to this path rather than stdout.") -parser.add_option("-f", "--forward", action="store_true", default=False, - help="Forward subunit stream on stdout.") -(options, args) = parser.parse_args() -if options.output_to is None: - output_to = sys.stdout -else: - output_to = file(options.output_to, 'wb') -try: - result = JUnitXmlResult(output_to) - if options.no_passthrough: - passthrough_stream = DiscardStream() - else: - passthrough_stream = None - if options.forward: - forward_stream = sys.stdout - else: - forward_stream = None - test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream, - forward=forward_stream) - result.startTestRun() - test.run(result) - result.stopTestRun() -finally: - if options.output_to is not None: - output_to.close() -if result.wasSuccessful(): - exit_code = 0 -else: - exit_code = 1 -sys.exit(exit_code) + +main(JUnitXmlResult, __doc__) diff --git a/python/subunit/filters.py b/python/subunit/filters.py index ac05af9..0bab9ed 100644 --- a/python/subunit/filters.py +++ b/python/subunit/filters.py @@ -21,11 +21,12 @@ from subunit import DiscardStream, ProtocolTestCase from subunit.test_results import CsvResult -def make_options(): - parser = OptionParser(description=__doc__) +def make_options(description): + parser = OptionParser(description=description) parser.add_option( "--no-passthrough", action="store_true", - help="Hide all non subunit input.", default=False, dest="no_passthrough") + help="Hide all non subunit input.", default=False, + dest="no_passthrough") parser.add_option( "-o", "--output-to", help="Output the XML to this path rather than stdout.") @@ -95,8 +96,7 @@ def filter_by_result(result_factory, output_path, no_passthrough, forward, try: result = result_factory(output_to) was_successful = run_tests_from_stream( - input_stream, result, output_to, passthrough_stream, - forward_stream) + input_stream, result, passthrough_stream, forward_stream) finally: if output_path: output_to.close() @@ -106,10 +106,10 @@ def filter_by_result(result_factory, output_path, no_passthrough, forward, return 1 -def main(result_factory): - parser = make_options() +def main(result_factory, description): + parser = make_options(description) (options, args) = parser.parse_args() sys.exit( filter_by_result( - CsvResult, options.output_to, options.no_passthrough, + result_factory, options.output_to, options.no_passthrough, options.forward)) |
