summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-08-05 15:41:29 +1000
committerRobert Collins <robertc@robertcollins.net>2009-08-05 15:41:29 +1000
commit27837a1f2a6a0a820cecfee674fac5592970a493 (patch)
treeed3bbac1e6e94b16834fc9d4e9b98bc92931c2ce /python
parent2ff41c1b09f13b1c8e6de5222033984c1511d597 (diff)
parent28e9a4580f7a6b1c1b70395d3c2cf1a2971489a8 (diff)
downloadsubunit-git-27837a1f2a6a0a820cecfee674fac5592970a493.tar.gz
Add --no-passthrough option to most filters.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/__init__.py35
-rw-r--r--python/subunit/tests/test_test_protocol.py8
2 files changed, 32 insertions, 11 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index e0a4ccc..4907332 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -63,6 +63,13 @@ def tags_to_new_gone(tags):
return new_tags, gone_tags
+class DiscardStream(object):
+ """A filelike object which discards what is written to it."""
+
+ def write(self, bytes):
+ pass
+
+
class TestProtocolServer(object):
"""A class for receiving results from a TestProtocol client.
@@ -77,19 +84,19 @@ class TestProtocolServer(object):
READING_XFAIL = 5
READING_SUCCESS = 6
- def __init__(self, client, stream=sys.stdout):
+ def __init__(self, client, stream=None):
"""Create a TestProtocol server instance.
- client should be an object that provides
- - startTest
- - addSuccess
- - addFailure
- - addError
- - stopTest
- methods, i.e. a TestResult.
+ :param client: An object meeting the unittest.TestResult protocol.
+ :param stream: The stream that lines received which are not part of the
+ subunit protocol should be written to. This allows custom handling
+ of mixed protocols. By default, sys.stdout will be used for
+ convenience.
"""
self.state = TestProtocolServer.OUTSIDE_TEST
self.client = client
+ if stream is None:
+ stream = sys.stdout
self._stream = stream
self.tags = set()
@@ -701,8 +708,16 @@ def tag_stream(original, filtered, tags):
class ProtocolTestCase(object):
"""A test case which reports a subunit stream."""
- def __init__(self, stream):
+ def __init__(self, stream, passthrough=None):
+ """Create a ProtocolTestCase reading from stream.
+
+ :param stream: A filelike object which a subunit stream can be read
+ from.
+ :param passthrough: A stream pass non subunit input on to. If not
+ supplied, the TestProtocolServer default is used.
+ """
self._stream = stream
+ self._passthrough = passthrough
def __call__(self, result=None):
return self.run(result)
@@ -710,7 +725,7 @@ class ProtocolTestCase(object):
def run(self, result=None):
if result is None:
result = self.defaultTestResult()
- protocol = TestProtocolServer(result)
+ protocol = TestProtocolServer(result, self._passthrough)
line = self._stream.readline()
while line:
protocol.lineReceived(line)
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index 5eedbf9..975d5b5 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -131,6 +131,7 @@ class TestMockTestProtocolServer(unittest.TestCase):
class TestTestImports(unittest.TestCase):
def test_imports(self):
+ from subunit import DiscardStream
from subunit import TestProtocolServer
from subunit import RemotedTestCase
from subunit import RemoteError
@@ -139,6 +140,12 @@ class TestTestImports(unittest.TestCase):
from subunit import TestProtocolClient
+class TestDiscardStream(unittest.TestCase):
+
+ def test_write(self):
+ subunit.DiscardStream().write("content")
+
+
class TestTestProtocolServerPipe(unittest.TestCase):
def test_story(self):
@@ -194,7 +201,6 @@ class TestTestProtocolServerStartTest(unittest.TestCase):
class TestTestProtocolServerPassThrough(unittest.TestCase):
def setUp(self):
- from StringIO import StringIO
self.stdout = StringIO()
self.test = subunit.RemotedTestCase("old mcdonald")
self.client = MockTestProtocolServerClient()