diff options
| author | Robert Collins <robertc@robertcollins.net> | 2009-08-08 10:09:19 +1000 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2009-08-08 10:09:19 +1000 |
| commit | cc4699a328dd76ecaad6a2e94b17845793bdf51d (patch) | |
| tree | 6b5776f40cb684ab124bb801c84e64afec96210e /python | |
| parent | 27837a1f2a6a0a820cecfee674fac5592970a493 (diff) | |
| parent | 3be3c3dc6f36e1ecaf668abc46d3c7942c4012bb (diff) | |
| download | subunit-git-cc4699a328dd76ecaad6a2e94b17845793bdf51d.tar.gz | |
Merge bugfix to expose xfail in python2.7 and above.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 20 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 72 |
2 files changed, 73 insertions, 19 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 4907332..f474bd9 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -120,7 +120,11 @@ class TestProtocolServer(object): self.current_test_description == line[offset:-1]): self.state = TestProtocolServer.OUTSIDE_TEST self.current_test_description = None - self.client.addSuccess(self._current_test) + xfail = getattr(self.client, 'addExpectedFailure', None) + if callable(xfail): + xfail(self._current_test, RemoteError()) + else: + 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]): @@ -203,10 +207,16 @@ class TestProtocolServer(object): self.current_test_description = None self._skip_or_error(self._message) self.client.stopTest(self._current_test) - elif self.state in ( - TestProtocolServer.READING_SUCCESS, - TestProtocolServer.READING_XFAIL, - ): + elif self.state == TestProtocolServer.READING_XFAIL: + self.state = TestProtocolServer.OUTSIDE_TEST + self.current_test_description = None + xfail = getattr(self.client, 'addExpectedFailure', None) + if callable(xfail): + xfail(self._current_test, RemoteError(self._message)) + else: + self.client.addSuccess(self._current_test) + self.client.stopTest(self._current_test) + elif self.state == TestProtocolServer.READING_SUCCESS: self._succeedTest() else: self.stdOutLineReceived(line) diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 975d5b5..a036192 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -28,7 +28,12 @@ import subunit.iso8601 as iso8601 class MockTestProtocolServerClient(object): - """A mock protocol server client to test callbacks.""" + """A mock protocol server client to test callbacks. + + Note that this is deliberately not Python 2.7 complete, to allow + testing compatibility - we need a TestResult that will not have new methods + like addExpectedFailure. + """ def __init__(self): self.end_calls = [] @@ -555,41 +560,74 @@ class TestTestProtocolServerAddFailure(unittest.TestCase): class TestTestProtocolServerAddxFail(unittest.TestCase): """Tests for the xfail keyword. - In Python this thunks through to Success due to stdlib limitations (see + In Python this can thunk through to Success due to stdlib limitations (see README). """ - def setUp(self): - """Setup a test object ready to be xfailed.""" + def capture_expected_failure(self, test, err): + self._calls.append((test, err)) + + def setup_python26(self): + """Setup a test object ready to be xfailed and thunk to success.""" self.client = MockTestProtocolServerClient() + self.setup_protocol() + + def setup_python27(self): + """Setup a test object ready to be xfailed and thunk to success.""" + self.client = MockTestProtocolServerClient() + self.client.addExpectedFailure = self.capture_expected_failure + self._calls = [] + self.setup_protocol() + + def setup_protocol(self): + """Setup the protocol based on self.client.""" 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): + def simple_xfail_keyword(self, keyword, as_success): 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]) + self.check_success_or_xfail(as_success) + + def check_success_or_xfail(self, as_success): + if as_success: + self.assertEqual(self.client.success_calls, [self.test]) + else: + self.assertEqual(1, len(self._calls)) + self.assertEqual(self.test, self._calls[0][0]) def test_simple_xfail(self): - self.simple_xfail_keyword("xfail") + self.setup_python26() + self.simple_xfail_keyword("xfail", True) + self.setup_python27() + self.simple_xfail_keyword("xfail", False) def test_simple_xfail_colon(self): - self.simple_xfail_keyword("xfail:") + self.setup_python26() + self.simple_xfail_keyword("xfail:", True) + self.setup_python27() + self.simple_xfail_keyword("xfail:", False) def test_xfail_empty_message(self): + self.setup_python26() + self.empty_message(True) + self.setup_python27() + self.empty_message(False) + + def empty_message(self, as_success): 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]) + self.check_success_or_xfail(as_success) - def xfail_quoted_bracket(self, keyword): + def xfail_quoted_bracket(self, keyword, as_success): # 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) @@ -599,19 +637,25 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): 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]) + self.check_success_or_xfail(as_success) def test_xfail_quoted_bracket(self): - self.xfail_quoted_bracket("xfail") + self.setup_python26() + self.xfail_quoted_bracket("xfail", True) + self.setup_python27() + self.xfail_quoted_bracket("xfail", False) def test_xfail_colon_quoted_bracket(self): - self.xfail_quoted_bracket("xfail:") + self.setup_python26() + self.xfail_quoted_bracket("xfail:", True) + self.setup_python27() + self.xfail_quoted_bracket("xfail:", False) class TestTestProtocolServerAddSkip(unittest.TestCase): """Tests for the skip keyword. - In python this meets the testtools extended TestResult contract. + In Python this meets the testtools extended TestResult contract. (See https://launchpad.net/testtools). """ |
