diff options
| author | Robert Collins <robertc@robertcollins.net> | 2008-12-07 10:01:15 +1100 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2008-12-07 10:01:15 +1100 |
| commit | 5c3c88265d467555e2e92f1a7f445f69b3c0a261 (patch) | |
| tree | c7658200c4fb94bcd87ab0df872b39fd42c3a865 /python | |
| parent | 632755acd911e3149501d7e36a0c3426947ab918 (diff) | |
| download | subunit-git-5c3c88265d467555e2e92f1a7f445f69b3c0a261.tar.gz | |
Implement skip support for the protocol server (but not for python clients as python has no standard way to describe skips.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 65 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 67 |
2 files changed, 110 insertions, 22 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index f0b0987..4c7cf57 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -49,6 +49,7 @@ class TestProtocolServer(object): TEST_STARTED = 1 READING_FAILURE = 2 READING_ERROR = 3 + READING_SKIP = 4 def __init__(self, client, stream=sys.stdout): """Create a TestProtocol server instance. @@ -94,14 +95,24 @@ class TestProtocolServer(object): else: self.stdOutLineReceived(line) - def _addSuccess(self, offset, line): + def _addSkip(self, offset, line): if (self.state == TestProtocolServer.TEST_STARTED and self.current_test_description == line[offset:-1]): + self.state = TestProtocolServer.OUTSIDE_TEST + self.current_test_description = None self.client.addSuccess(self._current_test) self.client.stopTest(self._current_test) - self.current_test_description = None - self._current_test = None - self.state = TestProtocolServer.OUTSIDE_TEST + elif (self.state == TestProtocolServer.TEST_STARTED and + self.current_test_description + " [" == line[offset:-1]): + self.state = TestProtocolServer.READING_SKIP + self._message = "" + else: + self.stdOutLineReceived(line) + + def _addSuccess(self, offset, line): + if (self.state == TestProtocolServer.TEST_STARTED and + self.current_test_description == line[offset:-1]): + self._succeedTest() else: self.stdOutLineReceived(line) @@ -125,6 +136,8 @@ class TestProtocolServer(object): self.client.addError(self._current_test, RemoteError(self._message)) self.client.stopTest(self._current_test) + elif self.state == TestProtocolServer.READING_SKIP: + self._succeedTest() else: self.stdOutLineReceived(line) @@ -132,8 +145,8 @@ class TestProtocolServer(object): """Call the appropriate local method for the received line.""" if line == "]\n": self.endQuote(line) - elif (self.state == TestProtocolServer.READING_FAILURE or - self.state == TestProtocolServer.READING_ERROR): + elif self.state in (TestProtocolServer.READING_FAILURE, + TestProtocolServer.READING_ERROR, TestProtocolServer.READING_SKIP): self._appendMessage(line) else: parts = line.split(None, 1) @@ -147,6 +160,8 @@ class TestProtocolServer(object): self._addError(offset, line) elif cmd == 'failure': self._addFailure(offset, line) + elif cmd == 'skip': + self._addSkip(offset, line) elif cmd in ('success', 'successful'): self._addSuccess(offset, line) else: @@ -154,27 +169,26 @@ class TestProtocolServer(object): else: self.stdOutLineReceived(line) + def _lostConnectionInTest(self, state_string): + error_string = "lost connection during %stest '%s'" % ( + state_string, self.current_test_description) + self.client.addError(self._current_test, RemoteError(error_string)) + self.client.stopTest(self._current_test) + def lostConnection(self): """The input connection has finished.""" + if self.state == TestProtocolServer.OUTSIDE_TEST: + return if self.state == TestProtocolServer.TEST_STARTED: - self.client.addError(self._current_test, - RemoteError("lost connection during test '%s'" - % self.current_test_description)) - self.client.stopTest(self._current_test) + self._lostConnectionInTest('') elif self.state == TestProtocolServer.READING_ERROR: - self.client.addError(self._current_test, - RemoteError("lost connection during " - "error report of test " - "'%s'" % - self.current_test_description)) - self.client.stopTest(self._current_test) + self._lostConnectionInTest('error report of ') elif self.state == TestProtocolServer.READING_FAILURE: - self.client.addError(self._current_test, - RemoteError("lost connection during " - "failure report of test " - "'%s'" % - self.current_test_description)) - self.client.stopTest(self._current_test) + self._lostConnectionInTest('failure report of ') + elif self.state == TestProtocolServer.READING_SKIP: + self._lostConnectionInTest('skip report of ') + else: + self._lostConnection('unknown state of ') def readFrom(self, pipe): for line in pipe.readlines(): @@ -194,6 +208,13 @@ class TestProtocolServer(object): def stdOutLineReceived(self, line): self._stream.write(line) + def _succeedTest(self): + self.client.addSuccess(self._current_test) + self.client.stopTest(self._current_test) + self.current_test_description = None + self._current_test = None + self.state = TestProtocolServer.OUTSIDE_TEST + class RemoteException(Exception): """An exception that occured remotely to python.""" diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 0083954..d12b0ac 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -396,6 +396,18 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.assertEqual(self.client.failure_calls, []) self.assertEqual(self.client.success_calls, [self.test]) + def test_lost_connection_during_skip(self): + self.protocol.lineReceived("test old mcdonald\n") + self.protocol.lineReceived("skip old mcdonald [\n") + self.protocol.lostConnection() + self.assertEqual(self.client.start_calls, [self.test]) + self.assertEqual(self.client.end_calls, [self.test]) + self.assertEqual(self.client.error_calls, [ + (self.test, subunit.RemoteError("lost connection during skip " + "report of test 'old mcdonald'"))]) + self.assertEqual(self.client.failure_calls, []) + self.assertEqual(self.client.success_calls, []) + class TestTestProtocolServerAddError(unittest.TestCase): @@ -493,6 +505,61 @@ class TestTestProtocolServerAddFailure(unittest.TestCase): self.failure_quoted_bracket("failure:") +class TestTestProtocolServerAddSkip(unittest.TestCase): + """Tests for the skip keyword. + + In python this thunks through to Success due to stdlib limitations. + """ + + def setUp(self): + """Setup a test object ready to be skipped.""" + self.client = MockTestProtocolServerClient() + self.protocol = subunit.TestProtocolServer(self.client) + self.protocol.lineReceived("test mcdonalds farm\n") + self.test = self.client.start_calls[-1] + + def simple_skip_keyword(self, keyword): + self.protocol.lineReceived("%s mcdonalds farm\n" % keyword) + self.assertEqual(self.client.start_calls, [self.test]) + self.assertEqual(self.client.end_calls, [self.test]) + self.assertEqual(self.client.error_calls, []) + self.assertEqual(self.client.failure_calls, []) + self.assertEqual(self.client.success_calls, [self.test]) + + def test_simple_skip(self): + self.simple_skip_keyword("skip") + + def test_simple_skip_colon(self): + self.simple_skip_keyword("skip:") + + def test_skip_empty_message(self): + self.protocol.lineReceived("skip mcdonalds farm [\n") + self.protocol.lineReceived("]\n") + self.assertEqual(self.client.start_calls, [self.test]) + self.assertEqual(self.client.end_calls, [self.test]) + self.assertEqual(self.client.error_calls, []) + self.assertEqual(self.client.failure_calls, []) + self.assertEqual(self.client.success_calls, [self.test]) + + def skip_quoted_bracket(self, keyword): + # This tests it is accepted, but cannot test it is used today, because + # of not having a way to expose it in python so far. + self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword) + self.protocol.lineReceived(" ]\n") + self.protocol.lineReceived("]\n") + self.assertEqual(self.client.start_calls, [self.test]) + self.assertEqual(self.client.end_calls, [self.test]) + self.assertEqual(self.client.error_calls, []) + self.assertEqual(self.client.failure_calls, []) + self.assertEqual(self.client.success_calls, [self.test]) + + def test_skip_quoted_bracket(self): + self.skip_quoted_bracket("skip") + + def test_skip_colon_quoted_bracket(self): + self.skip_quoted_bracket("skip:") + + class TestTestProtocolServerAddSuccess(unittest.TestCase): def setUp(self): |
