From bb7e4124b6d945551c5e4444a8f5b44dac211d74 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sat, 2 Dec 2006 15:42:35 +1100 Subject: Use absolute paths so the tests run from trial --- python/subunit/tests/TestUtil.py | 10 ++++++++-- python/subunit/tests/test_test_protocol.py | 13 ++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'python/subunit') diff --git a/python/subunit/tests/TestUtil.py b/python/subunit/tests/TestUtil.py index 7c6b5fb..d883f70 100644 --- a/python/subunit/tests/TestUtil.py +++ b/python/subunit/tests/TestUtil.py @@ -16,6 +16,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +import os import sys import logging import unittest @@ -39,6 +40,11 @@ def makeCollectingLogger(): return logger, handler +def mockFile(filename): + return os.path.join(os.path.dirname(os.path.abspath(__file__)), + filename) + + def visitTests(suite, visitor): """A foreign method for visiting the tests in a test suite.""" for test in suite._tests: @@ -50,7 +56,7 @@ def visitTests(suite, visitor): if isinstance(test, unittest.TestCase): visitor.visitCase(test) elif isinstance(test, unittest.TestSuite): - visitor.visitSuite(test) + #visitor.visitSuite(test) visitTests(test, visitor) else: print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__) @@ -64,7 +70,7 @@ class TestSuite(unittest.TestSuite): def visit(self, visitor): """visit the composite. Visiting is depth-first. current callbacks are visitSuite and visitCase.""" - visitor.visitSuite(self) + #visitor.visitSuite(self) visitTests(self, visitor) diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index eb77e68..ae5af0c 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -21,6 +21,7 @@ import unittest from StringIO import StringIO import subunit import sys +from subunit.tests.TestUtil import mockFile try: class MockTestProtocolServerClient(object): @@ -561,14 +562,15 @@ class TestExecTestCase(unittest.TestCase): class SampleExecTestCase(subunit.ExecTestCase): def test_sample_method(self): - """./python/subunit/tests/sample-script.py""" - # the sample script runs three tests, one each - # that fails, errors and succeeds + pass + test_sample_method.__doc__ = mockFile("sample-script.py") + # the sample script runs three tests, one each + # that fails, errors and succeeds def test_construct(self): test = self.SampleExecTestCase("test_sample_method") - self.assertEqual(test.script, "./python/subunit/tests/sample-script.py") + self.assertEqual(test.script, mockFile("sample-script.py")) def test_run(self): runner = MockTestProtocolServerClient() @@ -597,7 +599,8 @@ class TestExecTestCase(unittest.TestCase): class DoExecTestCase(subunit.ExecTestCase): def test_working_script(self): - """./python/subunit/tests/sample-two-script.py""" + pass + test_working_script.__doc__ = mockFile("sample-two-script.py") class TestIsolatedTestCase(unittest.TestCase): -- cgit v1.2.1 From 472b3ae396f3649158cbd776e42bda53a8f800a8 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sat, 2 Dec 2006 15:43:25 +1100 Subject: Clarify the line-handling logic --- python/subunit/__init__.py | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'python/subunit') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index f171f78..922c53f 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -119,32 +119,20 @@ class TestProtocolServer(object): elif (self.state == TestProtocolServer.READING_FAILURE or self.state == TestProtocolServer.READING_ERROR): self._appendMessage(line) - elif line.startswith("test:"): - self._startTest(6, line) - elif line.startswith("testing:"): - self._startTest(9, line) - elif line.startswith("testing"): - self._startTest(8, line) - elif line.startswith("test"): - self._startTest(5, line) - elif line.startswith("error:"): - self._addError(7, line) - elif line.startswith("error"): - self._addError(6, line) - elif line.startswith("failure:"): - self._addFailure(9, line) - elif line.startswith("failure"): - self._addFailure(8, line) - elif line.startswith("successful:"): - self._addSuccess(12, line) - elif line.startswith("successful"): - self._addSuccess(11, line) - elif line.startswith("success:"): - self._addSuccess(9, line) - elif line.startswith("success"): - self._addSuccess(8, line) else: - self.stdOutLineReceived(line) + cmd, rest = line.split(None, 1) + offset = len(cmd) + 1 + cmd = cmd.strip(':') + if cmd in ('test', 'testing'): + self._startTest(offset, line) + elif cmd == 'error': + self._addError(offset, line) + elif cmd == 'failure': + self._addFailure(offset, line) + elif cmd in ('success', 'successful'): + self._addSuccess(offset, line) + else: + self.stdOutLineReceived(line) def lostConnection(self): """The input connection has finished.""" -- cgit v1.2.1 From c42cac02dc84b8db42f3c85f36affdaf732245a1 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Tue, 19 Dec 2006 16:13:53 +1100 Subject: Return a valid exc_info tuple from RemoteError --- python/subunit/__init__.py | 2 +- python/subunit/tests/test_test_protocol.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'python/subunit') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 922c53f..1fc34ec 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -218,7 +218,7 @@ class TestProtocolClient(unittest.TestResult): def RemoteError(description=""): if description == "": description = "\n" - return (RemoteException("RemoteError:\n%s" % description), None, None) + return (RemoteException, RemoteException(description), None) class RemotedTestCase(unittest.TestCase): diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index ae5af0c..98d74fe 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -139,10 +139,10 @@ class TestTestProtocolServerPipe(unittest.TestCase): bing = subunit.RemotedTestCase("bing crosby") an_error = subunit.RemotedTestCase("an error") self.assertEqual(client.errors, - [(an_error, 'RemoteError:\n\n\n')]) - self.assertEqual(client.failures, - [(bing, - "RemoteError:\nfoo.c:53:ERROR invalid state\n\n")]) + [(an_error, 'RemoteException: \n\n')]) + self.assertEqual( + client.failures, + [(bing, "RemoteException: foo.c:53:ERROR invalid state\n\n")]) self.assertEqual(client.testsRun, 3) @@ -532,7 +532,7 @@ class TestRemotedTestCase(unittest.TestCase): "'A test description'>", "%r" % test) result = unittest.TestResult() test.run(result) - self.assertEqual([(test, "RemoteError:\n" + self.assertEqual([(test, "RemoteException: " "Cannot run RemotedTestCases.\n\n")], result.errors) self.assertEqual(1, result.testsRun) @@ -705,7 +705,7 @@ class TestTestProtocolClient(unittest.TestCase): self.protocol.addFailure(self.test, subunit.RemoteError("boo")) self.assertEqual(self.io.getvalue(), "failure: Test startTest on a " "TestProtocolClient. [\n" - "RemoteError:\n" + "RemoteException:\n" "boo\n" "]\n") @@ -714,7 +714,7 @@ class TestTestProtocolClient(unittest.TestCase): self.protocol.addError(self.test, subunit.RemoteError("phwoar")) self.assertEqual(self.io.getvalue(), "error: Test startTest on a " "TestProtocolClient. [\n" - "RemoteError:\n" + "RemoteException:\n" "phwoar\n" "]\n") -- cgit v1.2.1