diff options
Diffstat (limited to 'lib/subunit/python')
-rw-r--r-- | lib/subunit/python/subunit/__init__.py | 29 | ||||
-rwxr-xr-x | lib/subunit/python/subunit/run.py | 15 | ||||
-rw-r--r-- | lib/subunit/python/subunit/test_results.py | 7 | ||||
-rw-r--r-- | lib/subunit/python/subunit/tests/test_test_protocol.py | 15 | ||||
-rw-r--r-- | lib/subunit/python/subunit/tests/test_test_results.py | 6 |
5 files changed, 66 insertions, 6 deletions
diff --git a/lib/subunit/python/subunit/__init__.py b/lib/subunit/python/subunit/__init__.py index 6015c0e68c..42dcf297e4 100644 --- a/lib/subunit/python/subunit/__init__.py +++ b/lib/subunit/python/subunit/__init__.py @@ -147,6 +147,19 @@ from testtools import testresult from subunit import chunked, details, iso8601, test_results +# same format as sys.version_info: "A tuple containing the five components of +# the version number: major, minor, micro, releaselevel, and serial. All +# values except releaselevel are integers; the release level is 'alpha', +# 'beta', 'candidate', or 'final'. The version_info value corresponding to the +# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a +# releaselevel of 'dev' for unreleased under-development code. +# +# If the releaselevel is 'alpha' then the major/minor/micro components are not +# established at this point, and setup.py will use a version of next-$(revno). +# If the releaselevel is 'final', then the tarball will be major.minor.micro. +# Otherwise it is major.minor.micro~$(revno). + +__version__ = (0, 0, 9, 'final', 0) PROGRESS_SET = 0 PROGRESS_CUR = 1 @@ -636,6 +649,8 @@ class TestProtocolClient(testresult.TestResult): to subunit.Content objects. """ self._addOutcome("error", test, error=error, details=details) + if self.failfast: + self.stop() def addExpectedFailure(self, test, error=None, details=None): """Report an expected failure in test test. @@ -666,6 +681,8 @@ class TestProtocolClient(testresult.TestResult): to subunit.Content objects. """ self._addOutcome("failure", test, error=error, details=details) + if self.failfast: + self.stop() def _addOutcome(self, outcome, test, error=None, details=None, error_permitted=True): @@ -685,7 +702,7 @@ class TestProtocolClient(testresult.TestResult): :param error_permitted: If True then one and only one of error or details must be supplied. If False then error must not be supplied and details is still optional. """ - self._stream.write(_b("%s: %s" % (outcome, test.id()))) + self._stream.write(_b("%s: " % outcome) + self._test_id(test)) if error_permitted: if error is None and details is None: raise ValueError @@ -730,11 +747,19 @@ class TestProtocolClient(testresult.TestResult): """ self._addOutcome("uxsuccess", test, details=details, error_permitted=False) + if self.failfast: + self.stop() + + def _test_id(self, test): + result = test.id() + if type(result) is not bytes: + result = result.encode('utf8') + return result def startTest(self, test): """Mark a test as starting its test run.""" super(TestProtocolClient, self).startTest(test) - self._stream.write(_b("test: %s\n" % test.id())) + self._stream.write(_b("test: ") + self._test_id(test) + _b("\n")) self._stream.flush() def stopTest(self, test): diff --git a/lib/subunit/python/subunit/run.py b/lib/subunit/python/subunit/run.py index ca5fe5c17e..b5ccea449d 100755 --- a/lib/subunit/python/subunit/run.py +++ b/lib/subunit/python/subunit/run.py @@ -34,13 +34,22 @@ from testtools.run import ( class SubunitTestRunner(object): - def __init__(self, stream=sys.stdout): - self.stream = stream + def __init__(self, verbosity=None, failfast=None, buffer=None, stream=None): + """Create a TestToolsTestRunner. + + :param verbosity: Ignored. + :param failfast: Stop running tests at the first failure. + :param buffer: Ignored. + """ + self.failfast = failfast + self.stream = stream or sys.stdout def run(self, test): "Run the given test case or test suite." result = TestProtocolClient(self.stream) result = AutoTimingTestResultDecorator(result) + if self.failfast is not None: + result.failfast = self.failfast test(result) return result @@ -70,6 +79,6 @@ class SubunitTestProgram(TestProgram): if __name__ == '__main__': stream = get_default_formatter() - runner = SubunitTestRunner(stream) + runner = SubunitTestRunner SubunitTestProgram(module=None, argv=sys.argv, testRunner=runner, stdout=sys.stdout) diff --git a/lib/subunit/python/subunit/test_results.py b/lib/subunit/python/subunit/test_results.py index c00a2d3e97..91c9bbdc1e 100644 --- a/lib/subunit/python/subunit/test_results.py +++ b/lib/subunit/python/subunit/test_results.py @@ -78,6 +78,13 @@ class TestResultDecorator(object): def addUnexpectedSuccess(self, test, details=None): return self.decorated.addUnexpectedSuccess(test, details=details) + def _get_failfast(self): + return getattr(self.decorated, 'failfast', False) + + def _set_failfast(self, value): + self.decorated.failfast = value + failfast = property(_get_failfast, _set_failfast) + def progress(self, offset, whence): return self.decorated.progress(offset, whence) diff --git a/lib/subunit/python/subunit/tests/test_test_protocol.py b/lib/subunit/python/subunit/tests/test_test_protocol.py index ec6830d03b..7831ba16cd 100644 --- a/lib/subunit/python/subunit/tests/test_test_protocol.py +++ b/lib/subunit/python/subunit/tests/test_test_protocol.py @@ -18,7 +18,7 @@ import datetime import unittest import os -from testtools import skipIf, TestCase, TestResult +from testtools import PlaceHolder, skipIf, TestCase, TestResult from testtools.compat import _b, _u, BytesIO from testtools.content import Content, TracebackContent, text_content from testtools.content_type import ContentType @@ -1133,6 +1133,7 @@ class TestTestProtocolClient(unittest.TestCase): def setUp(self): self.io = BytesIO() self.protocol = subunit.TestProtocolClient(self.io) + self.unicode_test = PlaceHolder(_u('\u2603')) self.test = TestTestProtocolClient("test_start_test") self.sample_details = {'something':Content( ContentType('text', 'plain'), lambda:[_b('serialised\nform')])} @@ -1145,6 +1146,12 @@ class TestTestProtocolClient(unittest.TestCase): self.protocol.startTest(self.test) self.assertEqual(self.io.getvalue(), _b("test: %s\n" % self.test.id())) + def test_start_test_unicode_id(self): + """Test startTest on a TestProtocolClient.""" + self.protocol.startTest(self.unicode_test) + expected = _b("test: ") + _u('\u2603').encode('utf8') + _b("\n") + self.assertEqual(expected, self.io.getvalue()) + def test_stop_test(self): # stopTest doesn't output anything. self.protocol.stopTest(self.test) @@ -1156,6 +1163,12 @@ class TestTestProtocolClient(unittest.TestCase): self.assertEqual( self.io.getvalue(), _b("successful: %s\n" % self.test.id())) + def test_add_outcome_unicode_id(self): + """Test addSuccess on a TestProtocolClient.""" + self.protocol.addSuccess(self.unicode_test) + expected = _b("successful: ") + _u('\u2603').encode('utf8') + _b("\n") + self.assertEqual(expected, self.io.getvalue()) + def test_add_success_details(self): """Test addSuccess on a TestProtocolClient with details.""" self.protocol.addSuccess(self.test, details=self.sample_details) diff --git a/lib/subunit/python/subunit/tests/test_test_results.py b/lib/subunit/python/subunit/tests/test_test_results.py index 236dfa22e5..ff74b9a818 100644 --- a/lib/subunit/python/subunit/tests/test_test_results.py +++ b/lib/subunit/python/subunit/tests/test_test_results.py @@ -61,6 +61,7 @@ class TimeCapturingResult(unittest.TestResult): def __init__(self): super(TimeCapturingResult, self).__init__() self._calls = [] + self.failfast = False def time(self, a_datetime): self._calls.append(a_datetime) @@ -198,6 +199,11 @@ class TestAutoTimingTestResultDecorator(unittest.TestCase): self.assertEqual(3, len(self.decorated._calls)) self.assertNotEqual(None, self.decorated._calls[2]) + def test_set_failfast_True(self): + self.assertFalse(self.decorated.failfast) + self.result.failfast = True + self.assertTrue(self.decorated.failfast) + class TestTagCollapsingDecorator(TestCase): |