~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__known_graph.py

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
37
37
        ('python-nocache', {'module': _known_graph_py, 'do_cache': False}),
38
38
    ]
39
39
    suite = loader.suiteClass()
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}))
 
40
    if compiled_known_graph_feature.available():
 
41
        scenarios.append(('C', {'module': compiled_known_graph_feature.module,
 
42
                                'do_cache': True}))
 
43
        caching_scenarios.append(
 
44
            ('C-nocache', {'module': compiled_known_graph_feature.module,
 
45
                           'do_cache': False}))
45
46
    else:
46
47
        # the compiled module isn't available, so we add a failing test
47
48
        class FailWithoutFeature(tests.TestCase):
48
49
            def test_fail(self):
49
 
                self.requireFeature(CompiledKnownGraphFeature)
 
50
                self.requireFeature(compiled_known_graph_feature)
50
51
        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
51
52
    # TestKnownGraphHeads needs to be permutated with and without caching.
52
53
    # All other TestKnownGraph tests only need to be tested across module
58
59
    return suite
59
60
 
60
61
 
61
 
class _CompiledKnownGraphFeature(tests.Feature):
62
 
 
63
 
    def _probe(self):
64
 
        try:
65
 
            import bzrlib._known_graph_pyx
66
 
        except ImportError:
67
 
            return False
68
 
        return True
69
 
 
70
 
    def feature_name(self):
71
 
        return 'bzrlib._known_graph_pyx'
72
 
 
73
 
CompiledKnownGraphFeature = _CompiledKnownGraphFeature()
 
62
compiled_known_graph_feature = tests.ModuleAvailableFeature(
 
63
                                    'bzrlib._known_graph_pyx')
74
64
 
75
65
 
76
66
#  a
154
144
        self.assertGDFO(graph, 'a', 5)
155
145
        self.assertGDFO(graph, 'c', 5)
156
146
 
 
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
 
150
        # This is a 'no-op'
 
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'))
 
156
 
 
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',
 
160
                          ['rev2b', 'rev3'])
 
161
 
 
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)
 
167
 
 
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)
 
172
 
 
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)
 
178
 
 
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)
 
194
 
 
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)
 
213
 
157
214
 
158
215
class TestKnownGraphHeads(TestCaseWithKnownGraph):
159
216
 
260
317
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'e', 'g']))
261
318
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'f']))
262
319
 
 
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
 
324
        # different
 
325
        graph.add_node('g', ['e'])
 
326
        self.assertEqual(set(['g']), graph.heads(['e', 'g']))
 
327
 
263
328
 
264
329
class TestKnownGraphTopoSort(TestCaseWithKnownGraph):
265
330