Rev 2923: * New helper method ``bzrlib.tests.exclude_tests_by_re`` which gives a new in http://people.ubuntu.com/~robertc/baz2.0/in-module-parameterisation
Robert Collins
robertc at robertcollins.net
Sat Oct 20 23:49:57 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/in-module-parameterisation
------------------------------------------------------------
revno: 2923
revision-id: robertc at robertcollins.net-20071020224938-bh7rlcyv10oyztxc
parent: robertc at robertcollins.net-20071020223257-bu5r35znenkw9ups
committer: Robert Collins <robertc at robertcollins.net>
branch nick: in-module-parameterisation
timestamp: Sun 2007-10-21 08:49:38 +1000
message:
* New helper method ``bzrlib.tests.exclude_tests_by_re`` which gives a new
TestSuite that does not contain tests from the input that matched a
regular expression. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS 2007-10-20 22:32:57 +0000
+++ b/NEWS 2007-10-20 22:49:38 +0000
@@ -263,6 +263,10 @@
TESTING:
+ * New helper method ``bzrlib.tests.exclude_tests_by_re`` which gives a new
+ TestSuite that does not contain tests from the input that matched a
+ regular expression. (Robert Collins)
+
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test
suite into two according to a regular expression. (Robert Collins)
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-10-20 22:32:57 +0000
+++ b/bzrlib/tests/__init__.py 2007-10-20 22:49:38 +0000
@@ -2209,6 +2209,25 @@
random_order, False)
+def exclude_tests_by_re(suite, pattern):
+ """Create a test suite which excludes some tests from suite.
+
+ :param suite: The suite to get tests from.
+ :param pattern: A regular expression string. Test ids that match this
+ pattern will be excluded from the result.
+ :return: A TestSuite that contains all the tests from suite without the
+ tests that matched pattern. The order of tests is the same as it was in
+ suite.
+ """
+ result = []
+ exclude_re = re.compile(pattern)
+ for test in iter_suite_tests(suite):
+ test_id = test.id()
+ if not exclude_re.search(test_id):
+ result.append(test)
+ return TestUtil.TestSuite(result)
+
+
def sort_suite_by_re(suite, pattern, exclude_pattern=None,
random_order=False, append_rest=True):
"""Create a test suite by sorting another one.
@@ -2223,6 +2242,8 @@
just an ordering directive
:returns: the newly created suite
"""
+ if exclude_pattern is not None:
+ suite = exclude_tests_by_re(suite, exclude_pattern)
if append_rest:
suites = split_suite_by_re(suite, pattern)
else:
@@ -2231,15 +2252,12 @@
for suite in suites:
result = []
filter_re = re.compile(pattern)
- if exclude_pattern is not None:
- exclude_re = re.compile(exclude_pattern)
for test in iter_suite_tests(suite):
test_id = test.id()
- if exclude_pattern is None or not exclude_re.search(test_id):
- if append_rest:
- result.append(test)
- elif filter_re.search(test_id):
- result.append(test)
+ if append_rest:
+ result.append(test)
+ elif filter_re.search(test_id):
+ result.append(test)
if random_order:
random.shuffle(result)
out_tests.extend(result)
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2007-10-20 22:32:57 +0000
+++ b/bzrlib/tests/test_selftest.py 2007-10-20 22:49:38 +0000
@@ -54,8 +54,9 @@
TestUtil,
TextTestRunner,
UnavailableFeature,
+ exclude_tests_by_re,
+ filter_suite_by_re,
iter_suite_tests,
- filter_suite_by_re,
sort_suite_by_re,
split_suite_by_re,
test_lsprof,
@@ -1651,6 +1652,18 @@
"""Get the ids for the tests in a test suite."""
return [t.id() for t in iter_suite_tests(test_suite)]
+ def test_exclude_tests_by_re(self):
+ self.all_names = self._test_ids(self.suite)
+ filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re')
+ excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
+ 'test_exclude_tests_by_re')
+ self.assertEqual(len(self.all_names) - 1,
+ filtered_suite.countTestCases())
+ self.assertFalse(excluded_name in self._test_ids(filtered_suite))
+ remaining_names = list(self.all_names)
+ remaining_names.remove(excluded_name)
+ self.assertEqual(remaining_names, self._test_ids(filtered_suite))
+
def test_filter_suite_by_re(self):
filtered_suite = filter_suite_by_re(self.suite, 'test_filter')
filtered_names = self._test_ids(filtered_suite)
More information about the bazaar-commits
mailing list