~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: 2009-10-12 21:44:27 UTC
  • mto: This revision was merged to the branch mainline in revision 4737.
  • Revision ID: john@arbash-meinel.com-20091012214427-zddi1kmc2jlf7v31
Py_ssize_t and its associated function typedefs are not available w/ python 2.4

So we define them in python-compat.h
Even further, gcc issued a warning for:
static int
_workaround_pyrex_096()
So we changed it to:
_workaround_pyrex_096(void)

Also, some python api funcs were incorrectly defined as 'char *' when they meant
'const char *'. Work around that with a (char *) cast, to avoid compiler warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2009 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
20
20
 
21
21
from bzrlib import (
22
22
    errors,
 
23
    graph as _mod_graph,
23
24
    _known_graph_py,
24
25
    tests,
25
26
    )
26
27
from bzrlib.tests import test_graph
27
28
from bzrlib.revision import NULL_REVISION
28
 
from bzrlib.tests.scenarios import load_tests_apply_scenarios
29
 
 
30
 
 
31
 
def caching_scenarios():
 
29
 
 
30
 
 
31
def load_tests(standard_tests, module, loader):
 
32
    """Parameterize tests for all versions of groupcompress."""
32
33
    scenarios = [
33
34
        ('python', {'module': _known_graph_py, 'do_cache': True}),
34
35
    ]
35
 
    if compiled_known_graph_feature.available():
36
 
        scenarios.append(('C', {'module': compiled_known_graph_feature.module,
37
 
                                'do_cache': True}))
38
 
    return scenarios
39
 
 
40
 
 
41
 
def non_caching_scenarios():
42
 
    scenarios = [
 
36
    caching_scenarios = [
43
37
        ('python-nocache', {'module': _known_graph_py, 'do_cache': False}),
44
38
    ]
45
 
    if compiled_known_graph_feature.available():
46
 
        scenarios.append(
47
 
            ('C-nocache', {'module': compiled_known_graph_feature.module,
48
 
                           'do_cache': False}))
49
 
    return scenarios
50
 
 
51
 
 
52
 
load_tests = load_tests_apply_scenarios
53
 
 
54
 
 
55
 
compiled_known_graph_feature = tests.ModuleAvailableFeature(
56
 
    'bzrlib._known_graph_pyx')
 
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}))
 
45
    else:
 
46
        # the compiled module isn't available, so we add a failing test
 
47
        class FailWithoutFeature(tests.TestCase):
 
48
            def test_fail(self):
 
49
                self.requireFeature(CompiledKnownGraphFeature)
 
50
        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
 
51
    # TestKnownGraphHeads needs to be permutated with and without caching.
 
52
    # All other TestKnownGraph tests only need to be tested across module
 
53
    heads_suite, other_suite = tests.split_suite_by_condition(
 
54
        standard_tests, tests.condition_isinstance(TestKnownGraphHeads))
 
55
    suite = tests.multiply_tests(other_suite, scenarios, suite)
 
56
    suite = tests.multiply_tests(heads_suite, scenarios + caching_scenarios,
 
57
                                 suite)
 
58
    return suite
 
59
 
 
60
 
 
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()
57
74
 
58
75
 
59
76
#  a
68
85
 
69
86
class TestCaseWithKnownGraph(tests.TestCase):
70
87
 
71
 
    scenarios = caching_scenarios()
72
88
    module = None # Set by load_tests
73
89
 
74
90
    def make_known_graph(self, ancestry):
138
154
        self.assertGDFO(graph, 'a', 5)
139
155
        self.assertGDFO(graph, 'c', 5)
140
156
 
141
 
    def test_add_existing_node(self):
142
 
        graph = self.make_known_graph(test_graph.ancestry_1)
143
 
        # Add a node that already exists with identical content
144
 
        # This is a 'no-op'
145
 
        self.assertGDFO(graph, 'rev4', 5)
146
 
        graph.add_node('rev4', ['rev3', 'rev2b'])
147
 
        self.assertGDFO(graph, 'rev4', 5)
148
 
        # This also works if we use a tuple rather than a list
149
 
        graph.add_node('rev4', ('rev3', 'rev2b'))
150
 
 
151
 
    def test_add_existing_node_mismatched_parents(self):
152
 
        graph = self.make_known_graph(test_graph.ancestry_1)
153
 
        self.assertRaises(ValueError, graph.add_node, 'rev4',
154
 
                          ['rev2b', 'rev3'])
155
 
 
156
 
    def test_add_node_with_ghost_parent(self):
157
 
        graph = self.make_known_graph(test_graph.ancestry_1)
158
 
        graph.add_node('rev5', ['rev2b', 'revGhost'])
159
 
        self.assertGDFO(graph, 'rev5', 4)
160
 
        self.assertGDFO(graph, 'revGhost', 1)
161
 
 
162
 
    def test_add_new_root(self):
163
 
        graph = self.make_known_graph(test_graph.ancestry_1)
164
 
        graph.add_node('rev5', [])
165
 
        self.assertGDFO(graph, 'rev5', 1)
166
 
 
167
 
    def test_add_with_all_ghost_parents(self):
168
 
        graph = self.make_known_graph(test_graph.ancestry_1)
169
 
        graph.add_node('rev5', ['ghost'])
170
 
        self.assertGDFO(graph, 'rev5', 2)
171
 
        self.assertGDFO(graph, 'ghost', 1)
172
 
 
173
 
    def test_gdfo_after_add_node(self):
174
 
        graph = self.make_known_graph(test_graph.ancestry_1)
175
 
        self.assertEqual([], graph.get_child_keys('rev4'))
176
 
        graph.add_node('rev5', ['rev4'])
177
 
        self.assertEqual(['rev4'], graph.get_parent_keys('rev5'))
178
 
        self.assertEqual(['rev5'], graph.get_child_keys('rev4'))
179
 
        self.assertEqual([], graph.get_child_keys('rev5'))
180
 
        self.assertGDFO(graph, 'rev5', 6)
181
 
        graph.add_node('rev6', ['rev2b'])
182
 
        graph.add_node('rev7', ['rev6'])
183
 
        graph.add_node('rev8', ['rev7', 'rev5'])
184
 
        self.assertGDFO(graph, 'rev5', 6)
185
 
        self.assertGDFO(graph, 'rev6', 4)
186
 
        self.assertGDFO(graph, 'rev7', 5)
187
 
        self.assertGDFO(graph, 'rev8', 7)
188
 
 
189
 
    def test_fill_in_ghost(self):
190
 
        graph = self.make_known_graph(test_graph.with_ghost)
191
 
        # Add in a couple nodes and then fill in the 'ghost' so that it should
192
 
        # cause renumbering of children nodes
193
 
        graph.add_node('x', [])
194
 
        graph.add_node('y', ['x'])
195
 
        graph.add_node('z', ['y'])
196
 
        graph.add_node('g', ['z'])
197
 
        self.assertGDFO(graph, 'f', 2)
198
 
        self.assertGDFO(graph, 'e', 3)
199
 
        self.assertGDFO(graph, 'x', 1)
200
 
        self.assertGDFO(graph, 'y', 2)
201
 
        self.assertGDFO(graph, 'z', 3)
202
 
        self.assertGDFO(graph, 'g', 4)
203
 
        self.assertGDFO(graph, 'b', 4)
204
 
        self.assertGDFO(graph, 'd', 5)
205
 
        self.assertGDFO(graph, 'a', 5)
206
 
        self.assertGDFO(graph, 'c', 6)
207
 
 
208
157
 
209
158
class TestKnownGraphHeads(TestCaseWithKnownGraph):
210
159
 
211
 
    scenarios = caching_scenarios() + non_caching_scenarios()
212
160
    do_cache = None # Set by load_tests
213
161
 
214
162
    def test_heads_null(self):
312
260
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'e', 'g']))
313
261
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'f']))
314
262
 
315
 
    def test_filling_in_ghosts_resets_head_cache(self):
316
 
        graph = self.make_known_graph(test_graph.with_ghost)
317
 
        self.assertEqual(set(['e', 'g']), graph.heads(['e', 'g']))
318
 
        # 'g' is filled in, and decends from 'e', so the heads result is now
319
 
        # different
320
 
        graph.add_node('g', ['e'])
321
 
        self.assertEqual(set(['g']), graph.heads(['e', 'g']))
322
 
 
323
263
 
324
264
class TestKnownGraphTopoSort(TestCaseWithKnownGraph):
325
265