summaryrefslogtreecommitdiff
path: root/python/subunit/__init__.py
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-07-28 23:32:10 +1000
committerRobert Collins <robertc@robertcollins.net>2009-07-28 23:32:10 +1000
commit7aa495ccf553cf96c04cf2c2419aec8dd7465fac (patch)
tree5b90a06fe9dadb0a5fea1cdb61caaddcb512d575 /python/subunit/__init__.py
parent9361b85f6b08a1b0838d157a6b2f427291a06aa7 (diff)
downloadsubunit-git-7aa495ccf553cf96c04cf2c2419aec8dd7465fac.tar.gz
Basic progress support.
Diffstat (limited to 'python/subunit/__init__.py')
-rw-r--r--python/subunit/__init__.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index 7859ea7..e0a4ccc 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -28,6 +28,10 @@ import unittest
import iso8601
+SEEK_CUR = os.SEEK_CUR
+SEEK_SET = os.SEEK_SET
+
+
def test_suite():
import subunit.tests
return subunit.tests.test_suite()
@@ -200,6 +204,18 @@ class TestProtocolServer(object):
else:
self.stdOutLineReceived(line)
+ def _handleProgress(self, offset, line):
+ """Process a progress directive."""
+ line = line[offset:].strip()
+ if line[0] in '+-':
+ whence = SEEK_CUR
+ else:
+ whence = SEEK_SET
+ delta = int(line)
+ progress_method = getattr(self.client, 'progress', None)
+ if callable(progress_method):
+ progress_method(delta, whence)
+
def _handleTags(self, offset, line):
"""Process a tags command."""
tags = line[offset:].split()
@@ -243,6 +259,8 @@ class TestProtocolServer(object):
self._addError(offset, line)
elif cmd == 'failure':
self._addFailure(offset, line)
+ elif cmd == 'progress':
+ self._handleProgress(offset, line)
elif cmd == 'skip':
self._addSkip(offset, line)
elif cmd in ('success', 'successful'):
@@ -355,6 +373,21 @@ class TestProtocolClient(unittest.TestResult):
"""Mark a test as starting its test run."""
self._stream.write("test: %s\n" % test.id())
+ def progress(self, offset, whence):
+ """Provide indication about the progress/length of the test run.
+
+ :param offset: Information about the number of tests remaining. If
+ whence is SEEK_CUR, then offset increases/decreases the remaining
+ test count. If whence is SEEK_SET, then offset specifies exactly
+ the remaining test count.
+ :param whence: One of SEEK_CUR or SEEK_SET.
+ """
+ if whence == SEEK_CUR and offset > -1:
+ prefix = "+"
+ else:
+ prefix = ""
+ self._stream.write("progress: %s%s\n" % (prefix, offset))
+
def time(self, a_datetime):
"""Inform the client of the time.