Rev 4004: (robertc) Allow plugins to specify test runner classes for in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Feb 12 06:24:12 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4004
revision-id: pqm at pqm.ubuntu.com-20090212062408-yq0glwncmdzo5uzm
parent: pqm at pqm.ubuntu.com-20090212043701-kh62kseozbbcaypb
parent: robertc at robertcollins.net-20090212054329-ubctdgf2d39lltbx
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-02-12 06:24:08 +0000
message:
  (robertc) Allow plugins to specify test runner classes for
  	cmd_selftest. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 4000.2.4
    revision-id: robertc at robertcollins.net-20090212054329-ubctdgf2d39lltbx
    parent: robertc at robertcollins.net-20090211234655-zbnw36me1zfzorv0
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: test-result-registry
    timestamp: Thu 2009-02-12 16:43:29 +1100
    message:
      PEP8ification of selftest_kwargs in cmd_selftest.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 4000.2.3
    revision-id: robertc at robertcollins.net-20090211234655-zbnw36me1zfzorv0
    parent: robertc at robertcollins.net-20090211222518-32dloushiwrnzurr
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: test-result-registry
    timestamp: Thu 2009-02-12 10:46:55 +1100
    message:
      Allow extra options to bzrlib.tests.selftest from plugins.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
    ------------------------------------------------------------
    revno: 4000.2.2
    revision-id: robertc at robertcollins.net-20090211222518-32dloushiwrnzurr
    parent: robertc at robertcollins.net-20090211214755-pltzfmev8komxryt
    parent: robertc at robertcollins.net-20090211124950-70c4aa2a8ub65d0s
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: test-result-registry
    timestamp: Thu 2009-02-12 09:25:18 +1100
    message:
      Merge command extension support.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_commands.py  test_command.py-20051019190109-3b17be0f52eaa7a8
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 4000.2.1
    revision-id: robertc at robertcollins.net-20090211214755-pltzfmev8komxryt
    parent: pqm at pqm.ubuntu.com-20090211011240-gv0zdxmwomt3ndtn
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: test-result-registry
    timestamp: Thu 2009-02-12 08:47:55 +1100
    message:
      Add library level support for different test runners to bzrlib.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS	2009-02-11 12:49:50 +0000
+++ b/NEWS	2009-02-11 22:25:18 +0000
@@ -37,6 +37,9 @@
 
   INTERNALS:
 
+    * ``bzrlib.tests.run_suite`` accepts a runner_class parameter
+      supporting the use of different runners. (Robert Collins)
+
     * New hook Commands['extend_command'] to allow plugins to access a
       command object before the command is run (or help generated from
       it), without overriding the command. (Robert Collins)

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-02-11 00:29:57 +0000
+++ b/bzrlib/builtins.py	2009-02-12 05:43:29 +0000
@@ -2912,6 +2912,10 @@
                      ]
     encoding_type = 'replace'
 
+    def __init__(self):
+        Command.__init__(self)
+        self.additional_selftest_args = {}
+
     def run(self, testspecs_list=None, verbose=False, one=False,
             transport=None, benchmark=None,
             lsprof_timed=None, cache_dir=None,
@@ -2949,22 +2953,24 @@
             test_suite_factory = None
             benchfile = None
         try:
-            result = selftest(verbose=verbose,
-                              pattern=pattern,
-                              stop_on_failure=one,
-                              transport=transport,
-                              test_suite_factory=test_suite_factory,
-                              lsprof_timed=lsprof_timed,
-                              bench_history=benchfile,
-                              matching_tests_first=first,
-                              list_only=list_only,
-                              random_seed=randomize,
-                              exclude_pattern=exclude,
-                              strict=strict,
-                              load_list=load_list,
-                              debug_flags=debugflag,
-                              starting_with=starting_with,
-                              )
+            selftest_kwargs = {"verbose": verbose,
+                              "pattern": pattern,
+                              "stop_on_failure": one,
+                              "transport": transport,
+                              "test_suite_factory": test_suite_factory,
+                              "lsprof_timed": lsprof_timed,
+                              "bench_history": benchfile,
+                              "matching_tests_first": first,
+                              "list_only": list_only,
+                              "random_seed": randomize,
+                              "exclude_pattern": exclude,
+                              "strict": strict,
+                              "load_list": load_list,
+                              "debug_flags": debugflag,
+                              "starting_with": starting_with
+                              }
+            selftest_kwargs.update(self.additional_selftest_args)
+            result = selftest(**selftest_kwargs)
         finally:
             if benchfile is not None:
                 benchfile.close()

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-02-12 04:37:01 +0000
+++ b/bzrlib/tests/__init__.py	2009-02-12 06:24:08 +0000
@@ -2487,13 +2487,23 @@
               list_only=False,
               random_seed=None,
               exclude_pattern=None,
-              strict=False):
+              strict=False,
+              runner_class=None):
+    """Run a test suite for bzr selftest.
+
+    :param runner_class: The class of runner to use. Must support the
+        constructor arguments passed by run_suite which are more than standard
+        python uses.
+    :return: A boolean indicating success.
+    """
     TestCase._gather_lsprof_in_benchmarks = lsprof_timed
     if verbose:
         verbosity = 2
     else:
         verbosity = 1
-    runner = TextTestRunner(stream=sys.stdout,
+    if runner_class is None:
+        runner_class = TextTestRunner
+    runner = runner_class(stream=sys.stdout,
                             descriptions=0,
                             verbosity=verbosity,
                             bench_history=bench_history,
@@ -2555,6 +2565,7 @@
              load_list=None,
              debug_flags=None,
              starting_with=None,
+             runner_class=None,
              ):
     """Run the whole test suite under the enhanced runner"""
     # XXX: Very ugly way to do this...
@@ -2590,7 +2601,9 @@
                      list_only=list_only,
                      random_seed=random_seed,
                      exclude_pattern=exclude_pattern,
-                     strict=strict)
+                     strict=strict,
+                     runner_class=runner_class,
+                     )
     finally:
         default_transport = old_transport
         selftest_debug_flags = old_debug_flags

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2009-02-11 12:49:50 +0000
+++ b/bzrlib/tests/test_selftest.py	2009-02-11 22:25:18 +0000
@@ -71,6 +71,7 @@
                           iter_suite_tests,
                           preserve_input,
                           randomize_suite,
+                          run_suite,
                           split_suite_by_condition,
                           split_suite_by_re,
                           test_lsprof,
@@ -2273,3 +2274,21 @@
         self.assertEquals('bzrlib.tests', tpr.resolve_alias('bt'))
         self.assertEquals('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
         self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
+
+
+class TestRunSuite(TestCase):
+
+    def test_runner_class(self):
+        """run_suite accepts and uses a runner_class keyword argument."""
+        class Stub(TestCase):
+            def test_foo(self):
+                pass
+        suite = Stub("test_foo")
+        calls = []
+        class MyRunner(TextTestRunner):
+            def run(self, test):
+                calls.append(test)
+                return ExtendedTestResult(self.stream, self.descriptions,
+                    self.verbosity)
+        run_suite(suite, runner_class=MyRunner)
+        self.assertEqual(calls, [suite])




More information about the bazaar-commits mailing list