Rev 4612: Split up the tests a bit. in http://bazaar.launchpad.net/~jameinel/bzr/1.19-known-graph-sorted

John Arbash Meinel john at arbash-meinel.com
Thu Aug 13 22:40:58 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.19-known-graph-sorted

------------------------------------------------------------
revno: 4612
revision-id: john at arbash-meinel.com-20090813214051-erwc7zm2fxai7b5l
parent: john at arbash-meinel.com-20090813213007-4wqkou02fo0tegay
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.19-known-graph-sorted
timestamp: Thu 2009-08-13 16:40:51 -0500
message:
  Split up the tests a bit.
  
  Only the heads() tests need to be run 4 times, the rest only need to be run 2x.
-------------- next part --------------
=== modified file 'bzrlib/tests/test__known_graph.py'
--- a/bzrlib/tests/test__known_graph.py	2009-08-13 21:30:07 +0000
+++ b/bzrlib/tests/test__known_graph.py	2009-08-13 21:40:51 +0000
@@ -30,13 +30,15 @@
     """Parameterize tests for all versions of groupcompress."""
     scenarios = [
         ('python', {'module': _known_graph_py, 'do_cache': True}),
+    ]
+    caching_scenarios = [
         ('python-nocache', {'module': _known_graph_py, 'do_cache': False}),
     ]
     suite = loader.suiteClass()
     if CompiledKnownGraphFeature.available():
         from bzrlib import _known_graph_pyx
         scenarios.append(('C', {'module': _known_graph_pyx, 'do_cache': True}))
-        scenarios.append(('C-nocache',
+        caching_scenarios.append(('C-nocache',
                           {'module': _known_graph_pyx, 'do_cache': False}))
     else:
         # the compiled module isn't available, so we add a failing test
@@ -44,8 +46,14 @@
             def test_fail(self):
                 self.requireFeature(CompiledKnownGraphFeature)
         suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
-    result = tests.multiply_tests(standard_tests, scenarios, suite)
-    return result
+    # TestKnownGraphHeads needs to be permutated with and without caching.
+    # All other TestKnownGraph tests only need to be tested across module
+    heads_suite, other_suite = tests.split_suite_by_condition(
+        standard_tests, tests.condition_isinstance(TestKnownGraphHeads))
+    suite = tests.multiply_tests(other_suite, scenarios, suite)
+    suite = tests.multiply_tests(heads_suite, scenarios + caching_scenarios,
+                                 suite)
+    return suite
 
 
 class _CompiledKnownGraphFeature(tests.Feature):
@@ -73,40 +81,20 @@
 alt_merge = {'a': [], 'b': ['a'], 'c': ['b'], 'd': ['a', 'c']}
 
 
-class TestKnownGraph(tests.TestCase):
+class TestCaseWithKnownGraph(tests.TestCase):
 
     module = None # Set by load_tests
-    do_cache = None # Set by load_tests
 
     def make_known_graph(self, ancestry):
         return self.module.KnownGraph(ancestry, do_cache=self.do_cache)
 
+
+class TestKnownGraph(TestCaseWithKnownGraph):
+
     def assertGDFO(self, graph, rev, gdfo):
         node = graph._nodes[rev]
         self.assertEqual(gdfo, node.gdfo)
 
-    def assertTopoSortOrder(self, ancestry):
-        """Check topo_sort and iter_topo_order is genuinely topological order.
-
-        For every child in the graph, check if it comes after all of it's
-        parents.
-        """
-        graph = self.module.KnownGraph(ancestry)
-        sort_result = graph.topo_sort()
-        # We should have an entry in sort_result for every entry present in the
-        # graph.
-        self.assertEqual(len(ancestry), len(sort_result))
-        node_idx = dict((node, idx) for idx, node in enumerate(sort_result))
-        for node in sort_result:
-            parents = ancestry[node]
-            for parent in parents:
-                if parent not in ancestry:
-                    # ghost
-                    continue
-                if node_idx[node] <= node_idx[parent]:
-                    self.fail("parent %s must come before child %s:\n%s"
-                              % (parent, node, sort_result))
-
     def test_children_ancestry1(self):
         graph = self.make_known_graph(test_graph.ancestry_1)
         self.assertEqual(['rev1'], graph._nodes[NULL_REVISION].child_keys)
@@ -149,6 +137,11 @@
         self.assertGDFO(graph, 'a', 5)
         self.assertGDFO(graph, 'c', 5)
 
+
+class TestKnownGraphHeads(TestCaseWithKnownGraph):
+
+    do_cache = None # Set by load_tests
+
     def test_heads_null(self):
         graph = self.make_known_graph(test_graph.ancestry_1)
         self.assertEqual(set(['null:']), graph.heads(['null:']))
@@ -250,6 +243,31 @@
         self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'e', 'g']))
         self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'f']))
 
+
+class TestKnownGraphTopoSort(TestCaseWithKnownGraph):
+
+    def assertTopoSortOrder(self, ancestry):
+        """Check topo_sort and iter_topo_order is genuinely topological order.
+
+        For every child in the graph, check if it comes after all of it's
+        parents.
+        """
+        graph = self.make_known_graph(ancestry)
+        sort_result = graph.topo_sort()
+        # We should have an entry in sort_result for every entry present in the
+        # graph.
+        self.assertEqual(len(ancestry), len(sort_result))
+        node_idx = dict((node, idx) for idx, node in enumerate(sort_result))
+        for node in sort_result:
+            parents = ancestry[node]
+            for parent in parents:
+                if parent not in ancestry:
+                    # ghost
+                    continue
+                if node_idx[node] <= node_idx[parent]:
+                    self.fail("parent %s must come before child %s:\n%s"
+                              % (parent, node, sort_result))
+
     def test_topo_sort_empty(self):
         """TopoSort empty list"""
         self.assertTopoSortOrder({})



More information about the bazaar-commits mailing list