37
37
('python-nocache', {'module': _known_graph_py, 'do_cache': False}),
39
39
suite = loader.suiteClass()
40
if compiled_known_graph_feature.available():
41
scenarios.append(('C', {'module': compiled_known_graph_feature.module,
43
caching_scenarios.append(
44
('C-nocache', {'module': compiled_known_graph_feature.module,
40
if CompiledKnownGraphFeature.available():
41
from bzrlib import _known_graph_pyx
42
scenarios.append(('C', {'module': _known_graph_pyx, 'do_cache': True}))
43
caching_scenarios.append(('C-nocache',
44
{'module': _known_graph_pyx, 'do_cache': False}))
47
46
# the compiled module isn't available, so we add a failing test
48
47
class FailWithoutFeature(tests.TestCase):
49
48
def test_fail(self):
50
self.requireFeature(compiled_known_graph_feature)
49
self.requireFeature(CompiledKnownGraphFeature)
51
50
suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
52
51
# TestKnownGraphHeads needs to be permutated with and without caching.
53
52
# All other TestKnownGraph tests only need to be tested across module
144
154
self.assertGDFO(graph, 'a', 5)
145
155
self.assertGDFO(graph, 'c', 5)
147
def test_add_existing_node(self):
148
graph = self.make_known_graph(test_graph.ancestry_1)
149
# Add a node that already exists with identical content
151
self.assertGDFO(graph, 'rev4', 5)
152
graph.add_node('rev4', ['rev3', 'rev2b'])
153
self.assertGDFO(graph, 'rev4', 5)
154
# This also works if we use a tuple rather than a list
155
graph.add_node('rev4', ('rev3', 'rev2b'))
157
def test_add_existing_node_mismatched_parents(self):
158
graph = self.make_known_graph(test_graph.ancestry_1)
159
self.assertRaises(ValueError, graph.add_node, 'rev4',
162
def test_add_node_with_ghost_parent(self):
163
graph = self.make_known_graph(test_graph.ancestry_1)
164
graph.add_node('rev5', ['rev2b', 'revGhost'])
165
self.assertGDFO(graph, 'rev5', 4)
166
self.assertGDFO(graph, 'revGhost', 1)
168
def test_add_new_root(self):
169
graph = self.make_known_graph(test_graph.ancestry_1)
170
graph.add_node('rev5', [])
171
self.assertGDFO(graph, 'rev5', 1)
173
def test_add_with_all_ghost_parents(self):
174
graph = self.make_known_graph(test_graph.ancestry_1)
175
graph.add_node('rev5', ['ghost'])
176
self.assertGDFO(graph, 'rev5', 2)
177
self.assertGDFO(graph, 'ghost', 1)
179
def test_gdfo_after_add_node(self):
180
graph = self.make_known_graph(test_graph.ancestry_1)
181
self.assertEqual([], graph.get_child_keys('rev4'))
182
graph.add_node('rev5', ['rev4'])
183
self.assertEqual(['rev4'], graph.get_parent_keys('rev5'))
184
self.assertEqual(['rev5'], graph.get_child_keys('rev4'))
185
self.assertEqual([], graph.get_child_keys('rev5'))
186
self.assertGDFO(graph, 'rev5', 6)
187
graph.add_node('rev6', ['rev2b'])
188
graph.add_node('rev7', ['rev6'])
189
graph.add_node('rev8', ['rev7', 'rev5'])
190
self.assertGDFO(graph, 'rev5', 6)
191
self.assertGDFO(graph, 'rev6', 4)
192
self.assertGDFO(graph, 'rev7', 5)
193
self.assertGDFO(graph, 'rev8', 7)
195
def test_fill_in_ghost(self):
196
graph = self.make_known_graph(test_graph.with_ghost)
197
# Add in a couple nodes and then fill in the 'ghost' so that it should
198
# cause renumbering of children nodes
199
graph.add_node('x', [])
200
graph.add_node('y', ['x'])
201
graph.add_node('z', ['y'])
202
graph.add_node('g', ['z'])
203
self.assertGDFO(graph, 'f', 2)
204
self.assertGDFO(graph, 'e', 3)
205
self.assertGDFO(graph, 'x', 1)
206
self.assertGDFO(graph, 'y', 2)
207
self.assertGDFO(graph, 'z', 3)
208
self.assertGDFO(graph, 'g', 4)
209
self.assertGDFO(graph, 'b', 4)
210
self.assertGDFO(graph, 'd', 5)
211
self.assertGDFO(graph, 'a', 5)
212
self.assertGDFO(graph, 'c', 6)
215
158
class TestKnownGraphHeads(TestCaseWithKnownGraph):
317
260
self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'e', 'g']))
318
261
self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'f']))
320
def test_filling_in_ghosts_resets_head_cache(self):
321
graph = self.make_known_graph(test_graph.with_ghost)
322
self.assertEqual(set(['e', 'g']), graph.heads(['e', 'g']))
323
# 'g' is filled in, and decends from 'e', so the heads result is now
325
graph.add_node('g', ['e'])
326
self.assertEqual(set(['g']), graph.heads(['e', 'g']))
329
264
class TestKnownGraphTopoSort(TestCaseWithKnownGraph):