Rev 2924: * New helper method ``bzrlib.tests.randomise_suite`` which returns a in http://people.ubuntu.com/~robertc/baz2.0/in-module-parameterisation
Robert Collins
robertc at robertcollins.net
Sun Oct 21 00:02:10 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/in-module-parameterisation
------------------------------------------------------------
revno: 2924
revision-id: robertc at robertcollins.net-20071020230154-r22h8rsgpbhnw163
parent: robertc at robertcollins.net-20071020224938-bh7rlcyv10oyztxc
committer: Robert Collins <robertc at robertcollins.net>
branch nick: in-module-parameterisation
timestamp: Sun 2007-10-21 09:01:54 +1000
message:
* New helper method ``bzrlib.tests.randomise_suite`` which returns a
randomised copy of the input suite. (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:49:38 +0000
+++ b/NEWS 2007-10-20 23:01:54 +0000
@@ -267,6 +267,9 @@
TestSuite that does not contain tests from the input that matched a
regular expression. (Robert Collins)
+ * New helper method ``bzrlib.tests.randomise_suite`` which returns a
+ randomised copy of the input suite. (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:49:38 +0000
+++ b/bzrlib/tests/__init__.py 2007-10-20 23:01:54 +0000
@@ -2228,6 +2228,13 @@
return TestUtil.TestSuite(result)
+def randomise_suite(suite):
+ """Return a new TestSuite with suite's tests in random order."""
+ tests = list(iter_suite_tests(suite))
+ random.shuffle(tests)
+ return TestUtil.TestSuite(tests)
+
+
def sort_suite_by_re(suite, pattern, exclude_pattern=None,
random_order=False, append_rest=True):
"""Create a test suite by sorting another one.
@@ -2258,9 +2265,10 @@
result.append(test)
elif filter_re.search(test_id):
result.append(test)
+ result_suite = TestUtil.TestSuite(result)
if random_order:
- random.shuffle(result)
- out_tests.extend(result)
+ result_suite = randomise_suite(result_suite)
+ out_tests.append(result_suite)
return TestUtil.TestSuite(out_tests)
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2007-10-20 22:49:38 +0000
+++ b/bzrlib/tests/test_selftest.py 2007-10-20 23:01:54 +0000
@@ -57,6 +57,7 @@
exclude_tests_by_re,
filter_suite_by_re,
iter_suite_tests,
+ randomise_suite,
sort_suite_by_re,
split_suite_by_re,
test_lsprof,
@@ -1670,6 +1671,22 @@
self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
'TestSelftestFiltering.test_filter_suite_by_re'])
+ def test_randomise_suite(self):
+ randomised_suite = randomise_suite(self.suite)
+ # randomising should not add or remove test names.
+ self.assertEqual(set(self._test_ids(self.suite)),
+ set(self._test_ids(randomised_suite)))
+ # Technically, this *can* fail, because random.shuffle(list) can be
+ # equal to list. Trying multiple times just pushes the frequency back.
+ # As its len(self.all_names)!:1, the failure frequency should be low
+ # enough to ignore. RBC 20071021.
+ # It should change the order.
+ self.assertNotEqual(self.all_names, self._test_ids(randomised_suite))
+ # But not the length. (Possibly redundant with the set test, but not
+ # necessarily.)
+ self.assertEqual(len(self.all_names),
+ len(self._test_ids(randomised_suite)))
+
def test_sort_suite_by_re(self):
sorted_suite = sort_suite_by_re(self.suite, 'test_filter')
sorted_names = self._test_ids(sorted_suite)
More information about the bazaar-commits
mailing list