17
17
"""Filter a subunit stream to get aggregate statistics."""
19
from optparse import OptionParser
21
from subunit.filters import run_filter_script
23
from subunit import DiscardStream, ProtocolTestCase
25
24
from junitxml import JUnitXmlResult
26
25
except ImportError:
28
27
"http://pypi.python.org/pypi/junitxml) is required for this filter.")
31
parser = OptionParser(description=__doc__)
32
parser.add_option("--no-passthrough", action="store_true",
33
help="Hide all non subunit input.", default=False, dest="no_passthrough")
34
parser.add_option("-o", "--output-to",
35
help="Output the XML to this path rather than stdout.")
36
parser.add_option("-f", "--forward", action="store_true", default=False,
37
help="Forward subunit stream on stdout.")
38
(options, args) = parser.parse_args()
39
if options.output_to is None:
40
output_to = sys.stdout
42
output_to = file(options.output_to, 'wb')
44
result = JUnitXmlResult(output_to)
45
if options.no_passthrough:
46
passthrough_stream = DiscardStream()
48
passthrough_stream = None
50
forward_stream = sys.stdout
53
test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream,
54
forward=forward_stream)
59
if options.output_to is not None:
61
if result.wasSuccessful():
31
run_filter_script(JUnitXmlResult, __doc__)