summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/subunit/__init__.py15
-rw-r--r--python/subunit/tests/test_test_protocol.py66
2 files changed, 49 insertions, 32 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index fb6c83e..1a20dab 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -17,11 +17,13 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
+import calendar
import os
+import re
from StringIO import StringIO
import subprocess
import sys
-import re
+import time
import unittest
def test_suite():
@@ -207,6 +209,14 @@ class TestProtocolServer(object):
update_tags.update(new_tags)
update_tags.difference_update(gone_tags)
+ def _handleTime(self, offset, line):
+ # Accept it, but do not do anything with it yet.
+ event_time = time.strptime(line[offset:-1], "%Y-%m-%d %H:%M:%SZ")
+ time_seconds = calendar.timegm(event_time)
+ time_method = getattr(self.client, 'time', None)
+ if callable(time_method):
+ time_method(time_seconds)
+
def lineReceived(self, line):
"""Call the appropriate local method for the received line."""
if line == "]\n":
@@ -236,8 +246,7 @@ class TestProtocolServer(object):
elif cmd in ('tags',):
self._handleTags(offset, line)
elif cmd in ('time',):
- # Accept it, but do not do anything with it yet.
- pass
+ self._handleTime(offset, line)
elif cmd == 'xfail':
self._addExpectedFail(offset, line)
else:
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index ead0ac6..1ffaf30 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -24,39 +24,40 @@ import subunit
import sys
import time
-try:
- class MockTestProtocolServerClient(object):
- """A mock protocol server client to test callbacks."""
- def __init__(self):
- self.end_calls = []
- self.error_calls = []
- self.failure_calls = []
- self.skip_calls = []
- self.start_calls = []
- self.success_calls = []
- super(MockTestProtocolServerClient, self).__init__()
+class MockTestProtocolServerClient(object):
+ """A mock protocol server client to test callbacks."""
- def addError(self, test, error):
- self.error_calls.append((test, error))
+ def __init__(self):
+ self.end_calls = []
+ self.error_calls = []
+ self.failure_calls = []
+ self.skip_calls = []
+ self.start_calls = []
+ self.success_calls = []
+ self._time = None
+ super(MockTestProtocolServerClient, self).__init__()
- def addFailure(self, test, error):
- self.failure_calls.append((test, error))
+ def addError(self, test, error):
+ self.error_calls.append((test, error))
- def addSkip(self, test, reason):
- self.skip_calls.append((test, reason))
+ def addFailure(self, test, error):
+ self.failure_calls.append((test, error))
- def addSuccess(self, test):
- self.success_calls.append(test)
+ def addSkip(self, test, reason):
+ self.skip_calls.append((test, reason))
- def stopTest(self, test):
- self.end_calls.append(test)
+ def addSuccess(self, test):
+ self.success_calls.append(test)
- def startTest(self, test):
- self.start_calls.append(test)
+ def stopTest(self, test):
+ self.end_calls.append(test)
-except AttributeError:
- MockTestProtocolServer = None
+ def startTest(self, test):
+ self.start_calls.append(test)
+
+ def time(self, time):
+ self._time = time
class TestMockTestProtocolServer(unittest.TestCase):
@@ -763,15 +764,22 @@ class TestTestProtocolServerStreamTags(unittest.TestCase):
class TestTestProtocolServerStreamTime(unittest.TestCase):
"""Test managing time information at the protocol level."""
- def setUp(self):
- self.client = MockTestProtocolServerClient()
+ def test_time_accepted_stdlib(self):
+ self.result = unittest.TestResult()
self.stream = StringIO()
- self.protocol = subunit.TestProtocolServer(self.client,
+ self.protocol = subunit.TestProtocolServer(self.result,
stream=self.stream)
+ self.protocol.lineReceived("time: 2001-12-12 12:59:59Z\n")
+ self.assertEqual("", self.stream.getvalue())
- def test_time_accepted(self):
+ def test_time_accepted_extended(self):
+ self.result = MockTestProtocolServerClient()
+ self.stream = StringIO()
+ self.protocol = subunit.TestProtocolServer(self.result,
+ stream=self.stream)
self.protocol.lineReceived("time: 2001-12-12 12:59:59Z\n")
self.assertEqual("", self.stream.getvalue())
+ self.assertEqual(1008161999, self.result._time)
class TestRemotedTestCase(unittest.TestCase):