create a client concept for the TestProtocolServer
authorRobert Collins <robertc@robertcollins.net>
Sun, 28 Aug 2005 00:28:53 +0000 (10:28 +1000)
committerRobert Collins <robertc@robertcollins.net>
Sun, 28 Aug 2005 00:28:53 +0000 (10:28 +1000)
lib/subunit/__init__.py
lib/subunit/tests/test_test_protocol.py

index 90f427337576287c7f976dd18af45b3c83e45e2b..04f39d6c30e696c729af1d92a82496c5d5b41cec 100644 (file)
@@ -32,15 +32,17 @@ class TestProtocolServer(object):
     READING_FAILURE = 2
     READING_ERROR = 3
 
-    def __init__(self):
+    def __init__(self, client):
         self.state = TestProtocolServer.OUTSIDE_TEST
+        self.client = client
         
     def _addError(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.addError(self._current_test, RemoteError(""))
+            self.client.addError(self._current_test, RemoteError(""))
+            self._current_test = None
         elif (self.state == TestProtocolServer.TEST_STARTED and
             self.current_test_description + " [" == line[offset:-1]):
             self.state = TestProtocolServer.READING_ERROR
@@ -53,7 +55,7 @@ class TestProtocolServer(object):
             self.current_test_description == line[offset:-1]):
             self.state = TestProtocolServer.OUTSIDE_TEST
             self.current_test_description = None
-            self.addFailure(self._current_test, RemoteError())
+            self.client.addFailure(self._current_test, RemoteError())
         elif (self.state == TestProtocolServer.TEST_STARTED and
             self.current_test_description + " [" == line[offset:-1]):
             self.state = TestProtocolServer.READING_FAILURE
@@ -64,7 +66,7 @@ class TestProtocolServer(object):
     def _addSuccess(self, offset, line):
         if (self.state == TestProtocolServer.TEST_STARTED and
             self.current_test_description == line[offset:-1]):
-            self.addSuccess(self._current_test)
+            self.client.addSuccess(self._current_test)
             self.current_test_description = None
             self._current_test = None
             self.state = TestProtocolServer.OUTSIDE_TEST
@@ -82,11 +84,13 @@ class TestProtocolServer(object):
         if self.state == TestProtocolServer.READING_FAILURE:
             self.state = TestProtocolServer.OUTSIDE_TEST
             self.current_test_description = None
-            self.addFailure(self._current_test, RemoteError(self._message))
+            self.client.addFailure(self._current_test,
+                                   RemoteError(self._message))
         elif self.state == TestProtocolServer.READING_ERROR:
             self.state = TestProtocolServer.OUTSIDE_TEST
             self.current_test_description = None
-            self.addError(self._current_test, RemoteError(self._message))
+            self.client.addError(self._current_test,
+                                 RemoteError(self._message))
         else:
             self.stdOutLineRecieved(line)
         
@@ -127,19 +131,21 @@ class TestProtocolServer(object):
     def lostConnection(self):
         """The input connection has finished."""
         if self.state == TestProtocolServer.TEST_STARTED:
-            self.addError(self._current_test,
-                          RemoteError("lost connection during test '%s'"
-                                      % self.current_test_description))
+            self.client.addError(self._current_test,
+                                 RemoteError("lost connection during test '%s'"
+                                             % self.current_test_description))
         elif self.state == TestProtocolServer.READING_ERROR:
-            self.addError(self._current_test,
-                          RemoteError("lost connection during "
-                                      "error report of test "
-                                      "'%s'" % self.current_test_description))
+            self.client.addError(self._current_test,
+                                 RemoteError("lost connection during "
+                                             "error report of test "
+                                             "'%s'" %
+                                             self.current_test_description))
         elif self.state == TestProtocolServer.READING_FAILURE:
-            self.addError(self._current_test,
-                          RemoteError("lost connection during "
-                                      "failure report of test "
-                                      "'%s'" % self.current_test_description))
+            self.client.addError(self._current_test,
+                                 RemoteError("lost connection during "
+                                             "failure report of test "
+                                             "'%s'" % 
+                                             self.current_test_description))
 
     def readFrom(self, pipe):
         for line in pipe.readlines(pipe):
@@ -152,7 +158,7 @@ class TestProtocolServer(object):
             self.state = TestProtocolServer.TEST_STARTED
             self._current_test = RemotedTestCase(line[offset:-1])
             self.current_test_description = line[offset:-1]
-            self.startTest(self._current_test)
+            self.client.startTest(self._current_test)
         else:
             self.stdOutLineRecieved(line)
         
index 3d8a04e1a1d8d496f94c9fd0bf9019c50239fd24..ff48e186c96cb009a08ffbe14b891744af25087f 100644 (file)
@@ -23,15 +23,15 @@ import subunit
 import sys
 
 try:
-    class MockTestProtocolServer(subunit.TestProtocolServer):
-        """A mock protocol server to test callbacks."""
+    class MockTestProtocolServerClient(object):
+        """A mock protocol server client to test callbacks."""
 
         def __init__(self):
             self.error_calls = []
             self.failure_calls = []
             self.start_calls = []
             self.success_calls = []
-            super(MockTestProtocolServer, self).__init__()
+            super(MockTestProtocolServerClient, self).__init__()
 
         def addError(self, test, error):
             self.error_calls.append((test, error))
@@ -52,7 +52,7 @@ except AttributeError:
 class TestMockTestProtocolServer(unittest.TestCase):
 
     def test_start_test(self):
-        protocol = MockTestProtocolServer()
+        protocol = MockTestProtocolServerClient()
         protocol.startTest(subunit.RemotedTestCase("test old mcdonald"))
         self.assertEqual(protocol.start_calls,
                          [subunit.RemotedTestCase("test old mcdonald")])
@@ -61,7 +61,7 @@ class TestMockTestProtocolServer(unittest.TestCase):
         self.assertEqual(protocol.success_calls, [])
 
     def test_add_error(self):
-        protocol = MockTestProtocolServer()
+        protocol = MockTestProtocolServerClient()
         protocol.addError(subunit.RemotedTestCase("old mcdonald"), 
                           subunit.RemoteError("omg it works"))
         self.assertEqual(protocol.start_calls, [])
@@ -72,7 +72,7 @@ class TestMockTestProtocolServer(unittest.TestCase):
         self.assertEqual(protocol.success_calls, [])
         
     def test_add_failure(self):
-        protocol = MockTestProtocolServer()
+        protocol = MockTestProtocolServerClient()
         protocol.addFailure(subunit.RemotedTestCase("old mcdonald"),
                             subunit.RemoteError("omg it works"))
         self.assertEqual(protocol.start_calls, [])
@@ -83,7 +83,7 @@ class TestMockTestProtocolServer(unittest.TestCase):
         self.assertEqual(protocol.success_calls, [])
 
     def test_add_success(self):
-        protocol = MockTestProtocolServer()
+        protocol = MockTestProtocolServerClient()
         protocol.addSuccess(subunit.RemotedTestCase("test old mcdonald"))
         self.assertEqual(protocol.start_calls, [])
         self.assertEqual(protocol.error_calls, [])
@@ -103,7 +103,8 @@ class TestTestImports(unittest.TestCase):
 class TestTestProtocolServerPipe(unittest.TestCase):
 
     def test_story(self):
-        protocol = MockTestProtocolServer()
+        client = MockTestProtocolServerClient()
+        protocol = subunit.TestProtocolServer(client)
         pipe = StringIO("test old mcdonald\n"
                         "success old mcdonald\n"
                         "test bing crosby\n"
@@ -116,39 +117,40 @@ class TestTestProtocolServerPipe(unittest.TestCase):
         mcdonald = subunit.RemotedTestCase("old mcdonald")
         bing = subunit.RemotedTestCase("bing crosby")
         an_error = subunit.RemotedTestCase("an error")
-        self.assertEqual(protocol.start_calls, [mcdonald, bing, an_error])
-        self.assertEqual(protocol.error_calls, 
+        self.assertEqual(client.start_calls, [mcdonald, bing, an_error])
+        self.assertEqual(client.error_calls, 
                          [(an_error, subunit.RemoteError())])
-        self.assertEqual(protocol.failure_calls, 
+        self.assertEqual(client.failure_calls, 
                          [(bing,
                            subunit.RemoteError("foo.c:53:ERROR "
                                                "invalid state\n"))])
-        self.assertEqual(protocol.success_calls, [mcdonald])
+        self.assertEqual(client.success_calls, [mcdonald])
 
 
 class TestTestProtocolServerStartTest(unittest.TestCase):
     
     def setUp(self):
-        self.protocol = MockTestProtocolServer()
+        self.client = MockTestProtocolServerClient()
+        self.protocol = subunit.TestProtocolServer(self.client)
     
     def test_start_test(self):
         self.protocol.lineReceived("test old mcdonald\n")
-        self.assertEqual(self.protocol.start_calls,
+        self.assertEqual(self.client.start_calls,
                          [subunit.RemotedTestCase("old mcdonald")])
 
     def test_start_testing(self):
         self.protocol.lineReceived("testing old mcdonald\n")
-        self.assertEqual(self.protocol.start_calls,
+        self.assertEqual(self.client.start_calls,
                          [subunit.RemotedTestCase("old mcdonald")])
 
     def test_start_test_colon(self):
         self.protocol.lineReceived("test: old mcdonald\n")
-        self.assertEqual(self.protocol.start_calls,
+        self.assertEqual(self.client.start_calls,
                          [subunit.RemotedTestCase("old mcdonald")])
 
     def test_start_testing_colon(self):
         self.protocol.lineReceived("testing: old mcdonald\n")
-        self.assertEqual(self.protocol.start_calls,
+        self.assertEqual(self.client.start_calls,
                          [subunit.RemotedTestCase("old mcdonald")])
 
 
@@ -160,20 +162,22 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
         self.stdout = StringIO()
         sys.stdout = self.stdout
         self.test = subunit.RemotedTestCase("old mcdonald")
+        self.client = MockTestProtocolServerClient()
+        self.protocol = subunit.TestProtocolServer(self.client)
         
     def tearDown(self):
         sys.stdout = self.real_stdout
 
-    def keywords_before_test(self, protocol):
-        protocol.lineReceived("failure a\n")
-        protocol.lineReceived("failure: a\n")
-        protocol.lineReceived("error a\n")
-        protocol.lineReceived("error: a\n")
-        protocol.lineReceived("success a\n")
-        protocol.lineReceived("success: a\n")
-        protocol.lineReceived("successful a\n")
-        protocol.lineReceived("successful: a\n")
-        protocol.lineReceived("]\n")
+    def keywords_before_test(self):
+        self.protocol.lineReceived("failure a\n")
+        self.protocol.lineReceived("failure: a\n")
+        self.protocol.lineReceived("error a\n")
+        self.protocol.lineReceived("error: a\n")
+        self.protocol.lineReceived("success a\n")
+        self.protocol.lineReceived("success: a\n")
+        self.protocol.lineReceived("successful a\n")
+        self.protocol.lineReceived("successful: a\n")
+        self.protocol.lineReceived("]\n")
         self.assertEqual(self.stdout.getvalue(), "failure a\n"
                                                  "failure: a\n"
                                                  "error a\n"
@@ -185,59 +189,54 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
                                                  "]\n")
 
     def test_keywords_before_test(self):
-        protocol = MockTestProtocolServer()
-        self.keywords_before_test(protocol)
-        self.assertEqual(protocol.start_calls, [])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.keywords_before_test()
+        self.assertEqual(self.client.start_calls, [])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
     def test_keywords_after_error(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("error old mcdonald\n")
-        self.keywords_before_test(protocol)
-        self.assertEqual(protocol.start_calls, [self.test])
-        self.assertEqual(protocol.error_calls, 
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("error old mcdonald\n")
+        self.keywords_before_test()
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, 
                          [(self.test, subunit.RemoteError(""))])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls, [])
         
     def test_keywords_after_failure(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("failure old mcdonald\n")
-        self.keywords_before_test(protocol)
-        self.assertEqual(protocol.start_calls, [self.test])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.failure_calls, 
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("failure old mcdonald\n")
+        self.keywords_before_test()
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, 
                          [(self.test, subunit.RemoteError())])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.success_calls, [])
         
     def test_keywords_after_success(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("success old mcdonald\n")
-        self.keywords_before_test(protocol)
-        self.assertEqual(protocol.start_calls, [self.test])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [self.test])
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("success old mcdonald\n")
+        self.keywords_before_test()
+        self.assertEqual(self.client.start_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_keywords_after_test(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("failure a\n")
-        protocol.lineReceived("failure: a\n")
-        protocol.lineReceived("error a\n")
-        protocol.lineReceived("error: a\n")
-        protocol.lineReceived("success a\n")
-        protocol.lineReceived("success: a\n")
-        protocol.lineReceived("successful a\n")
-        protocol.lineReceived("successful: a\n")
-        protocol.lineReceived("]\n")
-        protocol.lineReceived("failure old mcdonald\n")
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("failure a\n")
+        self.protocol.lineReceived("failure: a\n")
+        self.protocol.lineReceived("error a\n")
+        self.protocol.lineReceived("error: a\n")
+        self.protocol.lineReceived("success a\n")
+        self.protocol.lineReceived("success: a\n")
+        self.protocol.lineReceived("successful a\n")
+        self.protocol.lineReceived("successful: a\n")
+        self.protocol.lineReceived("]\n")
+        self.protocol.lineReceived("failure old mcdonald\n")
         self.assertEqual(self.stdout.getvalue(), "test old mcdonald\n"
                                                  "failure a\n"
                                                  "failure: a\n"
@@ -248,30 +247,29 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
                                                  "successful a\n"
                                                  "successful: a\n"
                                                  "]\n")
-        self.assertEqual(protocol.start_calls, [self.test])
-        self.assertEqual(protocol.failure_calls, 
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.failure_calls, 
                          [(self.test, subunit.RemoteError())])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
     def test_keywords_during_failure(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("failure: old mcdonald [\n")
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("failure a\n")
-        protocol.lineReceived("failure: a\n")
-        protocol.lineReceived("error a\n")
-        protocol.lineReceived("error: a\n")
-        protocol.lineReceived("success a\n")
-        protocol.lineReceived("success: a\n")
-        protocol.lineReceived("successful a\n")
-        protocol.lineReceived("successful: a\n")
-        protocol.lineReceived(" ]\n")
-        protocol.lineReceived("]\n")
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("failure: old mcdonald [\n")
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("failure a\n")
+        self.protocol.lineReceived("failure: a\n")
+        self.protocol.lineReceived("error a\n")
+        self.protocol.lineReceived("error: a\n")
+        self.protocol.lineReceived("success a\n")
+        self.protocol.lineReceived("success: a\n")
+        self.protocol.lineReceived("successful a\n")
+        self.protocol.lineReceived("successful: a\n")
+        self.protocol.lineReceived(" ]\n")
+        self.protocol.lineReceived("]\n")
         self.assertEqual(self.stdout.getvalue(), "")
-        self.assertEqual(protocol.start_calls, [self.test])
-        self.assertEqual(protocol.failure_calls, 
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.failure_calls, 
                          [(self.test, subunit.RemoteError("test old mcdonald\n"
                                                   "failure a\n"
                                                   "failure: a\n"
@@ -282,107 +280,105 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
                                                   "successful a\n"
                                                   "successful: a\n"
                                                   "]\n"))])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
 
 class TestTestProtocolServerLostConnection(unittest.TestCase):
     
+    def setUp(self):
+        self.client = MockTestProtocolServerClient()
+        self.protocol = subunit.TestProtocolServer(self.client)
+
     def test_lost_connection_no_input(self):
-        protocol = MockTestProtocolServer()
-        protocol.lostConnection()
-        self.assertEqual(protocol.start_calls, [])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.protocol.lostConnection()
+        self.assertEqual(self.client.start_calls, [])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
     def test_lost_connection_after_start(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lostConnection()
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lostConnection()
         test = subunit.RemotedTestCase("old mcdonald")
-        self.assertEqual(protocol.start_calls, [test])
-        self.assertEqual(protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [test])
+        self.assertEqual(self.client.error_calls, [
             (test, subunit.RemoteError("lost connection during "
                                        "test 'old mcdonald'"))])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
     def test_lost_connected_after_error(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("error old mcdonald\n")
-        protocol.lostConnection()
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("error old mcdonald\n")
+        self.protocol.lostConnection()
         test = subunit.RemotedTestCase("old mcdonald")
-        self.assertEqual(protocol.start_calls, [test])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [test])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.error_calls, [
             (test, subunit.RemoteError(""))])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.success_calls, [])
         
     def test_lost_connection_during_error(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("error old mcdonald [\n")
-        protocol.lostConnection()
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("error old mcdonald [\n")
+        self.protocol.lostConnection()
         test = subunit.RemotedTestCase("old mcdonald")
-        self.assertEqual(protocol.start_calls, [test])
-        self.assertEqual(protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [test])
+        self.assertEqual(self.client.error_calls, [
             (test, subunit.RemoteError("lost connection during error report of"
                                        " test 'old mcdonald'"))])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
     def test_lost_connected_after_failure(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("failure old mcdonald\n")
-        protocol.lostConnection()
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("failure old mcdonald\n")
+        self.protocol.lostConnection()
         test = subunit.RemotedTestCase("old mcdonald")
-        self.assertEqual(protocol.start_calls, [test])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.failure_calls, [(test, subunit.RemoteError())])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.start_calls, [test])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, [(test, subunit.RemoteError())])
+        self.assertEqual(self.client.success_calls, [])
         
     def test_lost_connection_during_failure(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("failure old mcdonald [\n")
-        protocol.lostConnection()
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("failure old mcdonald [\n")
+        self.protocol.lostConnection()
         test = subunit.RemotedTestCase("old mcdonald")
-        self.assertEqual(protocol.start_calls, [test])
-        self.assertEqual(protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [test])
+        self.assertEqual(self.client.error_calls, [
             (test, subunit.RemoteError("lost connection during failure report"
                                        " of test 'old mcdonald'"))])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls, [])
 
     def test_lost_connection_after_success(self):
-        protocol = MockTestProtocolServer()
-        protocol.lineReceived("test old mcdonald\n")
-        protocol.lineReceived("success old mcdonald\n")
-        protocol.lostConnection()
-        self.assertEqual(protocol.start_calls,
+        self.protocol.lineReceived("test old mcdonald\n")
+        self.protocol.lineReceived("success old mcdonald\n")
+        self.protocol.lostConnection()
+        self.assertEqual(self.client.start_calls,
                          [subunit.RemotedTestCase("old mcdonald")])
-        self.assertEqual(protocol.error_calls, [])
-        self.assertEqual(protocol.failure_calls, [])
-        self.assertEqual(protocol.success_calls,
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
+        self.assertEqual(self.client.success_calls,
                          [subunit.RemotedTestCase("old mcdonald")])
 
 
 class TestTestProtocolServerAddError(unittest.TestCase):
     
     def setUp(self):
-        self.protocol = MockTestProtocolServer()
+        self.client = MockTestProtocolServerClient()
+        self.protocol = subunit.TestProtocolServer(self.client)
         self.protocol.lineReceived("test mcdonalds farm\n")
         self.test = subunit.RemotedTestCase("mcdonalds farm")
 
     def simple_error_keyword(self, keyword):
         self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [
             (self.test, subunit.RemoteError(""))])
-        self.assertEqual(self.protocol.failure_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
 
     def test_simple_error(self):
         self.simple_error_keyword("error")
@@ -393,19 +389,19 @@ class TestTestProtocolServerAddError(unittest.TestCase):
     def test_error_empty_message(self):
         self.protocol.lineReceived("error mcdonalds farm [\n")
         self.protocol.lineReceived("]\n")
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [
             (self.test, subunit.RemoteError(""))])
-        self.assertEqual(self.protocol.failure_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
 
     def error_quoted_bracket(self, keyword):
         self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword)
         self.protocol.lineReceived(" ]\n")
         self.protocol.lineReceived("]\n")
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [
             (self.test, subunit.RemoteError("]\n"))])
-        self.assertEqual(self.protocol.failure_calls, [])
+        self.assertEqual(self.client.failure_calls, [])
 
     def test_error_quoted_bracket(self):
         self.error_quoted_bracket("error")
@@ -417,15 +413,16 @@ class TestTestProtocolServerAddError(unittest.TestCase):
 class TestTestProtocolServerAddFailure(unittest.TestCase):
     
     def setUp(self):
-        self.protocol = MockTestProtocolServer()
+        self.client = MockTestProtocolServerClient()
+        self.protocol = subunit.TestProtocolServer(self.client)
         self.protocol.lineReceived("test mcdonalds farm\n")
         self.test = subunit.RemotedTestCase("mcdonalds farm")
 
     def simple_failure_keyword(self, keyword):
         self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [])
-        self.assertEqual(self.protocol.failure_calls, 
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, 
                          [(self.test, subunit.RemoteError())])
 
     def test_simple_failure(self):
@@ -437,18 +434,18 @@ class TestTestProtocolServerAddFailure(unittest.TestCase):
     def test_failure_empty_message(self):
         self.protocol.lineReceived("failure mcdonalds farm [\n")
         self.protocol.lineReceived("]\n")
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [])
-        self.assertEqual(self.protocol.failure_calls, 
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, 
                          [(self.test, subunit.RemoteError())])
 
     def failure_quoted_bracket(self, keyword):
         self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword)
         self.protocol.lineReceived(" ]\n")
         self.protocol.lineReceived("]\n")
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [])
-        self.assertEqual(self.protocol.failure_calls, 
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.failure_calls, 
                          [(self.test, subunit.RemoteError("]\n"))])
 
     def test_failure_quoted_bracket(self):
@@ -461,15 +458,16 @@ class TestTestProtocolServerAddFailure(unittest.TestCase):
 class TestTestProtocolServerAddSuccess(unittest.TestCase):
     
     def setUp(self):
-        self.protocol = MockTestProtocolServer()
+        self.client = MockTestProtocolServerClient()
+        self.protocol = subunit.TestProtocolServer(self.client)
         self.protocol.lineReceived("test mcdonalds farm\n")
         self.test = subunit.RemotedTestCase("mcdonalds farm")
 
     def simple_success_keyword(self, keyword):
         self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
-        self.assertEqual(self.protocol.start_calls, [self.test])
-        self.assertEqual(self.protocol.error_calls, [])
-        self.assertEqual(self.protocol.success_calls, [self.test])
+        self.assertEqual(self.client.start_calls, [self.test])
+        self.assertEqual(self.client.error_calls, [])
+        self.assertEqual(self.client.success_calls, [self.test])
 
     def test_simple_success(self):
         self.simple_success_keyword("failure")