Try to make the test set up a little more data driven.
authorJonathan Lange <jml@canonical.com>
Fri, 11 Feb 2011 16:22:21 +0000 (16:22 +0000)
committerJonathan Lange <jml@canonical.com>
Fri, 11 Feb 2011 16:22:21 +0000 (16:22 +0000)
python/subunit/tests/test_subunit_filter.py

index ac46f158c10049d017d250aab993ba86e94a6bb4..2f26f396c1f9db90cf1794e29445bdf8817ed464 100644 (file)
@@ -23,9 +23,34 @@ import subunit
 from subunit.test_results import TestResultFilter
 
 
+def make_stream(bytes):
+    """Take a string and return a stream from which that string can be read."""
+    stream = StringIO()
+    stream.write(bytes)
+    stream.seek(0)
+    return stream
+
+
 class TestTestResultFilter(unittest.TestCase):
     """Test for TestResultFilter, a TestResult object which filters tests."""
 
+    example_subunit_stream = """\
+tags: global
+test passed
+success passed
+test failed
+tags: local
+failure failed
+test error
+error error [
+error details
+]
+test skipped
+skip skipped
+test todo
+xfail todo
+"""
+
     def test_default(self):
         """The default is to exclude success and include everything else."""
         filtered_result = unittest.TestResult()
@@ -95,35 +120,10 @@ class TestTestResultFilter(unittest.TestCase):
         self.assertEqual(1, filtered_result.testsRun)
 
     def run_tests(self, result_filter):
-        input_stream = self.getTestStream()
+        input_stream = make_stream(self.example_subunit_stream)
         test = subunit.ProtocolTestCase(input_stream)
         test.run(result_filter)
 
-    def getTestStream(self):
-        # While TestResultFilter works on python objects, using a subunit
-        # stream is an easy pithy way of getting a series of test objects to
-        # call into the TestResult, and as TestResultFilter is intended for
-        # use with subunit also has the benefit of detecting any interface
-        # skew issues.
-        input_stream = StringIO()
-        input_stream.write("""tags: global
-test passed
-success passed
-test failed
-tags: local
-failure failed
-test error
-error error [
-error details
-]
-test skipped
-skip skipped
-test todo
-xfail todo
-""")
-        input_stream.seek(0)
-        return input_stream
-
 
 def test_suite():
     loader = subunit.tests.TestUtil.TestLoader()