summaryrefslogtreecommitdiff
path: root/python/subunit
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2008-12-07 14:54:50 +1100
committerRobert Collins <robertc@robertcollins.net>2008-12-07 14:54:50 +1100
commit755f5d6f16afeb65b55dcd6852974307eb690639 (patch)
treea601a5516e3639ce12ab387fe85293825879d64d /python/subunit
parent9a915af1f70344c63f232a2d82d14cf6e01aa84f (diff)
downloadsubunit-git-755f5d6f16afeb65b55dcd6852974307eb690639.tar.gz
Handle comments for test success (in wire parser) and connection loss for XFAIL and success.
Diffstat (limited to 'python/subunit')
-rw-r--r--python/subunit/__init__.py15
-rw-r--r--python/subunit/tests/test_test_protocol.py51
2 files changed, 64 insertions, 2 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index b2d1ad8..cde5707 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -51,6 +51,7 @@ class TestProtocolServer(object):
READING_ERROR = 3
READING_SKIP = 4
READING_XFAIL = 5
+ READING_SUCCESS = 6
def __init__(self, client, stream=sys.stdout):
"""Create a TestProtocol server instance.
@@ -128,6 +129,10 @@ class TestProtocolServer(object):
if (self.state == TestProtocolServer.TEST_STARTED and
self.current_test_description == line[offset:-1]):
self._succeedTest()
+ elif (self.state == TestProtocolServer.TEST_STARTED and
+ self.current_test_description + " [" == line[offset:-1]):
+ self.state = TestProtocolServer.READING_SUCCESS
+ self._message = ""
else:
self.stdOutLineReceived(line)
@@ -153,7 +158,9 @@ class TestProtocolServer(object):
self.client.stopTest(self._current_test)
elif self.state in (
TestProtocolServer.READING_SKIP,
- TestProtocolServer.READING_XFAIL):
+ TestProtocolServer.READING_SUCCESS,
+ TestProtocolServer.READING_XFAIL,
+ ):
self._succeedTest()
else:
self.stdOutLineReceived(line)
@@ -204,10 +211,14 @@ class TestProtocolServer(object):
self._lostConnectionInTest('error report of ')
elif self.state == TestProtocolServer.READING_FAILURE:
self._lostConnectionInTest('failure report of ')
+ elif self.state == TestProtocolServer.READING_SUCCESS:
+ self._lostConnectionInTest('success report of ')
elif self.state == TestProtocolServer.READING_SKIP:
self._lostConnectionInTest('skip report of ')
+ elif self.state == TestProtocolServer.READING_XFAIL:
+ self._lostConnectionInTest('xfail report of ')
else:
- self._lostConnection('unknown state of ')
+ self._lostConnectionInTest('unknown state of ')
def readFrom(self, pipe):
for line in pipe.readlines():
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index 842e887..9c17106 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -408,6 +408,30 @@ class TestTestProtocolServerLostConnection(unittest.TestCase):
self.assertEqual(self.client.failure_calls, [])
self.assertEqual(self.client.success_calls, [])
+ def test_lost_connection_during_xfail(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("xfail 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 xfail "
+ "report of test 'old mcdonald'"))])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connection_during_success(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("success 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 success "
+ "report of test 'old mcdonald'"))])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
class TestTestProtocolServerAddError(unittest.TestCase):
@@ -642,6 +666,33 @@ class TestTestProtocolServerAddSuccess(unittest.TestCase):
def test_simple_success_colon(self):
self.simple_success_keyword("successful:")
+ def test_success_empty_message(self):
+ self.protocol.lineReceived("success 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 success_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_success_quoted_bracket(self):
+ self.success_quoted_bracket("success")
+
+ def test_success_colon_quoted_bracket(self):
+ self.success_quoted_bracket("success:")
+
class TestRemotedTestCase(unittest.TestCase):