diff options
author | Robert Collins <robertc@robertcollins.net> | 2015-08-04 15:38:46 +1200 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2015-08-04 15:38:46 +1200 |
commit | 201f6f45708bf40e931d578a4460a356e9515cde (patch) | |
tree | eda0abedbafa7bae7c51cd1d0da2556a5045c063 | |
parent | c90fc5d0a74f7bc8a7e0d9c846c2d0f46b97f8d2 (diff) | |
download | subunit-201f6f45708bf40e931d578a4460a356e9515cde.tar.gz |
Handle very short packets
Yay quickcheck.
-rw-r--r-- | INSTALL | 2 | ||||
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | python/subunit/tests/test_test_protocol2.py | 14 | ||||
-rw-r--r-- | python/subunit/v2.py | 6 | ||||
-rwxr-xr-x | setup.py | 4 |
5 files changed, 27 insertions, 3 deletions
@@ -20,6 +20,8 @@ Dependencies * 'testscenarios' (On Debian and Ubuntu systems the 'python-testscenarios' package, the 'testscenarios' package on pypi, or https://launchpad.net/testscenarios) for running some of the python unit tests. +* 'fixtures' for running the Python tests +* 'hypothesis' for running the Python tests. * A C compiler for the C bindings * Perl for the Perl tools (including subunit-diff) * Check to run the subunit test suite. diff --git a/Makefile.am b/Makefile.am index b1c0473..1053348 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,8 +124,10 @@ clean-local: # Remove perl dir for VPATH builds. distclean-local: - -rmdir perl > /dev/null -rm perl/Makefile.PL > /dev/null + -rm perl/MYMETA.json > /dev/null + -rmdir perl > /dev/null + -rm -r .hypothesis > /dev/null install-exec-local: perl/Makefile $(MAKE) -C perl install diff --git a/python/subunit/tests/test_test_protocol2.py b/python/subunit/tests/test_test_protocol2.py index c21392c..9a84a84 100644 --- a/python/subunit/tests/test_test_protocol2.py +++ b/python/subunit/tests/test_test_protocol2.py @@ -17,6 +17,11 @@ from io import BytesIO import datetime +from hypothesis import given +# To debug hypothesis +# from hypothesis import Settings, Verbosity +# Settings.default.verbosity = Verbosity.verbose +import hypothesis.strategies as st from testtools import TestCase from testtools.matchers import Contains, HasLength from testtools.tests.test_testresult import TestStreamResultContract @@ -434,3 +439,12 @@ class TestByteStreamToStreamResult(TestCase): file_bytes=b'foo') self.check_event(content.getvalue(), test_id=None, file_name='bar', route_code='0', mime_type='text/plain', file_bytes=b'foo') + + @given(st.binary()) + def test_hypothesis_decoding(self, code_bytes): + source = BytesIO(code_bytes) + result = StreamResult() + stream = subunit.ByteStreamToStreamResult( + source, non_subunit_name="stdout") + stream.run(result) + self.assertEqual(b'', source.read()) diff --git a/python/subunit/v2.py b/python/subunit/v2.py index 057f65c..f649895 100644 --- a/python/subunit/v2.py +++ b/python/subunit/v2.py @@ -386,7 +386,11 @@ class ByteStreamToStreamResult(object): def _parse(self, packet, result): # 2 bytes flags, at most 3 bytes length. packet.append(self.source.read(5)) - flags = struct.unpack(FMT_16, packet[-1][:2])[0] + if len(packet[-1]) != 5: + raise ParseError( + 'Short read - got %d bytes, wanted 5' % len(packet[-1])) + flag_bytes = packet[-1][:2] + flags = struct.unpack(FMT_16, flag_bytes)[0] length, consumed = self._parse_varint( packet[-1], 2, max_3_bytes=True) remainder = self.source.read(length - 6) @@ -14,11 +14,13 @@ else: 'testtools>=0.9.34', ], 'tests_require': [ + 'fixtures', + 'hypothesis', 'testscenarios', ], 'extras_require': { 'docs': ['docutils'], - 'test': ['fixtures', 'testscenarios'], + 'test': ['fixtures', 'hypothesis', 'testscenarios'], }, } |