Rev 3177: UI for saving/loading test list instead of the whole test suite. in file:///v/home/vila/src/bzr/experimental/selftest/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Jan 10 21:14:59 GMT 2008


At file:///v/home/vila/src/bzr/experimental/selftest/

------------------------------------------------------------
revno: 3177
revision-id:v.ladeuil+lp at free.fr-20080110211454-0qvigli37mad5hd4
parent: v.ladeuil+lp at free.fr-20080110195359-wg1nrabfxb0poh24
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest
timestamp: Thu 2008-01-10 22:14:54 +0100
message:
  UI for saving/loading test list instead of the whole test suite.
  
  * bzrlib/tests/blackbox/test_selftest.py:
  (TestSelftestWithLists): Add blackbox tests for new options.
  
  * bzrlib/tests/__init__.py:
  (run_suite): Save test list if required.
  (selftest): Load test list if required.
  
  * bzrlib/builtins.py:
  (cmd_selftest): Add --save-list and --load-list options.
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/blackbox/test_selftest.py test_selftest.py-20060123024542-01c5f1bbcb596d78
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-01-10 16:23:07 +0000
+++ b/bzrlib/builtins.py	2008-01-10 21:14:54 +0000
@@ -2584,7 +2584,8 @@
                             help='Cache intermediate benchmark output in this '
                                  'directory.'),
                      Option('first',
-                            help='Run all tests, but run specified tests first.',
+                            help='Run all tests,'
+                            ' but run specified tests first.',
                             short_name='f',
                             ),
                      Option('list-only',
@@ -2601,6 +2602,12 @@
                      Option('coverage', type=str, argname="DIRECTORY",
                             help='Generate line coverage report in this '
                                  'directory.'),
+                     Option('load-list', type=str, argname='TESTLISTFILE',
+                            help='Load the test suite from a previously'
+                            ' saved file.'),
+                     Option('save-list', type=str, argname='TESTLISTFILE',
+                            help='Save a serialized representation of'
+                            ' the tests runned in this file.'),
                      ]
     encoding_type = 'replace'
 
@@ -2608,7 +2615,8 @@
             transport=None, benchmark=None,
             lsprof_timed=None, cache_dir=None,
             first=False, list_only=False,
-            randomize=None, exclude=None, strict=False, coverage=None):
+            randomize=None, exclude=None, strict=False, coverage=None,
+            load_list=None, save_list=None):
         import bzrlib.ui
         from bzrlib.tests import selftest
         import bzrlib.benchmarks as benchmarks
@@ -2652,6 +2660,8 @@
                                      random_seed=randomize,
                                      exclude_pattern=exclude,
                                      coverage_dir=coverage,
+                                     load_list=load_list,
+                                     save_list=save_list,
                                      )
             if strict:
                 success = result.wasStrictlySuccessful()

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-01-10 19:53:59 +0000
+++ b/bzrlib/tests/__init__.py	2008-01-10 21:14:54 +0000
@@ -1212,7 +1212,7 @@
             'NO_PROXY': None,
             'all_proxy': None,
             'ALL_PROXY': None,
-            # Nobody cares about these ones AFAIK. So far at
+            # Nobody cares about ftp_proxy and FTP_PROXY PAFAIK. So far at
             # least. If you do (care), please update this comment
             # -- vila 20061212
             'ftp_proxy': None,
@@ -2427,6 +2427,7 @@
               random_seed=None,
               exclude_pattern=None,
               coverage_dir=None,
+              save_list=None,
               ):
     TestCase._gather_lsprof_in_benchmarks = lsprof_timed
     if verbose:
@@ -2475,6 +2476,12 @@
         tracer = trace.Trace(count=1, trace=0)
         sys.settrace(tracer.globaltrace)
 
+    # Save the test list before running so that the tests don't get modified by
+    # running them and ensure that the list is saved even if the tests are
+    # interrupted.
+    if save_list is not None:
+        save_test_list(suite, save_list, runner.stream)
+
     result = runner.run(suite)
 
     if coverage_dir is not None:
@@ -2495,6 +2502,8 @@
              random_seed=None,
              exclude_pattern=None,
              coverage_dir=None,
+             load_list=None,
+             save_list=None,
              ):
     """Run the whole test suite under the enhanced runner"""
     # XXX: Very ugly way to do this...
@@ -2509,20 +2518,24 @@
     old_transport = default_transport
     default_transport = transport
     try:
-        if test_suite_factory is None:
+        if load_list is not None:
+            suite = load_test_list(load_list)
+        elif test_suite_factory is None:
             suite = test_suite()
         else:
             suite = test_suite_factory()
-        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
-                     stop_on_failure=stop_on_failure,
-                     transport=transport,
-                     lsprof_timed=lsprof_timed,
-                     bench_history=bench_history,
-                     matching_tests_first=matching_tests_first,
-                     list_only=list_only,
-                     random_seed=random_seed,
-                     exclude_pattern=exclude_pattern,
-                     coverage_dir=coverage_dir)
+        return run_suite(
+            suite, 'testbzr', verbose=verbose, pattern=pattern,
+            stop_on_failure=stop_on_failure,
+            transport=transport,
+            lsprof_timed=lsprof_timed,
+            bench_history=bench_history,
+            matching_tests_first=matching_tests_first,
+            list_only=list_only,
+            random_seed=random_seed,
+            exclude_pattern=exclude_pattern,
+            coverage_dir=coverage_dir,
+            save_list=save_list)
     finally:
         default_transport = old_transport
 

=== modified file 'bzrlib/tests/blackbox/test_selftest.py'
--- a/bzrlib/tests/blackbox/test_selftest.py	2007-12-24 10:31:24 +0000
+++ b/bzrlib/tests/blackbox/test_selftest.py	2008-01-10 21:14:54 +0000
@@ -23,15 +23,17 @@
 
 import bzrlib
 from bzrlib import (
+    errors,
     osutils,
+    tests,
     )
-from bzrlib.errors import ParamikoNotPresent
 from bzrlib.tests import (
                           TestCase,
                           TestCaseInTempDir,
                           TestCaseWithMemoryTransport,
                           TestCaseWithTransport,
                           TestUIFactory,
+                          TestUtil, # Module
                           TestSkipped,
                           )
 from bzrlib.symbol_versioning import (
@@ -49,7 +51,7 @@
         # test_transport test
         try:
             import bzrlib.transport.sftp
-        except ParamikoNotPresent:
+        except errors.ParamikoNotPresent:
             raise TestSkipped("Paramiko not present")
         if TestOptions.current_test != "test_transport_set_to_sftp":
             return
@@ -69,7 +71,7 @@
         # test that --transport=sftp works
         try:
             import bzrlib.transport.sftp
-        except ParamikoNotPresent:
+        except errors.ParamikoNotPresent:
             raise TestSkipped("Paramiko not present")
         old_transport = bzrlib.tests.default_transport
         old_root = TestCaseWithMemoryTransport.TEST_ROOT
@@ -558,3 +560,24 @@
             out_rand2.splitlines(), 2)
         self.assertEqual(tests_rand, tests_rand2)
 
+
+class TestSelftestWithLists(TestCaseInTempDir):
+
+    def test_save_reload(self):
+        # We don't want to call selftest for the whole suite, so we start with
+        # a reduced list.
+        loader = TestUtil.TestLoader()
+        suite = loader.loadTestsFromTestCase(TestSelftestWithLists)
+        tests.save_test_list(suite, 'myself')
+        out, err = self.run_bzr(
+            'selftest --load-list myself --save-list myveryself --list'
+            ' TestSelftestWithLists.test_save_reload')
+        self.assertContainsRe(out, "Listed 1 test in")
+
+        out, err = self.run_bzr(
+            'selftest --load-list myveryself --list')
+        self.assertContainsRe(out, "Listed 1 test in")
+
+    def test_load_unknown(self):
+        out, err = self.run_bzr('selftest --load-list I_do_not_exist ',
+                                retcode=3)



More information about the bazaar-commits mailing list