Rev 4166: Add builtin subunit support. in http://people.ubuntu.com/~robertc/baz2.0/pending/subunit

Robert Collins robertc at robertcollins.net
Fri Mar 20 01:05:07 GMT 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/subunit

------------------------------------------------------------
revno: 4166
revision-id: robertc at robertcollins.net-20090320010458-v8ervol4dpjxqx48
parent: pqm at pqm.ubuntu.com-20090319035632-3o6ewx7kwnk42b63
committer: Robert Collins <robertc at robertcollins.net>
branch nick: subunit
timestamp: Fri 2009-03-20 12:04:58 +1100
message:
  Add builtin subunit support.
=== modified file 'NEWS'
--- a/NEWS	2009-03-19 03:13:24 +0000
+++ b/NEWS	2009-03-20 01:04:58 +0000
@@ -142,7 +142,11 @@
 * Removed ``InterRemoteToOther``, ``InterOtherToRemote`` and
   ``InterPackToRemotePack`` classes, as they are now unnecessary.
   (Andrew Bennetts)
-  
+
+* ``bzr selftest`` now accepts ``--subunit`` to run in subunit output
+  mode. Requires ``lp:subunit`` installed to work, but is not a hard
+  dependency. (Robert Collins)
+
 * ``_walk_to_common_revisions`` will now batch up at least 50
   revisions before calling ``get_parent_map`` on the target,
   regardless of ``InterRepository``.

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-03-17 22:22:57 +0000
+++ b/bzrlib/builtins.py	2009-03-20 01:04:58 +0000
@@ -3143,6 +3143,8 @@
                             short_name='x',
                             help='Exclude tests that match this regular'
                                  ' expression.'),
+                     Option('subunit',
+                        help='Output test progress via subunit.'),
                      Option('strict', help='Fail on missing dependencies or '
                             'known failures.'),
                      Option('load-list', type=str, argname='TESTLISTFILE',
@@ -3165,7 +3167,7 @@
             lsprof_timed=None, cache_dir=None,
             first=False, list_only=False,
             randomize=None, exclude=None, strict=False,
-            load_list=None, debugflag=None, starting_with=None):
+            load_list=None, debugflag=None, starting_with=None, subunit=False):
         from bzrlib.tests import selftest
         import bzrlib.benchmarks as benchmarks
         from bzrlib.benchmarks import tree_creator
@@ -3187,6 +3189,9 @@
             pattern = '|'.join(testspecs_list)
         else:
             pattern = ".*"
+        if subunit:
+            from bzrlib.tests import SubUnitBzrRunner
+            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
         if benchmark:
             test_suite_factory = benchmarks.test_suite
             # Unless user explicitly asks for quiet, be verbose in benchmarks

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-03-17 05:15:26 +0000
+++ b/bzrlib/tests/__init__.py	2009-03-20 01:04:58 +0000
@@ -3546,3 +3546,31 @@
         return 'case-insensitive filesystem'
 
 CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
+
+
+class _SubUnitFeature(Feature):
+    """Check if subunit is available."""
+
+    def _probe(self):
+        try:
+            import subunit
+            return True
+        except ImportError:
+            return False
+
+    def feature_name(self):
+        return 'subunit'
+
+SubUnitFeature = _SubUnitFeature()
+# Only define SubUnitBzrRunner if subunit is available.
+try:
+    from subunit import TestProtocolClient
+    class SubUnitBzrRunner(TextTestRunner):
+        def run(self, test):
+            # undo out claim for testing which looks like a test start to subunit
+            self.stream.write("success: %s\n" % (osutils.realpath(sys.argv[0]),))
+            result = TestProtocolClient(self.stream)
+            test.run(result)
+            return result
+except ImportError:
+    pass

=== modified file 'bzrlib/tests/blackbox/test_selftest.py'
--- a/bzrlib/tests/blackbox/test_selftest.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/blackbox/test_selftest.py	2009-03-20 01:04:58 +0000
@@ -16,10 +16,12 @@
 
 """UI tests for the test framework."""
 
+from cStringIO import StringIO
 import os
 import re
 import signal
 import sys
+import unittest
 
 import bzrlib
 from bzrlib import (
@@ -27,6 +29,7 @@
     )
 from bzrlib.errors import ParamikoNotPresent
 from bzrlib.tests import (
+                          SubUnitFeature,
                           TestCase,
                           TestCaseInTempDir,
                           TestCaseWithMemoryTransport,
@@ -88,6 +91,21 @@
             TestOptions.current_test = None
             TestCaseWithMemoryTransport.TEST_ROOT = old_root
 
+    def test_subunit(self):
+        """Passing --subunit results in subunit output."""
+        self.requireFeature(SubUnitFeature)
+        from subunit import ProtocolTestCase
+        stdout = self.run_bzr(
+            'selftest --subunit --no-plugins '
+            'tests.test_selftest.SelftestTests.test_import_tests')[0]
+        stream = StringIO(str(stdout))
+        test = ProtocolTestCase(stream)
+        result = unittest.TestResult()
+        test.run(result)
+        # 1 to deal with the 'test:' noise at the start, and 1 for the one we
+        # ran.
+        self.assertEqual(2, result.testsRun)
+
 
 class TestRunBzr(ExternalBase):
 




More information about the bazaar-commits mailing list