Rev 3320: Simplify tests.test_suite. in file:///v/home/vila/src/bzr/experimental/faster-selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Mar 26 11:37:14 GMT 2008
At file:///v/home/vila/src/bzr/experimental/faster-selftest/
------------------------------------------------------------
revno: 3320
revision-id: v.ladeuil+lp at free.fr-20080326113710-7l1n6r7m7ggzd4ly
parent: v.ladeuil+lp at free.fr-20080326112940-leugmcpkbzox54c1
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: filter-by-module-test-loader
timestamp: Wed 2008-03-26 12:37:10 +0100
message:
Simplify tests.test_suite.
* bzrlib/tests/__init__.py:
(test_suite): Simplified by creating a
TestFilteredByModuleTestLoader if needed, using the appropriate
loader for every category of tests and filtering once at the
end. Punt for DocTests to keep the commit short.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-03-26 08:42:01 +0000
+++ b/bzrlib/tests/__init__.py 2008-03-26 11:37:10 +0000
@@ -2794,11 +2794,14 @@
'bzrlib.tests.test_transport_implementations',
'bzrlib.tests.test_read_bundle',
]
- suite = TestUtil.TestSuite()
loader = TestUtil.TestLoader()
- if keep_only is not None:
+ if keep_only is None:
+ loader = TestUtil.TestLoader()
+ else:
id_filter = TestIdList(keep_only)
+ loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
+ suite = loader.suiteClass()
# modules building their suite with loadTestsFromModuleNames
if keep_only is None:
@@ -2807,7 +2810,6 @@
for mod in [m for m in testmod_names
if id_filter.refers_to(m)]:
mod_suite = loader.loadTestsFromModuleNames([mod])
- mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
suite.addTest(mod_suite)
# modules adapted for transport implementations
@@ -2820,7 +2822,6 @@
if id_filter.refers_to(m)]:
mod_suite = TestUtil.TestSuite()
adapt_modules([mod], adapter, loader, mod_suite)
- mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
suite.addTest(mod_suite)
# modules defining their own test_suite()
@@ -2828,19 +2829,17 @@
if (keep_only is None
or id_filter.refers_to(p.__name__))]:
pack_suite = package.test_suite()
- if keep_only is not None:
- pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
suite.addTest(pack_suite)
for mod in MODULES_TO_DOCTEST:
+ # FIXME: Can't filter on 'mod' since it can be either a module or its
+ # name.
+
try:
doc_suite = doctest.DocTestSuite(mod)
except ValueError, e:
print '**failed to get doctest for: %s\n%s' % (mod, e)
raise
- if keep_only is not None:
- # DocTests may use ids which doesn't contain the module name
- doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
suite.addTest(doc_suite)
default_encoding = sys.getdefaultencoding()
@@ -2852,10 +2851,9 @@
# 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.
# mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
+ if plugin_suite is None:
+ plugin_suite = plugin.load_tests(loader)
if plugin_suite is not None:
- if keep_only is not None:
- plugin_suite = filter_suite_by_id_list(plugin_suite,
- id_filter)
suite.addTest(plugin_suite)
if default_encoding != sys.getdefaultencoding():
bzrlib.trace.warning(
@@ -2865,6 +2863,9 @@
sys.setdefaultencoding(default_encoding)
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:
More information about the bazaar-commits
mailing list