diff options
| author | Robert Collins <robertc@robertcollins.net> | 2009-10-07 23:19:12 +1100 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2009-10-07 23:19:12 +1100 |
| commit | 446d6f69537d2fb2bff212e3f8ebc3f36b525740 (patch) | |
| tree | f917778178e0ddc9090e1d53a945397cd9a8e357 /python | |
| parent | aa757dce0d1ca43a66a5f008e05699a0230b0d59 (diff) | |
| download | subunit-git-446d6f69537d2fb2bff212e3f8ebc3f36b525740.tar.gz | |
Hook addError up to the details protocol.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 45 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 16 |
2 files changed, 50 insertions, 11 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 9d021fe..1c6937c 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -46,9 +46,9 @@ will either lose fidelity (for instance, folding expected failures to success in Python versions < 2.7 or 3.1), or discard the extended data (for extra details, tags, timestamping and progress markers). -The test outcome methods ``addSuccess``, ``addFailure`` take an optional -keyword parameter ``details`` which can be used instead of the usual python -unittest parameter. +The test outcome methods ``addSuccess``, ``addError``, ``addFailure`` take an +optional keyword parameter ``details`` which can be used instead of the usual +python unittest parameter. When used the value of details should be a dict from ``string`` to ``subunit.content.Content`` objects. This is a draft API being worked on with the Python Testing In Python mail list, with the goal of permitting a common @@ -473,12 +473,20 @@ class TestProtocolClient(unittest.TestResult): unittest.TestResult.__init__(self) self._stream = stream - def addError(self, test, error): - """Report an error in test test.""" - self._stream.write("error: %s [\n" % test.id()) - for line in self._exc_info_to_string(error, test).splitlines(): - self._stream.write("%s\n" % line) - self._stream.write("]\n") + def addError(self, test, error=None, details=None): + """Report an error in test test. + + Only one of error and details should be provided: conceptually there + are two separate methods: + addError(self, test, error) + addError(self, test, details) + + :param error: Standard unittest positional argument form - an + exc_info tuple. + :param details: New Testing-in-python drafted API; a dict from string + to subunit.Content objects. + """ + self._addOutcome("error", test, error=error, details=details) def addFailure(self, test, error=None, details=None): """Report a failure in test test. @@ -493,7 +501,24 @@ class TestProtocolClient(unittest.TestResult): :param details: New Testing-in-python drafted API; a dict from string to subunit.Content objects. """ - self._stream.write("failure: %s" % test.id()) + self._addOutcome("failure", test, error=error, details=details) + + def _addOutcome(self, outcome, test, error=None, details=None): + """Report a failure in test test. + + Only one of error and details should be provided: conceptually there + are two separate methods: + addOutcome(self, test, error) + addOutcome(self, test, details) + + :param outcome: A string describing the outcome - used as the + event name in the subunit stream. + :param error: Standard unittest positional argument form - an + exc_info tuple. + :param details: New Testing-in-python drafted API; a dict from string + to subunit.Content objects. + """ + self._stream.write("%s: %s" % (outcome, test.id())) if error is None and details is None: raise ValueError if error is not None: diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 1b48290..1700de6 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -1108,7 +1108,6 @@ class TestTestProtocolClient(unittest.TestCase): "25\nRemoteException: boo qux\n0\n" "]\n" % self.test.id()) - def test_add_error(self): """Test stopTest on a TestProtocolClient.""" self.protocol.addError( @@ -1119,6 +1118,21 @@ class TestTestProtocolClient(unittest.TestCase): "RemoteException: phwoar crikey\n" "]\n" % self.test.id()) + def test_add_error_details(self): + """Test stopTest on a TestProtocolClient with details.""" + self.protocol.addError( + self.test, details=self.sample_tb_details) + self.assertEqual( + self.io.getvalue(), + "error: %s [ multipart\n" + "Content-Type: text/plain\n" + "something\n" + "15\nserialised\nform0\n" + "Content-Type: text/x-traceback;language=python\n" + "traceback\n" + "25\nRemoteException: boo qux\n0\n" + "]\n" % self.test.id()) + def test_add_skip(self): """Test addSkip on a TestProtocolClient.""" self.protocol.addSkip( |
