summaryrefslogtreecommitdiff
path: root/python/subunit
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-07-22 18:46:04 +1000
committerRobert Collins <robertc@robertcollins.net>2009-07-22 18:46:04 +1000
commit1f0757a4af48338e3a046093d991a8c40ab31088 (patch)
treee54bd18bc7b26c64ca07cc19533d34a02527c701 /python/subunit
parent926e1ba475443641089e1146e46462ae4c895d57 (diff)
downloadsubunit-git-1f0757a4af48338e3a046093d991a8c40ab31088.tar.gz
Add TestProtocolClient.time().
Diffstat (limited to 'python/subunit')
-rw-r--r--python/subunit/__init__.py15
-rw-r--r--python/subunit/tests/test_test_protocol.py10
2 files changed, 23 insertions, 2 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index 72d5b2d..7859ea7 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -213,7 +213,10 @@ class TestProtocolServer(object):
def _handleTime(self, offset, line):
# Accept it, but do not do anything with it yet.
- event_time = iso8601.parse_date(line[offset:-1])
+ try:
+ event_time = iso8601.parse_date(line[offset:-1])
+ except TypeError, e:
+ raise TypeError("Failed to parse %r, got %r" % (line, e))
time_method = getattr(self.client, 'time', None)
if callable(time_method):
time_method(event_time)
@@ -352,6 +355,16 @@ class TestProtocolClient(unittest.TestResult):
"""Mark a test as starting its test run."""
self._stream.write("test: %s\n" % test.id())
+ def time(self, a_datetime):
+ """Inform the client of the time.
+
+ ":param datetime: A datetime.datetime object.
+ """
+ time = a_datetime.astimezone(iso8601.Utc())
+ self._stream.write("time: %04d-%02d-%02d %02d:%02d:%02d.%06dZ\n" % (
+ time.year, time.month, time.day, time.hour, time.minute,
+ time.second, time.microsecond))
+
def done(self):
"""Obey the testtools result.done() interface."""
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index f140b87..8124042 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -969,7 +969,7 @@ class TestTestProtocolClient(unittest.TestCase):
self.assertEqual(self.io.getvalue(), "test: %s\n" % self.test.id())
def test_stop_test(self):
- """Test stopTest on a TestProtocolClient."""
+ # stopTest doesn't output anything.
self.protocol.stopTest(self.test)
self.assertEqual(self.io.getvalue(), "")
@@ -1005,6 +1005,14 @@ class TestTestProtocolClient(unittest.TestCase):
self.io.getvalue(),
'skip: %s [\nHas it really?\n]\n' % self.test.id())
+ def test_time(self):
+ # Calling time() outputs a time signal immediately.
+ self.protocol.time(
+ datetime.datetime(2009,10,11,12,13,14,15, iso8601.Utc()))
+ self.assertEqual(
+ "time: 2009-10-11 12:13:14.000015Z\n",
+ self.io.getvalue())
+
def test_suite():
loader = subunit.tests.TestUtil.TestLoader()