From e0fe5856dce0725841d54b6be2c3c8d70f89a0b5 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 25 Apr 2011 22:26:51 +0100 Subject: Avoid leaking test output in TestTestProtocolServerStartTest.test_indented_test_colon_ignored --- python/subunit/tests/test_test_protocol.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 7ec7758..d8af230 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -107,7 +107,8 @@ class TestTestProtocolServerStartTest(unittest.TestCase): def setUp(self): self.client = Python26TestResult() - self.protocol = subunit.TestProtocolServer(self.client) + self.stream = BytesIO() + self.protocol = subunit.TestProtocolServer(self.client, self.stream) def test_start_test(self): self.protocol.lineReceived(_b("test old mcdonald\n")) @@ -125,8 +126,10 @@ class TestTestProtocolServerStartTest(unittest.TestCase): [('startTest', subunit.RemotedTestCase("old mcdonald"))]) def test_indented_test_colon_ignored(self): - self.protocol.lineReceived(_b(" test: old mcdonald\n")) + ignored_line = _b(" test: old mcdonald\n") + self.protocol.lineReceived(ignored_line) self.assertEqual([], self.client._events) + self.assertEqual(self.stream.getvalue(), ignored_line) def test_start_testing_colon(self): self.protocol.lineReceived(_b("testing: old mcdonald\n")) -- cgit v1.2.1 From a9af4250b0eeaf9b45a6e25a59736efffe1d46fd Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 27 Apr 2011 02:25:24 +0100 Subject: Hack ExecTestCase and its tests to sort-of be portable fixing the remaing spew --- python/subunit/__init__.py | 8 ++++++-- python/subunit/tests/sample-script.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index a7048d3..82864f7 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -817,6 +817,8 @@ class ExecTestCase(unittest.TestCase): """ unittest.TestCase.__init__(self, methodName) testMethod = getattr(self, methodName) + # GZ 2011-04-25: Embedding shell commands in docstrings is fragile and + # and may break if the module directory contains spaces self.script = join_dir(sys.modules[self.__class__.__module__].__file__, testMethod.__doc__) @@ -833,8 +835,10 @@ class ExecTestCase(unittest.TestCase): def _run(self, result): protocol = TestProtocolServer(result) - output = subprocess.Popen(self.script, shell=True, - stdout=subprocess.PIPE).communicate()[0] + process = subprocess.Popen(self.script, shell=True, + stdout=subprocess.PIPE) + _make_stream_binary(process.stdout) + output = process.communicate()[0] protocol.readFrom(BytesIO(output)) diff --git a/python/subunit/tests/sample-script.py b/python/subunit/tests/sample-script.py index 0ee019a..618e495 100755 --- a/python/subunit/tests/sample-script.py +++ b/python/subunit/tests/sample-script.py @@ -1,5 +1,8 @@ #!/usr/bin/env python import sys +if sys.platform == "win32": + import msvcrt, os + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) if len(sys.argv) == 2: # subunit.tests.test_test_protocol.TestExecTestCase.test_sample_method_args # uses this code path to be sure that the arguments were passed to -- cgit v1.2.1 From 43221d66d43180fd75c626422b005af3963a4669 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 27 Apr 2011 02:27:48 +0100 Subject: Skip os.fork tests on non-posix systems, by switching to testtools testcases there --- python/subunit/tests/test_test_protocol.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index d8af230..1b1aa1d 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -21,6 +21,7 @@ import os from testtools.compat import _b, _u, BytesIO, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType +from testtools.testcase import skipIf, TestCase from testtools.tests.helpers import ( Python26TestResult, Python27TestResult, @@ -922,7 +923,7 @@ class DoExecTestCase(subunit.ExecTestCase): """sample-two-script.py""" -class TestIsolatedTestCase(unittest.TestCase): +class TestIsolatedTestCase(TestCase): class SampleIsolatedTestCase(subunit.IsolatedTestCase): @@ -943,6 +944,7 @@ class TestIsolatedTestCase(unittest.TestCase): def test_construct(self): self.SampleIsolatedTestCase("test_sets_global_state") + @skipIf(os.name != "posix", "Need a posix system for forking tests") def test_run(self): result = unittest.TestResult() test = self.SampleIsolatedTestCase("test_sets_global_state") @@ -958,7 +960,7 @@ class TestIsolatedTestCase(unittest.TestCase): #test.debug() -class TestIsolatedTestSuite(unittest.TestCase): +class TestIsolatedTestSuite(TestCase): class SampleTestToIsolate(unittest.TestCase): @@ -979,6 +981,7 @@ class TestIsolatedTestSuite(unittest.TestCase): def test_construct(self): subunit.IsolatedTestSuite() + @skipIf(os.name != "posix", "Need a posix system for forking tests") def test_run(self): result = unittest.TestResult() suite = subunit.IsolatedTestSuite() -- cgit v1.2.1 From d3cff62c266095520eccd7a35ad16a3b119c7479 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 27 Apr 2011 02:32:23 +0100 Subject: Fix join_dir test by being more specific about what constitutes a match --- python/subunit/tests/test_test_protocol.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 1b1aa1d..e0fa7ef 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -913,7 +913,8 @@ class TestExecTestCase(unittest.TestCase): def test_join_dir(self): sibling = subunit.join_dir(__file__, 'foo') - expected = '%s/foo' % (os.path.split(__file__)[0],) + filedir = os.path.abspath(os.path.dirname(__file__)) + expected = os.path.join(filedir, 'foo') self.assertEqual(sibling, expected) -- cgit v1.2.1