diff options
| author | Robert Collins <robertc@robertcollins.net> | 2013-03-04 00:42:05 +1300 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2013-03-04 00:42:05 +1300 |
| commit | 22ea5b6a1f0e008f449c5984e215a53073b8dbfe (patch) | |
| tree | f005e51da505f4b40ad673d1d5004a6be5a51fb3 /python | |
| parent | 7444588c895e2dc3946d6ca3e6650d4549cd4d43 (diff) | |
| download | subunit-git-22ea5b6a1f0e008f449c5984e215a53073b8dbfe.tar.gz | |
Fix up buffering to make pdb usable.
Diffstat (limited to 'python')
| -rwxr-xr-x | python/subunit/run.py | 4 | ||||
| -rw-r--r-- | python/subunit/test_results.py | 1 | ||||
| -rw-r--r-- | python/subunit/v2.py | 22 |
3 files changed, 24 insertions, 3 deletions
diff --git a/python/subunit/run.py b/python/subunit/run.py index 479691d..2e07d86 100755 --- a/python/subunit/run.py +++ b/python/subunit/run.py @@ -20,6 +20,7 @@ $ python -m subunit.run mylib.tests.test_suite """ +import os import sys from testtools import ExtendedToStreamDecorator @@ -84,6 +85,9 @@ class SubunitTestProgram(TestProgram): if __name__ == '__main__': + # Disable the default buffering, for Python 2.x where pdb doesn't do it + # on non-ttys. + sys.stdout = os.fdopen(sys.stdout.fileno(), 'ab', 0) stream = get_default_formatter() runner = SubunitTestRunner SubunitTestProgram(module=None, argv=sys.argv, testRunner=runner, diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index 7d60962..c9c7681 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -691,3 +691,4 @@ class CatFiles(StreamResult): mime_type=None, route_code=None, timestamp=None): if file_name is not None: self.stream.write(file_bytes) + self.stream.flush() diff --git a/python/subunit/v2.py b/python/subunit/v2.py index 89a2e72..34ab838 100644 --- a/python/subunit/v2.py +++ b/python/subunit/v2.py @@ -16,6 +16,7 @@ import datetime from io import UnsupportedOperation +import os import select import struct import zlib @@ -24,6 +25,7 @@ import subunit import subunit.iso8601 as iso8601 __all__ = [ + 'ByteStreamToStreamResult', 'StreamResultToBytes', ] @@ -222,15 +224,29 @@ class ByteStreamToStreamResult(object): # Won't be able to select, fallback to # one-byte-at-a-time. break - readable = select.select([self.source], [], [], 0.050)[0] + # Note: this has a very low timeout because with stdin, the + # BufferedIO layer typically has all the content available + # from the stream when e.g. pdb is dropped into, leading to + # select always timing out when in fact we could have read + # (from the buffer layer) - we typically fail to aggregate + # any content on 3.x Pythons. + readable = select.select([self.source], [], [], 0.000001)[0] if readable: - buffered.append(self.source.read(1)) + content = self.source.read(1) + if len(content) and content[0] != SIGNATURE[0]: + buffered.append(content) + else: + # EOF or we hit a new packet. + break if not readable or len(buffered) >= 1048576: break result.status( file_name=self.non_subunit_name, file_bytes=b''.join(buffered)) - continue + if not len(content) or content[0] != SIGNATURE[0]: + continue + # Fall through to process the packet whose first byte is in + # content. try: packet = [SIGNATURE] self._parse(packet, result) |
