From a53caea7a27c8616cabfc2e5bdf91a90e35891d5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 14 Nov 2012 09:47:16 +0100 Subject: subunit: Update to latest upstream version. Autobuild-User(master): Jelmer Vernooij Autobuild-Date(master): Wed Nov 14 12:11:58 CET 2012 on sn-devel-104 --- lib/subunit/filters/subunit-filter | 148 +++++++++++++++++++++-------------- lib/subunit/filters/subunit-notify | 53 ++++--------- lib/subunit/filters/subunit2csv | 23 ++++++ lib/subunit/filters/subunit2junitxml | 42 +--------- 4 files changed, 132 insertions(+), 134 deletions(-) create mode 100755 lib/subunit/filters/subunit2csv (limited to 'lib/subunit/filters') diff --git a/lib/subunit/filters/subunit-filter b/lib/subunit/filters/subunit-filter index 7f5620f151..6a1ecc9a01 100755 --- a/lib/subunit/filters/subunit-filter +++ b/lib/subunit/filters/subunit-filter @@ -36,41 +36,59 @@ from subunit import ( TestProtocolClient, read_test_list, ) -from subunit.test_results import TestResultFilter - -parser = OptionParser(description=__doc__) -parser.add_option("--error", action="store_false", - help="include errors", default=False, dest="error") -parser.add_option("-e", "--no-error", action="store_true", - help="exclude errors", dest="error") -parser.add_option("--failure", action="store_false", - help="include failures", default=False, dest="failure") -parser.add_option("-f", "--no-failure", action="store_true", - help="exclude failures", dest="failure") -parser.add_option("--passthrough", action="store_false", - help="Show all non subunit input.", default=False, dest="no_passthrough") -parser.add_option("--no-passthrough", action="store_true", - help="Hide all non subunit input.", default=False, dest="no_passthrough") -parser.add_option("-s", "--success", action="store_false", - help="include successes", dest="success") -parser.add_option("--no-success", action="store_true", - help="exclude successes", default=True, dest="success") -parser.add_option("--no-skip", action="store_true", - help="exclude skips", dest="skip") -parser.add_option("--xfail", action="store_false", - help="include expected falures", default=True, dest="xfail") -parser.add_option("--no-xfail", action="store_true", - help="exclude expected falures", default=True, dest="xfail") -parser.add_option("-m", "--with", type=str, - help="regexp to include (case-sensitive by default)", - action="append", dest="with_regexps") -parser.add_option("--fixup-expected-failures", type=str, - help="File with list of test ids that are expected to fail; on failure " - "their result will be changed to xfail; on success they will be " - "changed to error.", dest="fixup_expected_failures", action="append") -parser.add_option("--without", type=str, - help="regexp to exclude (case-sensitive by default)", - action="append", dest="without_regexps") +from subunit.filters import filter_by_result +from subunit.test_results import ( + and_predicates, + make_tag_filter, + TestResultFilter, + ) + + +def make_options(description): + parser = OptionParser(description=__doc__) + parser.add_option("--error", action="store_false", + help="include errors", default=False, dest="error") + parser.add_option("-e", "--no-error", action="store_true", + help="exclude errors", dest="error") + parser.add_option("--failure", action="store_false", + help="include failures", default=False, dest="failure") + parser.add_option("-f", "--no-failure", action="store_true", + help="exclude failures", dest="failure") + parser.add_option("--passthrough", action="store_false", + help="Show all non subunit input.", default=False, dest="no_passthrough") + parser.add_option("--no-passthrough", action="store_true", + help="Hide all non subunit input.", default=False, dest="no_passthrough") + parser.add_option("-s", "--success", action="store_false", + help="include successes", dest="success") + parser.add_option("--no-success", action="store_true", + help="exclude successes", default=True, dest="success") + parser.add_option("--no-skip", action="store_true", + help="exclude skips", dest="skip") + parser.add_option("--xfail", action="store_false", + help="include expected falures", default=True, dest="xfail") + parser.add_option("--no-xfail", action="store_true", + help="exclude expected falures", default=True, dest="xfail") + parser.add_option( + "--with-tag", type=str, + help="include tests with these tags", action="append", dest="with_tags") + parser.add_option( + "--without-tag", type=str, + help="exclude tests with these tags", action="append", dest="without_tags") + parser.add_option("-m", "--with", type=str, + help="regexp to include (case-sensitive by default)", + action="append", dest="with_regexps") + parser.add_option("--fixup-expected-failures", type=str, + help="File with list of test ids that are expected to fail; on failure " + "their result will be changed to xfail; on success they will be " + "changed to error.", dest="fixup_expected_failures", action="append") + parser.add_option("--without", type=str, + help="regexp to exclude (case-sensitive by default)", + action="append", dest="without_regexps") + parser.add_option("-F", "--only-genuine-failures", action="callback", + callback=only_genuine_failures_callback, + help="Only pass through failures and exceptions.") + return parser + def only_genuine_failures_callback(option, opt, value, parser): parser.rargs.insert(0, '--no-passthrough') @@ -78,11 +96,6 @@ def only_genuine_failures_callback(option, opt, value, parser): parser.rargs.insert(0, '--no-skip') parser.rargs.insert(0, '--no-success') -parser.add_option("-F", "--only-genuine-failures", action="callback", - callback=only_genuine_failures_callback, - help="Only pass through failures and exceptions.") - -(options, args) = parser.parse_args() def _compile_re_from_list(l): return re.compile("|".join(l), re.MULTILINE) @@ -97,7 +110,7 @@ def _make_regexp_filter(with_regexps, without_regexps): with_re = with_regexps and _compile_re_from_list(with_regexps) without_re = without_regexps and _compile_re_from_list(without_regexps) - def check_regexps(test, outcome, err, details): + def check_regexps(test, outcome, err, details, tags): """Check if this test and error match the regexp filters.""" test_str = str(test) + outcome + str(err) + str(details) if with_re and not with_re.search(test_str): @@ -108,21 +121,38 @@ def _make_regexp_filter(with_regexps, without_regexps): return check_regexps -regexp_filter = _make_regexp_filter(options.with_regexps, - options.without_regexps) -fixup_expected_failures = set() -for path in options.fixup_expected_failures or (): - fixup_expected_failures.update(read_test_list(path)) -result = TestProtocolClient(sys.stdout) -result = TestResultFilter(result, filter_error=options.error, - filter_failure=options.failure, filter_success=options.success, - filter_skip=options.skip, filter_xfail=options.xfail, - filter_predicate=regexp_filter, - fixup_expected_failures=fixup_expected_failures) -if options.no_passthrough: - passthrough_stream = DiscardStream() -else: - passthrough_stream = None -test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream) -test.run(result) -sys.exit(0) +def _make_result(output, options, predicate): + """Make the result that we'll send the test outcomes to.""" + fixup_expected_failures = set() + for path in options.fixup_expected_failures or (): + fixup_expected_failures.update(read_test_list(path)) + return TestResultFilter( + TestProtocolClient(output), + filter_error=options.error, + filter_failure=options.failure, + filter_success=options.success, + filter_skip=options.skip, + filter_xfail=options.xfail, + filter_predicate=predicate, + fixup_expected_failures=fixup_expected_failures) + + +def main(): + parser = make_options(__doc__) + (options, args) = parser.parse_args() + + regexp_filter = _make_regexp_filter( + options.with_regexps, options.without_regexps) + tag_filter = make_tag_filter(options.with_tags, options.without_tags) + filter_predicate = and_predicates([regexp_filter, tag_filter]) + + filter_by_result( + lambda output_to: _make_result(sys.stdout, options, filter_predicate), + output_path=None, + passthrough=(not options.no_passthrough), + forward=False) + sys.exit(0) + + +if __name__ == '__main__': + main() diff --git a/lib/subunit/filters/subunit-notify b/lib/subunit/filters/subunit-notify index 758e7fc8ff..8cce2d1609 100755 --- a/lib/subunit/filters/subunit-notify +++ b/lib/subunit/filters/subunit-notify @@ -16,50 +16,29 @@ """Notify the user of a finished test run.""" -from optparse import OptionParser -import sys - import pygtk pygtk.require('2.0') import pynotify -from subunit import DiscardStream, ProtocolTestCase, TestResultStats +from subunit import TestResultStats +from subunit.filters import run_filter_script if not pynotify.init("Subunit-notify"): sys.exit(1) -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("-f", "--forward", action="store_true", default=False, - help="Forward subunit stream on stdout.") -(options, args) = parser.parse_args() -result = TestResultStats(sys.stdout) -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) -test.run(result) -if result.failed_tests > 0: - summary = "Test run failed" -else: - summary = "Test run successful" -body = "Total tests: %d; Passed: %d; Failed: %d" % ( - result.total_tests, - result.passed_tests, - result.failed_tests, + +def notify_of_result(result): + if result.failed_tests > 0: + summary = "Test run failed" + else: + summary = "Test run successful" + body = "Total tests: %d; Passed: %d; Failed: %d" % ( + result.total_tests, + result.passed_tests, + result.failed_tests, ) -nw = pynotify.Notification(summary, body) -nw.show() + nw = pynotify.Notification(summary, body) + nw.show() + -if result.wasSuccessful(): - exit_code = 0 -else: - exit_code = 1 -sys.exit(exit_code) +run_filter_script(TestResultStats, __doc__, notify_of_result) diff --git a/lib/subunit/filters/subunit2csv b/lib/subunit/filters/subunit2csv new file mode 100755 index 0000000000..14620ff674 --- /dev/null +++ b/lib/subunit/filters/subunit2csv @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# subunit: extensions to python unittest to get test results from subprocesses. +# Copyright (C) 2009 Robert Collins +# +# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause +# license at the users choice. A copy of both licenses are available in the +# project source as Apache-2.0 and BSD. You may not use this file except in +# compliance with one of these two licences. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under these licenses is d on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# license you chose for the specific language governing permissions and +# limitations under that license. +# + +"""Turn a subunit stream into a CSV""" + +from subunit.filters import run_filter_script +from subunit.test_results import CsvResult + + +run_filter_script(CsvResult, __doc__) diff --git a/lib/subunit/filters/subunit2junitxml b/lib/subunit/filters/subunit2junitxml index bea795d2bd..d568c71dd4 100755 --- a/lib/subunit/filters/subunit2junitxml +++ b/lib/subunit/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 run_filter_script -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) + +run_filter_script(JUnitXmlResult, __doc__) -- cgit