From 7aa495ccf553cf96c04cf2c2419aec8dd7465fac Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 28 Jul 2009 23:32:10 +1000 Subject: Basic progress support. --- python/subunit/__init__.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'python/subunit/__init__.py') 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. -- cgit v1.2.1