diff options
| author | Robert Collins <robertc@robertcollins.net> | 2009-07-30 07:24:54 +1000 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2009-07-30 07:24:54 +1000 |
| commit | 30b4dc09bafcd17622550ffdb3ce4576e7d1cf03 (patch) | |
| tree | 64ffd8e2c239390d2cd86df61a593e093080d34c /python/subunit/__init__.py | |
| parent | 82bce267e6f118f8d1e951606a346a42128e85c0 (diff) | |
| parent | 89296f1cea44baf53db9194bebeee03847eb7b7f (diff) | |
| download | subunit-git-30b4dc09bafcd17622550ffdb3ce4576e7d1cf03.tar.gz | |
Merge linear progress support for the protocol definition and python bindings.
Diffstat (limited to 'python/subunit/__init__.py')
| -rw-r--r-- | python/subunit/__init__.py | 33 |
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. |
