Rev 3371: * New helper function for splitting test suites ``split_suite_by_condition``. in http://people.ubuntu.com/~robertc/baz2.0/versioned_files

Robert Collins robertc at robertcollins.net
Wed Apr 30 07:29:30 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/versioned_files

------------------------------------------------------------
revno: 3371
revision-id: robertc at robertcollins.net-20080430062907-oodfp972lp0m4b1s
parent: robertc at robertcollins.net-20080430053203-p0oegpfwxbh7yiz7
committer: Robert Collins <robertc at robertcollins.net>
branch nick: VersionedFiles
timestamp: Wed 2008-04-30 16:29:07 +1000
message:
   * New helper function for splitting test suites ``split_suite_by_condition``.
     (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	2008-04-30 05:32:03 +0000
+++ b/NEWS	2008-04-30 06:29:07 +0000
@@ -55,6 +55,9 @@
 
   TESTING:
 
+    * New helper function for splitting test suites
+      ``split_suite_by_condition``. (Robert Collins)
+
   INTERNALS:
 
     * Implement xml8 serializer.  (Aaron Bentley)

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-04-07 04:44:56 +0000
+++ b/bzrlib/tests/__init__.py	2008-04-30 06:29:07 +0000
@@ -2430,6 +2430,28 @@
         return order_changer(filter_suite_by_re(suite, pattern))
 
 
+def split_suite_by_condition(suite, condition):
+    """Split a test suite into two by a condition.
+    
+    :param suite: The suite to split.
+    :param condition: The condition to match on. Tests that match this
+        condition are returned in the first test suite, ones that do not match
+        are in the second suite.
+    :return: A tuple of two test suites, where the first contains tests from
+        suite matching the condition, and the second contains the remainder
+        from suite. The order within each output suite is the same as it was in
+        suite.
+    """ 
+    matched = []
+    did_not_match = []
+    for test in iter_suite_tests(suite):
+        if condition(test):
+            matched.append(test)
+        else:
+            did_not_match.append(test)
+    return TestUtil.TestSuite(matched), TestUtil.TestSuite(did_not_match)
+
+
 def split_suite_by_re(suite, pattern):
     """Split a test suite into two by a regular expression.
     
@@ -2442,16 +2464,7 @@
         suite. The order within each output suite is the same as it was in
         suite.
     """ 
-    matched = []
-    did_not_match = []
-    filter_re = re.compile(pattern)
-    for test in iter_suite_tests(suite):
-        test_id = test.id()
-        if filter_re.search(test_id):
-            matched.append(test)
-        else:
-            did_not_match.append(test)
-    return TestUtil.TestSuite(matched), TestUtil.TestSuite(did_not_match)
+    return split_suite_by_condition(suite, condition_id_re(pattern))
 
 
 def run_suite(suite, name='test', verbose=False, pattern=".*",

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2008-04-11 23:05:02 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-04-30 06:29:07 +0000
@@ -66,6 +66,7 @@
                           preserve_input,
                           randomize_suite,
                           sort_suite_by_re,
+                          split_suite_by_condition,
                           split_suite_by_re,
                           test_lsprof,
                           test_suite,
@@ -1830,6 +1831,18 @@
             'TestSelftestFiltering.test_filter_suite_by_re')
         self.assertEquals(sorted(self.all_names), sorted(sorted_names))
 
+    def test_split_suit_by_condition(self):
+        self.all_names = _test_ids(self.suite)
+        condition = condition_id_re('test_filter_suite_by_r')
+        split_suite = split_suite_by_condition(self.suite, condition)
+        filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
+            'test_filter_suite_by_re')
+        self.assertEqual([filtered_name], _test_ids(split_suite[0]))
+        self.assertFalse(filtered_name in _test_ids(split_suite[1]))
+        remaining_names = list(self.all_names)
+        remaining_names.remove(filtered_name)
+        self.assertEqual(remaining_names, _test_ids(split_suite[1]))
+
     def test_split_suit_by_re(self):
         self.all_names = _test_ids(self.suite)
         split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r')




More information about the bazaar-commits mailing list