Rev 3199: Filter the whole test suite. in file:///v/home/vila/src/bzr/experimental/selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sun Jan 20 22:59:44 GMT 2008
At file:///v/home/vila/src/bzr/experimental/selftest/
------------------------------------------------------------
revno: 3199
revision-id:v.ladeuil+lp at free.fr-20080120225939-i38w6p3mgfkr53mo
parent: v.ladeuil+lp at free.fr-20080120204831-y36y3qprboygeb4a
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest
timestamp: Sun 2008-01-20 23:59:39 +0100
message:
Filter the whole test suite.
* bzrlib/tests/__init__.py:
(test_suite): Add a new 'keep_only' parameter listing the wanted
test ids.
* bzrlib/tests/test_selftest.py:
(TestTestIdListFilter): Add tests filtering the whole test suite.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-01-20 20:48:31 +0000
+++ b/bzrlib/tests/__init__.py 2008-01-20 22:59:39 +0000
@@ -2629,9 +2629,11 @@
self.get_tests_under(module_name))
-def test_suite():
+def test_suite(keep_only=None):
"""Build and return TestSuite for the whole of bzrlib.
-
+
+ :param keep_only: A list of test ids limiting the suite returned.
+
This function can be replaced if you need to change the default test
suite on a global basis, but it is not encouraged.
"""
@@ -2770,22 +2772,67 @@
]
suite = TestUtil.TestSuite()
loader = TestUtil.TestLoader()
- suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
+
+ if keep_only is not None:
+ id_filter = TestIdListFilter(keep_only)
+
+ # modules building their suite with loadTestsFromModuleNames
+ if keep_only is None:
+ suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
+ else:
+ for mod in [m for m in testmod_names
+ if id_filter.is_module_name_used(m)]:
+ mod_suite = loader.loadTestsFromModuleNames([mod])
+ mod_suite = id_filter.for_module_and_below(mod, mod_suite)
+ suite.addTest(mod_suite)
+
+ # modules adapted for transport implementations
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
adapter = TransportTestProviderAdapter()
- adapt_modules(test_transport_implementations, adapter, loader, suite)
- for package in packages_to_test():
- suite.addTest(package.test_suite())
- for m in MODULES_TO_TEST:
- suite.addTest(loader.loadTestsFromModule(m))
- for m in MODULES_TO_DOCTEST:
+ if keep_only is None:
+ adapt_modules(test_transport_implementations, adapter, loader, suite)
+ else:
+ for mod in [m for m in test_transport_implementations
+ if id_filter.is_module_name_used(m)]:
+ mod_suite = TestUtil.TestSuite()
+ adapt_modules([mod], adapter, loader, mod_suite)
+ mod_suite = id_filter.for_module_and_below(mod, mod_suite)
+ suite.addTest(mod_suite)
+
+ # modules defining their own test_suite()
+ for package in [p for p in packages_to_test()
+ if (keep_only is None
+ or id_filter.is_module_name_used(p.__name__))]:
+ pack_suite = package.test_suite()
+ if keep_only is not None:
+ pack_suite = id_filter.for_module_and_below(package.__name__,
+ pack_suite)
+ suite.addTest(pack_suite)
+
+ # XXX: MODULES_TO_TEST should be obsoleted ?
+ for mod in [m for m in MODULES_TO_TEST
+ if keep_only is None or id_filter.is_module_name_used(m)]:
+ mod_suite = loader.loadTestsFromModule(mod)
+ if keep_only is not None:
+ mod_suite = id_filter.for_module_and_below(mod, mod_suite)
+ suite.addTest(mod_suite)
+
+ for mod in MODULES_TO_DOCTEST:
try:
- suite.addTest(doctest.DocTestSuite(m))
+ doc_suite = doctest.DocTestSuite(mod)
except ValueError, e:
- print '**failed to get doctest for: %s\n%s' %(m,e)
+ print '**failed to get doctest for: %s\n%s' % (mod, e)
raise
+ if keep_only is not None:
+ # DocTest may used ids which doesn't contain the module name
+ doc_suite = filter_suite_by_id_list(doc_suite, keep_only)
+ suite.addTest(doc_suite)
+
default_encoding = sys.getdefaultencoding()
- for name, plugin in bzrlib.plugin.plugins().items():
+ for name, plugin in [(n, p) for (n, p) in bzrlib.plugin.plugins().items()
+ if (keep_only is None
+ or id_filter.is_module_name_used(
+ p.module.__name__))]:
try:
plugin_suite = plugin.test_suite()
except ImportError, e:
@@ -2793,6 +2840,11 @@
'Unable to test plugin "%s": %s', name, e)
else:
if plugin_suite is not None:
+ if keep_only is not None:
+ plugin_suite = id_filter.for_module_and_below(
+ plugin.module.__name__, plugin_suite)
+ if name == 'multiparent':
+ import pdb; pdb.set_trace()
suite.addTest(plugin_suite)
if default_encoding != sys.getdefaultencoding():
bzrlib.trace.warning(
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2008-01-20 20:48:31 +0000
+++ b/bzrlib/tests/test_selftest.py 2008-01-20 22:59:39 +0000
@@ -1970,3 +1970,25 @@
filter = self._create_filter(test_list)
mod3_suite = filter.for_module_and_below('mod3', suite)
self.assertEquals(0, mod3_suite.countTestCases())
+
+ def test_test_suite(self):
+ # This test is slow, so we do a single test with one test in each
+ # category
+ test_list = [
+ # testmod_names
+ 'bzrlib.tests.test_selftest.TestTestIdListFilter.test_test_suite',
+ # transport implementations
+ 'bzrlib.tests.test_transport_implementations.TransportTests'
+ '.test_abspath(LocalURLServer)',
+ # packages_to_test()
+ 'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
+ # MODULES_TO_DOCTEST
+ 'bzrlib.timestamp.format_highres_date',
+ # plugins (launchpad is included with core, but this may be
+ # fragile)
+ 'bzrlib.plugins.launchpad.test_register.TestBranchRegistration'
+ '.test_mock_bug_branch_link',
+ ]
+ suite = tests.test_suite(test_list)
+ self.assertEquals(len(test_list), suite.countTestCases())
+ self.assertEquals(test_list, self._test_ids(suite))
More information about the bazaar-commits
mailing list