Rev 3340: selftest now accepts --starting-ith <id> to load and execute only a module|class|test* reduced suite. in file:///v/home/vila/src/bzr/experimental/faster-selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 23 21:47:55 BST 2008
At file:///v/home/vila/src/bzr/experimental/faster-selftest/
------------------------------------------------------------
revno: 3340
revision-id: v.ladeuil+lp at free.fr-20080423204751-ck6m619a30ivap0x
parent: v.ladeuil+lp at free.fr-20080423184452-h9p6zkkm8yjfb8pw
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest-starts-with
timestamp: Wed 2008-04-23 22:47:51 +0200
message:
selftest now accepts --starting-ith <id> to load and execute only a module|class|test* reduced suite.
* bzrlib/tests/blackbox/test_selftest.py:
(TestSelftestWithIdList.test_load_unknown): Test option.
* bzrlib/tests/__init__.py:
(selftest): Add starting_with parameter.
(test_suite): Add starting_with parameter. Filter the test suite
for test ids starting with a given name.
* bzrlib/builtins.py:
(cmd_selftest): Add --statring-with option.
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-04-12 06:46:35 +0000
+++ b/bzrlib/builtins.py 2008-04-23 20:47:51 +0000
@@ -2653,6 +2653,8 @@
'known failures.'),
Option('load-list', type=str, argname='TESTLISTFILE',
help='Load a test id list from a text file.'),
+ Option('starting-with', type=str, argname='TESTID',
+ help='Load only the tests starting with TESTID.'),
]
encoding_type = 'replace'
@@ -2661,7 +2663,7 @@
lsprof_timed=None, cache_dir=None,
first=False, list_only=False,
randomize=None, exclude=None, strict=False,
- load_list=None):
+ load_list=None, starting_with=None):
import bzrlib.ui
from bzrlib.tests import selftest
import bzrlib.benchmarks as benchmarks
@@ -2704,6 +2706,7 @@
exclude_pattern=exclude,
strict=strict,
load_list=load_list,
+ starting_with=starting_with,
)
finally:
if benchfile is not None:
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-04-23 18:44:52 +0000
+++ b/bzrlib/tests/__init__.py 2008-04-23 20:47:51 +0000
@@ -2509,6 +2509,7 @@
exclude_pattern=None,
strict=False,
load_list=None,
+ starting_with=None,
):
"""Run the whole test suite under the enhanced runner"""
# XXX: Very ugly way to do this...
@@ -2528,7 +2529,7 @@
else:
keep_only = load_test_id_list(load_list)
if test_suite_factory is None:
- suite = test_suite(keep_only)
+ suite = test_suite(keep_only, starting_with)
else:
suite = test_suite_factory()
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
@@ -2647,11 +2648,14 @@
return self.tests.has_key(test_id)
-def test_suite(keep_only=None):
+def test_suite(keep_only=None, starting_with=None):
"""Build and return TestSuite for the whole of bzrlib.
:param keep_only: A list of test ids limiting the suite returned.
+ :param starting_with: An id limiting the suite returned to the tests
+ starting with it.
+
This function can be replaced if you need to change the default test
suite on a global basis, but it is not encouraged.
"""
@@ -2806,11 +2810,15 @@
loader = TestUtil.TestLoader()
- if keep_only is None:
- loader = TestUtil.TestLoader()
- else:
+ if starting_with is not None:
+ # We take precedence over keep_only because *at loading time* using
+ # both options means we will load less tests for the same final result.
+ loader = TestUtil.FilteredByModuleTestLoader(starting_with.startswith)
+ elif keep_only is not None:
id_filter = TestIdList(keep_only)
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
+ else:
+ loader = TestUtil.TestLoader()
suite = loader.suiteClass()
# modules building their suite with loadTestsFromModuleNames
@@ -2831,8 +2839,16 @@
'bzrlib.version_info_formats.format_custom',
]
+ def interesting_module(name):
+ if starting_with is not None:
+ return name.startswith(starting_with)
+ elif keep_only is not None:
+ return id_filter.refers_to(name)
+ else:
+ return True
+
for mod in modules_to_doctest:
- if not (keep_only is None or id_filter.refers_to(mod)):
+ if not interesting_module(mod):
# No tests to keep here, move along
continue
try:
@@ -2844,9 +2860,8 @@
default_encoding = sys.getdefaultencoding()
for name, plugin in bzrlib.plugin.plugins().items():
- if keep_only is not None:
- if not id_filter.refers_to(plugin.module.__name__):
- continue
+ if not interesting_module(plugin.module.__name__):
+ continue
plugin_suite = plugin.test_suite()
# We used to catch ImportError here and turn it into just a warning,
# but really if you don't have --no-plugins this should be a failure.
@@ -2862,14 +2877,22 @@
reload(sys)
sys.setdefaultencoding(default_encoding)
+ if starting_with is not None:
+ suite = filter_suite_by_id_startswith(suite, starting_with)
+
if keep_only is not None:
# Now that the referred modules have loaded their tests, keep only the
# requested ones.
suite = filter_suite_by_id_list(suite, id_filter)
# Do some sanity checks on the id_list filtering
not_found, duplicates = suite_matches_id_list(suite, keep_only)
- for id in not_found:
- bzrlib.trace.warning('"%s" not found in the test suite', id)
+ if starting_with is not None:
+ # No need to annoy the tester with tests not found since when both
+ # options are used *there will be* tests excluded from the list.
+ pass
+ else:
+ for id in not_found:
+ bzrlib.trace.warning('"%s" not found in the test suite', id)
for id in duplicates:
bzrlib.trace.warning('"%s" is used as an id by several tests', id)
=== modified file 'bzrlib/tests/blackbox/test_selftest.py'
--- a/bzrlib/tests/blackbox/test_selftest.py 2008-01-21 10:51:02 +0000
+++ b/bzrlib/tests/blackbox/test_selftest.py 2008-04-23 20:47:51 +0000
@@ -575,3 +575,12 @@
def test_load_unknown(self):
out, err = self.run_bzr('selftest --load-list I_do_not_exist ',
retcode=3)
+
+
+class TestSelftestStartingWith(TestCase):
+
+ def test_starting_with(self):
+ out, err = self.run_bzr(
+ ['selftest', '--starting-with', self.id(), '--list'])
+ self.assertContainsRe(out, "Listed 1 test in")
+
More information about the bazaar-commits
mailing list