summaryrefslogtreecommitdiff
path: root/python/subunit/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/subunit/tests')
-rw-r--r--python/subunit/tests/__init__.py2
-rw-r--r--python/subunit/tests/test_progress_model.py121
-rw-r--r--python/subunit/tests/test_test_protocol.py25
-rw-r--r--python/subunit/tests/test_test_results.py7
4 files changed, 145 insertions, 10 deletions
diff --git a/python/subunit/tests/__init__.py b/python/subunit/tests/__init__.py
index 11f3095..bbe12b1 100644
--- a/python/subunit/tests/__init__.py
+++ b/python/subunit/tests/__init__.py
@@ -19,6 +19,7 @@
from subunit.tests import (
TestUtil,
+ test_progress_model,
test_subunit_filter,
test_subunit_stats,
test_subunit_tags,
@@ -29,6 +30,7 @@ from subunit.tests import (
def test_suite():
result = TestUtil.TestSuite()
+ result.addTest(test_progress_model.test_suite())
result.addTest(test_test_results.test_suite())
result.addTest(test_test_protocol.test_suite())
result.addTest(test_tap2subunit.test_suite())
diff --git a/python/subunit/tests/test_progress_model.py b/python/subunit/tests/test_progress_model.py
new file mode 100644
index 0000000..60beb41
--- /dev/null
+++ b/python/subunit/tests/test_progress_model.py
@@ -0,0 +1,121 @@
+#
+# subunit: extensions to Python unittest to get test results from subprocesses.
+# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import unittest
+
+import subunit
+from subunit.progress_model import ProgressModel
+
+
+class TestProgressModel(unittest.TestCase):
+
+ def assertProgressSummary(self, pos, total, progress):
+ """Assert that a progress model has reached a particular point."""
+ self.assertEqual(pos, progress.pos())
+ self.assertEqual(total, progress.width())
+
+ def test_new_progress_0_0(self):
+ progress = ProgressModel()
+ self.assertProgressSummary(0, 0, progress)
+
+ def test_advance_0_0(self):
+ progress = ProgressModel()
+ progress.advance()
+ self.assertProgressSummary(1, 0, progress)
+
+ def test_advance_1_0(self):
+ progress = ProgressModel()
+ progress.advance()
+ self.assertProgressSummary(1, 0, progress)
+
+ def test_set_width_absolute(self):
+ progress = ProgressModel()
+ progress.set_width(10)
+ self.assertProgressSummary(0, 10, progress)
+
+ def test_set_width_absolute_preserves_pos(self):
+ progress = ProgressModel()
+ progress.advance()
+ progress.set_width(2)
+ self.assertProgressSummary(1, 2, progress)
+
+ def test_adjust_width(self):
+ progress = ProgressModel()
+ progress.adjust_width(10)
+ self.assertProgressSummary(0, 10, progress)
+ progress.adjust_width(-10)
+ self.assertProgressSummary(0, 0, progress)
+
+ def test_adjust_width_preserves_pos(self):
+ progress = ProgressModel()
+ progress.advance()
+ progress.adjust_width(10)
+ self.assertProgressSummary(1, 10, progress)
+ progress.adjust_width(-10)
+ self.assertProgressSummary(1, 0, progress)
+
+ def test_push_preserves_progress(self):
+ progress = ProgressModel()
+ progress.adjust_width(3)
+ progress.advance()
+ progress.push()
+ self.assertProgressSummary(1, 3, progress)
+
+ def test_advance_advances_substack(self):
+ progress = ProgressModel()
+ progress.adjust_width(3)
+ progress.advance()
+ progress.push()
+ progress.adjust_width(1)
+ progress.advance()
+ self.assertProgressSummary(2, 3, progress)
+
+ def test_adjust_width_adjusts_substack(self):
+ progress = ProgressModel()
+ progress.adjust_width(3)
+ progress.advance()
+ progress.push()
+ progress.adjust_width(2)
+ progress.advance()
+ self.assertProgressSummary(3, 6, progress)
+
+ def test_set_width_adjusts_substack(self):
+ progress = ProgressModel()
+ progress.adjust_width(3)
+ progress.advance()
+ progress.push()
+ progress.set_width(2)
+ progress.advance()
+ self.assertProgressSummary(3, 6, progress)
+
+ def test_pop_restores_progress(self):
+ progress = ProgressModel()
+ progress.adjust_width(3)
+ progress.advance()
+ progress.push()
+ progress.adjust_width(1)
+ progress.advance()
+ progress.pop()
+ self.assertProgressSummary(1, 3, progress)
+
+
+def test_suite():
+ loader = subunit.tests.TestUtil.TestLoader()
+ result = loader.loadTestsFromName(__name__)
+ return result
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index a036192..2b90b9e 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -129,8 +129,8 @@ class TestMockTestProtocolServer(unittest.TestCase):
def test_progress(self):
protocol = MockTestProtocolServerClient()
- protocol.progress(-1, subunit.SEEK_CUR)
- self.assertEqual(protocol.progress_calls, [(-1, subunit.SEEK_CUR)])
+ protocol.progress(-1, subunit.PROGRESS_CUR)
+ self.assertEqual(protocol.progress_calls, [(-1, subunit.PROGRESS_CUR)])
class TestTestImports(unittest.TestCase):
@@ -790,12 +790,15 @@ class TestTestProtocolServerProgress(unittest.TestCase):
self.protocol = subunit.TestProtocolServer(self.result,
stream=self.stream)
self.protocol.lineReceived("progress: 23")
+ self.protocol.lineReceived("progress: push")
self.protocol.lineReceived("progress: -2")
+ self.protocol.lineReceived("progress: pop")
self.protocol.lineReceived("progress: +4")
self.assertEqual("", self.stream.getvalue())
self.assertEqual(
- [(23, subunit.SEEK_SET), (-2, subunit.SEEK_CUR),
- (4, subunit.SEEK_CUR)],
+ [(23, subunit.PROGRESS_SET), (None, subunit.PROGRESS_PUSH),
+ (-2, subunit.PROGRESS_CUR), (None, subunit.PROGRESS_POP),
+ (4, subunit.PROGRESS_CUR)],
self.result.progress_calls)
@@ -1095,17 +1098,25 @@ class TestTestProtocolClient(unittest.TestCase):
'skip: %s [\nHas it really?\n]\n' % self.test.id())
def test_progress_set(self):
- self.protocol.progress(23, subunit.SEEK_SET)
+ self.protocol.progress(23, subunit.PROGRESS_SET)
self.assertEqual(self.io.getvalue(), 'progress: 23\n')
def test_progress_neg_cur(self):
- self.protocol.progress(-23, subunit.SEEK_CUR)
+ self.protocol.progress(-23, subunit.PROGRESS_CUR)
self.assertEqual(self.io.getvalue(), 'progress: -23\n')
def test_progress_pos_cur(self):
- self.protocol.progress(23, subunit.SEEK_CUR)
+ self.protocol.progress(23, subunit.PROGRESS_CUR)
self.assertEqual(self.io.getvalue(), 'progress: +23\n')
+ def test_progress_pop(self):
+ self.protocol.progress(1234, subunit.PROGRESS_POP)
+ self.assertEqual(self.io.getvalue(), 'progress: pop\n')
+
+ def test_progress_push(self):
+ self.protocol.progress(1234, subunit.PROGRESS_PUSH)
+ self.assertEqual(self.io.getvalue(), 'progress: push\n')
+
def test_time(self):
# Calling time() outputs a time signal immediately.
self.protocol.time(
diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py
index 4537304..2f76917 100644
--- a/python/subunit/tests/test_test_results.py
+++ b/python/subunit/tests/test_test_results.py
@@ -21,10 +21,11 @@ import datetime
import unittest
from StringIO import StringIO
import os
-import subunit.test_results
import sys
+import subunit
import subunit.iso8601 as iso8601
+import subunit.test_results
class LoggingDecorator(subunit.test_results.HookedTestResultDecorator):
@@ -109,7 +110,7 @@ class TestHookedTestResultDecorator(unittest.TestCase):
self.result.addUnexpectedSuccess(self)
def test_progress(self):
- self.result.progress(1, os.SEEK_SET)
+ self.result.progress(1, subunit.PROGRESS_SET)
def test_wasSuccessful(self):
self.result.wasSuccessful()
@@ -139,7 +140,7 @@ class TestAutoTimingTestResultDecorator(unittest.TestCase):
self.assertNotEqual(None, self.result.decorated._calls[0])
def test_no_time_from_progress(self):
- self.result.progress(1, os.SEEK_CUR)
+ self.result.progress(1, subunit.PROGRESS_CUR)
self.assertEqual(0, len(self.result.decorated._calls))
def test_no_time_from_shouldStop(self):