From dbc0c6cbbd7f6cc6a3b2bb617525e6f16b817359 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 11 Feb 2014 13:38:15 +1300 Subject: * When list-tests encounters an error, a much clearer response will now be shown. (Robert Collins, #1271133) --- NEWS | 3 +++ testrepository/results.py | 26 +++++++++++++++++++++++++- testrepository/testcommand.py | 13 ++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index e17b622..17b92aa 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ CHANGES * ``run`` was outputting bad MIME types - test/plain, not text/plain. (Robert Collins) +* When list-tests encounters an error, a much clearer response will + now be shown. (Robert Collins, #1271133) + 0.0.18 ++++++ diff --git a/testrepository/results.py b/testrepository/results.py index ed01856..2babcb0 100644 --- a/testrepository/results.py +++ b/testrepository/results.py @@ -13,7 +13,11 @@ # limitations under that license. -from testtools import StreamSummary +import subunit +from testtools import ( + StreamSummary, + StreamResult, + ) from testrepository.utils import timedelta_to_seconds @@ -47,3 +51,23 @@ class SummarizingResult(StreamSummary): if None in (self._last_time, self._first_time): return None return timedelta_to_seconds(self._last_time - self._first_time) + + +#XXX: Should be in testtools. +class CatFiles(StreamResult): + """Cat file attachments received to a stream.""" + + def __init__(self, byte_stream): + self.stream = subunit.make_stream_binary(byte_stream) + self.last_file = None + + 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 None: + return + if self.last_file != file_name: + self.stream.write(("--- %s ---\n" % file_name).encode('utf8')) + self.last_file = file_name + self.stream.write(file_bytes) + self.stream.flush() diff --git a/testrepository/testcommand.py b/testrepository/testcommand.py index 267f4ef..f2d51ef 100644 --- a/testrepository/testcommand.py +++ b/testrepository/testcommand.py @@ -14,10 +14,14 @@ """The test command that test repository knows how to run.""" -from extras import try_imports +from extras import ( + try_import, + try_imports, + ) from collections import defaultdict ConfigParser = try_imports(['ConfigParser', 'configparser']) +import io import itertools import operator import os.path @@ -29,7 +33,9 @@ import multiprocessing from textwrap import dedent from fixtures import Fixture +v2 = try_import('subunit.v2') +from testrepository import results from testrepository.testlist import ( parse_enumeration, write_list, @@ -294,6 +300,11 @@ class TestListingFixture(Fixture): stdout=subprocess.PIPE, stdin=subprocess.PIPE) out, err = run_proc.communicate() if run_proc.returncode != 0: + if v2 is not None: + new_out = io.BytesIO() + v2.ByteStreamToStreamResult(io.BytesIO(out), 'stdout').run( + results.CatFiles(new_out)) + out = new_out.getvalue() raise ValueError( "Non-zero exit code (%d) from test listing." " stdout=%r, stderr=%r" % (run_proc.returncode, out, err)) -- cgit v1.2.1