Rev 3198: Add helper method to get only listed tests from a module test suite. in file:///v/home/vila/src/bzr/experimental/selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sun Jan 20 20:48:36 GMT 2008
At file:///v/home/vila/src/bzr/experimental/selftest/
------------------------------------------------------------
revno: 3198
revision-id:v.ladeuil+lp at free.fr-20080120204831-y36y3qprboygeb4a
parent: v.ladeuil+lp at free.fr-20080120174523-n84kq5xsin1vualx
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest
timestamp: Sun 2008-01-20 21:48:31 +0100
message:
Add helper method to get only listed tests from a module test suite.
* bzrlib/tests/test_selftest.py:
(TestTestIdListFilter): Add tests for filtering helper method
for_module_and_below.
* bzrlib/tests/__init__.py:
(TestIdListFilter.for_module_and_below): Helper to filter module
test suite retaining only the listed tests.
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 17:45:23 +0000
+++ b/bzrlib/tests/__init__.py 2008-01-20 20:48:31 +0000
@@ -2620,6 +2620,14 @@
"""Is there tests for the module or one of its sub modules."""
return self.module_hierarchies.has_key(module_name)
+ def for_module_and_below(self, module_name, suite):
+ """Filter a test suite by a module name.
+
+ Returns tests defined in a module or one of its sub modules.
+ """
+ return filter_suite_by_id_list(suite,
+ self.get_tests_under(module_name))
+
def test_suite():
"""Build and return TestSuite for the whole of bzrlib.
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2008-01-20 17:45:23 +0000
+++ b/bzrlib/tests/test_selftest.py 2008-01-20 20:48:31 +0000
@@ -1870,6 +1870,26 @@
def _create_filter(self, test_list):
return tests.TestIdListFilter(test_list)
+ def _create_suite(self, id_list):
+
+ class Stub(TestCase):
+ def test_foo(self):
+ pass
+
+ def _create_test_id(id):
+ return lambda: id
+
+ suite = TestUtil.TestSuite()
+ for id in id_list:
+ t = Stub('test_foo')
+ t.id = _create_test_id(id)
+ suite.addTest(t)
+ return suite
+
+ def _test_ids(self, test_suite):
+ """Get the ids for the tests in a test suite."""
+ return [t.id() for t in iter_suite_tests(test_suite)]
+
def test_empty_list(self):
filter = self._create_filter([])
self.assertEquals([], filter.used_modules())
@@ -1901,7 +1921,6 @@
'mod.submod.cl1.meth1', 'mod.submod.cl2.meth2']),
set(filter.get_tests_under('mod')))
-
def test_too_short_test_name(self):
filter = self._create_filter(['mod1', 'mod2.method1', 'mod3.cl1'])
self.assertEquals([''],filter.used_modules())
@@ -1928,4 +1947,26 @@
filter = self._create_filter(['mod.sub_mod.class.meth'])
self.assertFalse(filter.is_module_name_used('mod.sub_mod.class'))
+ def test_filter_for_module_and_below(self):
+ test_list = ['mod1.cl1.meth1', 'mod1.cl2.meth2',
+ 'mod1.submod2.cl1.meth1',
+ 'mod2.submod2.cl1.meth2',
+ ]
+ suite = self._create_suite(test_list)
+ filter = self._create_filter(test_list)
+ mod1_suite = filter.for_module_and_below('mod1', suite)
+ self.assertEquals(['mod1.cl1.meth1', 'mod1.cl2.meth2',
+ 'mod1.submod2.cl1.meth1'],
+ self._test_ids(mod1_suite))
+ mod2_suite = filter.for_module_and_below('mod2', suite)
+ self.assertEquals(['mod2.submod2.cl1.meth2'],
+ self._test_ids(mod2_suite))
+ def test_filter_for_module_and_below_empty_result(self):
+ test_list = ['mod1.cl1.meth1', 'mod1.cl2.meth2',
+ 'mod2.submod2.cl1.meth2',
+ ]
+ suite = self._create_suite(test_list)
+ filter = self._create_filter(test_list)
+ mod3_suite = filter.for_module_and_below('mod3', suite)
+ self.assertEquals(0, mod3_suite.countTestCases())
More information about the bazaar-commits
mailing list