diff options
| author | Robert Collins <robertc@robertcollins.net> | 2008-12-07 14:37:48 +1100 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2008-12-07 14:37:48 +1100 |
| commit | 9a915af1f70344c63f232a2d82d14cf6e01aa84f (patch) | |
| tree | d44b7ca9d66d22d0bff430f077d42555f6d9ab0a /python | |
| parent | 5c3c88265d467555e2e92f1a7f445f69b3c0a261 (diff) | |
| download | subunit-git-9a915af1f70344c63f232a2d82d14cf6e01aa84f.tar.gz | |
Add XFAIL support. As with Skip, there is no python object representation of the skip, because there is no standard for reporting them.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 21 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 55 |
2 files changed, 75 insertions, 1 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 4c7cf57..b2d1ad8 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -50,6 +50,7 @@ class TestProtocolServer(object): READING_FAILURE = 2 READING_ERROR = 3 READING_SKIP = 4 + READING_XFAIL = 5 def __init__(self, client, stream=sys.stdout): """Create a TestProtocol server instance. @@ -81,6 +82,20 @@ class TestProtocolServer(object): else: self.stdOutLineReceived(line) + def _addExpectedFail(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) + elif (self.state == TestProtocolServer.TEST_STARTED and + self.current_test_description + " [" == line[offset:-1]): + self.state = TestProtocolServer.READING_XFAIL + self._message = "" + else: + self.stdOutLineReceived(line) + def _addFailure(self, offset, line): if (self.state == TestProtocolServer.TEST_STARTED and self.current_test_description == line[offset:-1]): @@ -136,7 +151,9 @@ class TestProtocolServer(object): self.client.addError(self._current_test, RemoteError(self._message)) self.client.stopTest(self._current_test) - elif self.state == TestProtocolServer.READING_SKIP: + elif self.state in ( + TestProtocolServer.READING_SKIP, + TestProtocolServer.READING_XFAIL): self._succeedTest() else: self.stdOutLineReceived(line) @@ -164,6 +181,8 @@ class TestProtocolServer(object): self._addSkip(offset, line) elif cmd in ('success', 'successful'): self._addSuccess(offset, line) + elif cmd == 'xfail': + self._addExpectedFail(offset, line) else: self.stdOutLineReceived(line) else: diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index d12b0ac..842e887 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -505,6 +505,61 @@ class TestTestProtocolServerAddFailure(unittest.TestCase): self.failure_quoted_bracket("failure:") +class TestTestProtocolServerAddxFail(unittest.TestCase): + """Tests for the xfail keyword. + + In python this thunks through to Success due to stdlib limitations. + """ + + def setUp(self): + """Setup a test object ready to be xfailed.""" + 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_xfail_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_xfail(self): + self.simple_xfail_keyword("xfail") + + def test_simple_xfail_colon(self): + self.simple_xfail_keyword("xfail:") + + def test_xfail_empty_message(self): + self.protocol.lineReceived("xfail 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 xfail_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_xfail_quoted_bracket(self): + self.xfail_quoted_bracket("xfail") + + def test_xfail_colon_quoted_bracket(self): + self.xfail_quoted_bracket("xfail:") + + class TestTestProtocolServerAddSkip(unittest.TestCase): """Tests for the skip keyword. |
