Rev 3310: New test loader reducing modules imports and tests loaded. in file:///v/home/vila/src/bzr/experimental/faster-selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Mar 24 18:18:02 GMT 2008
At file:///v/home/vila/src/bzr/experimental/faster-selftest/
------------------------------------------------------------
revno: 3310
revision-id: v.ladeuil+lp at free.fr-20080324181758-pzlqy05mg3ktdivu
parent: v.ladeuil+lp at free.fr-20080324181430-91hpx1x34cfexygw
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: filter-by-module-test-loader
timestamp: Mon 2008-03-24 19:17:58 +0100
message:
New test loader reducing modules imports and tests loaded.
* bzrlib/tests/test_selftest.py:
(TestFilteredByModuleTestLoader): Tests for a loader that don't
import unneeded modules.
* bzrlib/tests/TestUtil.py:
(FilteredByModuleTestLoader): Specialized loader importing and
loading tests for a reduced set of modules.
modified:
bzrlib/tests/TestUtil.py TestUtil.py-20050824080200-5f70140a2d938694
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
-------------- next part --------------
=== modified file 'bzrlib/tests/TestUtil.py'
--- a/bzrlib/tests/TestUtil.py 2008-03-24 18:10:42 +0000
+++ b/bzrlib/tests/TestUtil.py 2008-03-24 18:17:58 +0000
@@ -141,6 +141,26 @@
self.test_func_names[test_case_class] = test_fn_names
return test_fn_names
+
+class FilteredByModuleTestLoader(TestLoader):
+ """A test loader that import only the needed modules."""
+
+ def __init__(self, needs_module):
+ """Constructor.
+
+ :param needs_module: a callable taking a module name as a
+ parameter returing True if the module should be loaded.
+ """
+ TestLoader.__init__(self)
+ self.needs_module = needs_module
+
+ def loadTestsFromModuleName(self, name):
+ if self.needs_module(name):
+ return TestLoader.loadTestsFromModuleName(self, name)
+ else:
+ return self.suiteClass()
+
+
def _load_module_by_name(mod_name):
parts = mod_name.split('.')
module = __import__(mod_name)
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2008-03-24 18:10:42 +0000
+++ b/bzrlib/tests/test_selftest.py 2008-03-24 18:17:58 +0000
@@ -2034,3 +2034,24 @@
self.assertEquals('bar baz', tlist[3])
+class TestFilteredByModuleTestLoader(tests.TestCase):
+
+ def _create_loader(self, test_list):
+ id_filter = tests.TestIdList(test_list)
+ loader = TestUtil.FilteredByModuleTestLoader(
+ id_filter.is_module_name_used)
+ return loader
+
+ def test_load_tests(self):
+ test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
+ loader = self._create_loader(test_list)
+
+ suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
+ self.assertEquals(test_list, _test_ids(suite))
+
+ def test_exclude_tests(self):
+ test_list = ['bogus']
+ loader = self._create_loader(test_list)
+
+ suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
+ self.assertEquals([], _test_ids(suite))
More information about the bazaar-commits
mailing list