from optparse import OptionParser
import sys
-from subunit import DiscardStream, ProtocolTestCase
+from testtools import StreamToExtendedDecorator, StreamResultRouter
+
+from subunit import ByteStreamToStreamResult
+from subunit.filters import run_tests_from_stream
from subunit.test_results import (
- AutoTimingTestResultDecorator,
+ CatFiles,
TestIdPrintingResult,
)
parser.add_option("--no-passthrough", action="store_true",
help="Hide all non subunit input.", default=False, dest="no_passthrough")
(options, args) = parser.parse_args()
-result = AutoTimingTestResultDecorator(
- TestIdPrintingResult(sys.stdout, options.times))
-if options.no_passthrough:
- passthrough_stream = DiscardStream()
+test = ByteStreamToStreamResult(sys.stdin, non_subunit_name="stdout")
+printer = TestIdPrintingResult(sys.stdout, options.times)
+result = StreamToExtendedDecorator(printer)
+if not options.no_passthrough:
+ orig_result = result
+ result = StreamResultRouter(result)
+ cat = CatFiles(sys.stdout)
+ result.map(cat, 'test_id', test_id=None)
else:
- passthrough_stream = None
-test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
+ orig_result = result
+orig_result.startTestRun()
test.run(result)
-if result.wasSuccessful():
+orig_result.stopTestRun()
+if printer.wasSuccessful():
exit_code = 0
else:
exit_code = 1
text_content,
TracebackContent,
)
+from testtools import StreamResult
from subunit import iso8601
+import subunit
# NOT a TestResult, because we are implementing the interface, not inheriting
def startTestRun(self):
super(CsvResult, self).startTestRun()
self._write_row(['test', 'status', 'start_time', 'stop_time'])
+
+
+class CatFiles(StreamResult):
+ """Cat file attachments received to a stream."""
+
+ def __init__(self, byte_stream):
+ self.stream = subunit.make_stream_binary(byte_stream)
+
+ def status(self, test_id=None, test_status=None, test_tags=None,
+ runnable=True, file_name=None, file_bytes=None, eof=False,
+ mime_type=None, route_code=None, timestamp=None):
+ if file_name is not None:
+ self.stream.write(file_bytes)