diff options
| author | Robert Collins <robertc@robertcollins.net> | 2009-10-05 05:22:14 +1100 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2009-10-05 05:22:14 +1100 |
| commit | 869d2a4f792a4d5d2c9f7f55d95ba216f0fbe4f1 (patch) | |
| tree | c01cac098f2bc713f710b9c187b867b9a6c608b9 /python | |
| parent | 5bf0f62627c4fecdcac1c5044f4e3aba03ad1e30 (diff) | |
| download | subunit-git-869d2a4f792a4d5d2c9f7f55d95ba216f0fbe4f1.tar.gz | |
Hook up addSuccess with a details parameter.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 30 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 15 |
2 files changed, 39 insertions, 6 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index d92e1bd..4edd69d 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -41,10 +41,18 @@ Twisted. See the ``TestProtocolServer`` parser class for more details. Subunit includes extensions to the Python ``TestResult`` protocol. These are all done in a compatible manner: ``TestResult`` objects that do not implement -the extension methods will not cause errors to be raised, instead the extesion +the extension methods will not cause errors to be raised, instead the extension 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 tags, -timestamping and progress markers). +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`` 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 +way to provide additional data beyond a traceback, such as captured data from +disk, logging messages etc. The ``tags(new_tags, gone_tags)`` method is called (if present) to add or remove tags in the test run that is currently executing. If called when no @@ -484,9 +492,21 @@ class TestProtocolClient(unittest.TestResult): self._stream.write("%s\n" % reason) self._stream.write("]\n") - def addSuccess(self, test): + def addSuccess(self, test, details=None): """Report a success in a test.""" - self._stream.write("successful: %s\n" % test.id()) + self._stream.write("successful: %s" % test.id()) + if not details: + self._stream.write("\n") + else: + self._stream.write(" [ multipart\n") + for name, content in details.iteritems(): + self._stream.write("Content-Type: %s/%s\n" % + (content.content_type.type, content.content_type.subtype)) + self._stream.write("%s\n" % name) + for bytes in content.iter_bytes(): + self._stream.write("%d\n%s" % (len(bytes), bytes)) + self._stream.write("0\n") + self._stream.write("]\n") def startTest(self, test): """Mark a test as starting its test run.""" diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 00a21ed..f505626 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -18,9 +18,11 @@ import datetime import unittest from StringIO import StringIO import os -import subunit import sys +import subunit +from subunit.content import Content +from subunit.content_type import ContentType import subunit.iso8601 as iso8601 @@ -1052,6 +1054,8 @@ class TestTestProtocolClient(unittest.TestCase): self.io = StringIO() self.protocol = subunit.TestProtocolClient(self.io) self.test = TestTestProtocolClient("test_start_test") + self.sample_details = {'something':Content( + ContentType('text', 'plain'), lambda:['serialised\nform'])} def test_start_test(self): """Test startTest on a TestProtocolClient.""" @@ -1069,6 +1073,15 @@ class TestTestProtocolClient(unittest.TestCase): self.assertEqual( self.io.getvalue(), "successful: %s\n" % self.test.id()) + def test_add_success_details(self): + """Test addSuccess on a TestProtocolClient.""" + self.protocol.addSuccess(self.test, details=self.sample_details) + self.assertEqual( + self.io.getvalue(), "successful: %s [ multipart\n" + "Content-Type: text/plain\n" + "something\n" + "15\nserialised\nform0\n]\n"% self.test.id()) + def test_add_failure(self): """Test addFailure on a TestProtocolClient.""" self.protocol.addFailure( |
