Rev 3339: Create a new selftest filter allowing loading only one module/class/test. in file:///v/home/vila/src/bzr/experimental/faster-selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 23 19:44:56 BST 2008
At file:///v/home/vila/src/bzr/experimental/faster-selftest/
------------------------------------------------------------
revno: 3339
revision-id: v.ladeuil+lp at free.fr-20080423184452-h9p6zkkm8yjfb8pw
parent: v.ladeuil+lp at free.fr-20080423135033-nhnu9u2re6m1c2xw
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest-starts-with
timestamp: Wed 2008-04-23 20:44:52 +0200
message:
Create a new selftest filter allowing loading only one module/class/test.
* bzrlib/tests/test_selftest.py:
(TestSelftestFiltering.test_condition_id_startswith): Test condition.
(TestSelftestFiltering): Test filter.
(TestFilteredByModuleTestLoader.test_exclude_tests): Test loader.
* bzrlib/tests/__init__.py:
(condition_id_startswith): New condition to filter tests.
(filter_suite_by_id_startswith): New filter.
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-04-17 14:55:39 +0000
+++ b/bzrlib/tests/__init__.py 2008-04-23 18:44:52 +0000
@@ -2247,6 +2247,18 @@
return condition
+def condition_id_startswith(start):
+ """Create a condition filter verifying that test's id starts with a string.
+
+ :param start: A string.
+ :return: A callable that returns True if the test's id starts with the
+ given string.
+ """
+ def condition(test):
+ return test.id().startswith(start)
+ return condition
+
+
def exclude_tests_by_condition(suite, condition):
"""Create a test suite which excludes some tests from suite.
@@ -2322,6 +2334,18 @@
return result_suite
+def filter_suite_by_id_startswith(suite, start):
+ """Create a test suite by filtering another one.
+
+ :param suite: The source suite.
+ :param start: A string the test id must start with.
+ :returns: the newly created suite
+ """
+ condition = condition_id_startswith(start)
+ result_suite = filter_suite_by_condition(suite, condition)
+ return result_suite
+
+
def exclude_tests_by_re(suite, pattern):
"""Create a test suite which excludes some tests from suite.
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2008-04-17 14:55:39 +0000
+++ b/bzrlib/tests/test_selftest.py 2008-04-23 18:44:52 +0000
@@ -1747,6 +1747,16 @@
re_filtered = filter_suite_by_re(self.suite, my_pattern)
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
+ def test_condition_id_startswith(self):
+ klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
+ start = klass + 'test_condition_id_starts'
+ test_names = [klass + 'test_condition_id_startswith']
+ filtered_suite = filter_suite_by_condition(
+ self.suite, tests.condition_id_startswith(start))
+ my_pattern = 'TestSelftestFiltering.*test_condition_id_startswith'
+ re_filtered = filter_suite_by_re(self.suite, my_pattern)
+ self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
+
def test_condition_isinstance(self):
filtered_suite = filter_suite_by_condition(self.suite,
condition_isinstance(self.__class__))
@@ -1802,6 +1812,19 @@
['bzrlib.tests.test_selftest.'
'TestSelftestFiltering.test_filter_suite_by_id_list'])
+ def test_filter_suite_by_id_startswith(self):
+ # By design this test may fail if another test is added whose a name
+ # also begins with the start value used.
+ klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
+ start = klass + 'test_filter_suite_by_id_starts'
+ test_list = [klass + 'test_filter_suite_by_id_startswith']
+ filtered_suite = tests.filter_suite_by_id_startswith(self.suite, start)
+ filtered_names = _test_ids(filtered_suite)
+ self.assertEqual(
+ filtered_names,
+ ['bzrlib.tests.test_selftest.'
+ 'TestSelftestFiltering.test_filter_suite_by_id_startswith'])
+
def test_preserve_input(self):
# NB: Surely this is something in the stdlib to do this?
self.assertTrue(self.suite is preserve_input(self.suite))
@@ -2078,3 +2101,24 @@
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
self.assertEquals([], _test_ids(suite))
+
+
+class TestFilteredByNameStartTestLoader(tests.TestCase):
+
+ def _create_loader(self, name_start):
+ loader = TestUtil.FilteredByModuleTestLoader(name_start.startswith)
+ return loader
+
+ def test_load_tests(self):
+ test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
+ loader = self._create_loader('bzrlib.tests.test_sampler.DemoTest')
+
+ 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('bogus')
+
+ suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
+ self.assertEquals([], _test_ids(suite))
More information about the bazaar-commits
mailing list