Move Failure reporting to the new details API.
authorRobert Collins <robertc@robertcollins.net>
Sat, 24 Oct 2009 09:10:23 +0000 (20:10 +1100)
committerRobert Collins <robertc@robertcollins.net>
Sat, 24 Oct 2009 09:10:23 +0000 (20:10 +1100)
python/subunit/__init__.py
python/subunit/content.py
python/subunit/tests/test_test_protocol.py

index a981a821cc56af95c3eb8dd99e8b8bb08338e1b2..5c8585f758242b1eb2cff74f98e990ef624f8542 100644 (file)
@@ -284,7 +284,8 @@ class _InTest(_ParserState):
             self.parser._reading_xfail_details)
 
     def _failure(self):
-        self.parser.client.addFailure(self.parser._current_test, RemoteError())
+        self.parser.client.addFailure(self.parser._current_test,
+            details={})
 
     def addFailure(self, offset, line):
         """A 'failure:' directive has been read."""
@@ -363,7 +364,7 @@ class _ReadingFailureDetails(_ReadingDetails):
 
     def _report_outcome(self):
         self.parser.client.addFailure(self.parser._current_test,
-            RemoteError(self.details_parser.get_message()))
+            details=self.details_parser.get_details())
 
     def _outcome_label(self):
         return "failure"
index d7d389350843246a9b4666a88ac643a29a97a51c..5961e2440f2a631015cd61f27e40a69ed2954ade 100644 (file)
@@ -50,6 +50,10 @@ class Content(object):
         """Iterate over bytestrings of the serialised content."""
         return self._get_bytes()
 
+    def __repr__(self):
+        return "<Content type=%r, value=%r>" % (
+            self.content_type, ''.join(self.iter_bytes()))
+
 
 class TracebackContent(Content):
     """Content object for tracebacks.
index 39734b5fd17e271b46d68cc55529b942e44e1248..d117a40025f71ad0496a16ced45432a630819b3f 100644 (file)
@@ -70,7 +70,9 @@ class TestTestProtocolServerPipe(unittest.TestCase):
                          [(an_error, 'RemoteException: \n\n')])
         self.assertEqual(
             client.failures,
-            [(bing, "RemoteException: foo.c:53:ERROR invalid state\n\n")])
+            [(bing, "RemoteException: Text attachment: traceback\n"
+                "------------\nfoo.c:53:ERROR invalid state\n"
+                "------------\n\n")])
         self.assertEqual(client.testsRun, 3)
 
 
@@ -106,7 +108,7 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
     def setUp(self):
         self.stdout = StringIO()
         self.test = subunit.RemotedTestCase("old mcdonald")
-        self.client = Python26TestResult()
+        self.client = ExtendedTestResult()
         self.protocol = subunit.TestProtocolServer(self.client, self.stdout)
 
     def keywords_before_test(self):
@@ -139,7 +141,7 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
         self.keywords_before_test()
         self.assertEqual([
             ('startTest', self.test),
-            ('addError', self.test, subunit.RemoteError("")),
+            ('addError', self.test, {}),
             ('stopTest', self.test),
             ], self.client._calls)
 
@@ -149,7 +151,7 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
         self.keywords_before_test()
         self.assertEqual(self.client._calls, [
             ('startTest', self.test),
-            ('addFailure', self.test, subunit.RemoteError("")),
+            ('addFailure', self.test, {}),
             ('stopTest', self.test),
             ])
 
@@ -188,11 +190,13 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
                                                  "]\n")
         self.assertEqual(self.client._calls, [
             ('startTest', self.test),
-            ('addFailure', self.test, subunit.RemoteError("")),
+            ('addFailure', self.test, {}),
             ('stopTest', self.test),
             ])
 
     def test_keywords_during_failure(self):
+        # A smoke test to make sure that the details parsers have control
+        # appropriately.
         self.protocol.lineReceived("test old mcdonald\n")
         self.protocol.lineReceived("failure: old mcdonald [\n")
         self.protocol.lineReceived("test old mcdonald\n")
@@ -207,7 +211,10 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
         self.protocol.lineReceived(" ]\n")
         self.protocol.lineReceived("]\n")
         self.assertEqual(self.stdout.getvalue(), "")
-        failure = subunit.RemoteError("test old mcdonald\n"
+        details = {}
+        details['traceback'] = Content(ContentType("text", "x-traceback"),
+            lambda:[
+            "test old mcdonald\n"
             "failure a\n"
             "failure: a\n"
             "error a\n"
@@ -216,10 +223,10 @@ class TestTestProtocolServerPassThrough(unittest.TestCase):
             "success: a\n"
             "successful a\n"
             "successful: a\n"
-            "]\n")
+            "]\n"])
         self.assertEqual(self.client._calls, [
             ('startTest', self.test),
-            ('addFailure', self.test, failure),
+            ('addFailure', self.test, details),
             ('stopTest', self.test),
             ])
 
@@ -404,20 +411,23 @@ class TestTestProtocolServerAddError(unittest.TestCase):
 class TestTestProtocolServerAddFailure(unittest.TestCase):
 
     def setUp(self):
-        self.client = Python26TestResult()
+        self.client = ExtendedTestResult()
         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)
-        failure = subunit.RemoteError("")
+    def assertFailure(self, details):
         self.assertEqual([
             ('startTest', self.test),
-            ('addFailure', self.test, failure),
+            ('addFailure', self.test, details),
             ('stopTest', self.test),
             ], self.client._calls)
 
+    def simple_failure_keyword(self, keyword):
+        self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
+        details = {}
+        self.assertFailure(details)
+
     def test_simple_failure(self):
         self.simple_failure_keyword("failure")
 
@@ -427,23 +437,19 @@ class TestTestProtocolServerAddFailure(unittest.TestCase):
     def test_failure_empty_message(self):
         self.protocol.lineReceived("failure mcdonalds farm [\n")
         self.protocol.lineReceived("]\n")
-        failure = subunit.RemoteError("")
-        self.assertEqual([
-            ('startTest', self.test),
-            ('addFailure', self.test, failure),
-            ('stopTest', self.test),
-            ], self.client._calls)
+        details = {}
+        details['traceback'] = Content(ContentType("text", "x-traceback"),
+            lambda:[""])
+        self.assertFailure(details)
 
     def failure_quoted_bracket(self, keyword):
         self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword)
         self.protocol.lineReceived(" ]\n")
         self.protocol.lineReceived("]\n")
-        failure = subunit.RemoteError("]\n")
-        self.assertEqual([
-            ('startTest', self.test),
-            ('addFailure', self.test, failure),
-            ('stopTest', self.test),
-            ], self.client._calls)
+        details = {}
+        details['traceback'] = Content(ContentType("text", "x-traceback"),
+            lambda:["]\n"])
+        self.assertFailure(details)
 
     def test_failure_quoted_bracket(self):
         self.failure_quoted_bracket("failure")
@@ -814,24 +820,25 @@ class TestExecTestCase(unittest.TestCase):
         self.assertEqual(1, result.testsRun)
 
     def test_run(self):
-        result = Python26TestResult()
+        result = ExtendedTestResult()
         test = self.SampleExecTestCase("test_sample_method")
         test.run(result)
         mcdonald = subunit.RemotedTestCase("old mcdonald")
         bing = subunit.RemotedTestCase("bing crosby")
+        bing_details = {}
+        bing_details['traceback'] = Content(ContentType("text", "x-traceback"),
+            lambda:["foo.c:53:ERROR invalid state\n"])
         an_error = subunit.RemotedTestCase("an error")
-        error_error = subunit.RemoteError()
-        bing_failure = subunit.RemoteError(
-            "foo.c:53:ERROR invalid state\n")
+        error_details = {}
         self.assertEqual([
             ('startTest', mcdonald),
             ('addSuccess', mcdonald),
             ('stopTest', mcdonald),
             ('startTest', bing),
-            ('addFailure', bing, bing_failure),
+            ('addFailure', bing, bing_details),
             ('stopTest', bing),
             ('startTest', an_error),
-            ('addError', an_error, error_error),
+            ('addError', an_error, error_details),
             ('stopTest', an_error),
             ], result._calls)