Update subunit-ls.
authorRobert Collins <robertc@robertcollins.net>
Wed, 27 Feb 2013 10:30:53 +0000 (23:30 +1300)
committerRobert Collins <robertc@robertcollins.net>
Wed, 27 Feb 2013 10:30:53 +0000 (23:30 +1300)
filters/subunit-ls
python/subunit/filters.py
python/subunit/test_results.py

index 82db4c371ac1e820472d6869c60c86ee549d5815..912bc8085b8103a88e33db526266d8cfe3c9fe20 100755 (executable)
 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,
     )
 
@@ -33,15 +36,20 @@ parser.add_option("--times", action="store_true",
 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
index 208bd8b728af95bdaf4e72d7b1314fdb997593e3..be3b6b8076f4ec2f6fa38b03869f7c33dc9330ad 100644 (file)
@@ -102,7 +102,7 @@ def filter_by_result(result_factory, output_path, passthrough, forward,
     :param input_stream: The source of subunit input.  Defaults to
         ``sys.stdin``.
     :param protocol_version: The subunit protocol version to expect.
-    :return: A test result with the resultts of the run.
+    :return: A test result with the results of the run.
     """
     if passthrough:
         passthrough_stream = sys.stdout
index 91c9bbdc1e4219e21957bd39e16a6c0e06043925..7d609629b79dea1acaafb0df25b19b6553091fee 100644 (file)
@@ -25,8 +25,10 @@ from testtools.content import (
     text_content,
     TracebackContent,
     )
+from testtools import StreamResult
 
 from subunit import iso8601
+import subunit
 
 
 # NOT a TestResult, because we are implementing the interface, not inheriting
@@ -676,3 +678,16 @@ class CsvResult(TestByTestResult):
     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)