Handle comments for test success (in wire parser) and connection loss for XFAIL and...
authorRobert Collins <robertc@robertcollins.net>
Sun, 7 Dec 2008 03:54:50 +0000 (14:54 +1100)
committerRobert Collins <robertc@robertcollins.net>
Sun, 7 Dec 2008 03:54:50 +0000 (14:54 +1100)
README
python/subunit/__init__.py
python/subunit/tests/test_test_protocol.py

diff --git a/README b/README
index 0426b3d1ede3ff8130a5eb1126440e15d91e0ac2..de99994d6a5ae8d61cfccb81e3873d20a304b69a 100644 (file)
--- a/README
+++ b/README
@@ -145,6 +145,9 @@ foo.c:34 WARNING foo is not defined.
 control protocol:
 test|testing|test:|testing: test label
 success|success:|successful|successful: test label
+success|success:|successful|successful: test label [
+...
+]
 failure test label
 failure: test label
 failure test label [
index b2d1ad8b3e87d09a17bae5b75ce2e7e5bd97a0ff..cde57077cf22ae33c50f01025294ec001121c588 100644 (file)
@@ -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():
index 842e887f7e7e8cf5022f0c5858b3ed313c7eff7a..9c171061ba4b454f41173e8d8ec0ecf272537357 100644 (file)
@@ -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):