~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__known_graph.py

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011 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,
24
23
    _known_graph_py,
25
24
    tests,
26
25
    )
27
26
from bzrlib.tests import test_graph
28
27
from bzrlib.revision import NULL_REVISION
29
 
 
30
 
 
31
 
def load_tests(standard_tests, module, loader):
32
 
    """Parameterize tests for all versions of groupcompress."""
 
28
from bzrlib.tests.scenarios import load_tests_apply_scenarios
 
29
from bzrlib.tests import (
 
30
    features,
 
31
    )
 
32
 
 
33
 
 
34
def caching_scenarios():
33
35
    scenarios = [
34
36
        ('python', {'module': _known_graph_py, 'do_cache': True}),
35
37
    ]
36
 
    caching_scenarios = [
 
38
    if compiled_known_graph_feature.available():
 
39
        scenarios.append(('C', {'module': compiled_known_graph_feature.module,
 
40
                                'do_cache': True}))
 
41
    return scenarios
 
42
 
 
43
 
 
44
def non_caching_scenarios():
 
45
    scenarios = [
37
46
        ('python-nocache', {'module': _known_graph_py, 'do_cache': False}),
38
47
    ]
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()
 
48
    if compiled_known_graph_feature.available():
 
49
        scenarios.append(
 
50
            ('C-nocache', {'module': compiled_known_graph_feature.module,
 
51
                           'do_cache': False}))
 
52
    return scenarios
 
53
 
 
54
 
 
55
load_tests = load_tests_apply_scenarios
 
56
 
 
57
 
 
58
compiled_known_graph_feature = features.ModuleAvailableFeature(
 
59
    'bzrlib._known_graph_pyx')
74
60
 
75
61
 
76
62
#  a
85
71
 
86
72
class TestCaseWithKnownGraph(tests.TestCase):
87
73
 
 
74
    scenarios = caching_scenarios()
88
75
    module = None # Set by load_tests
89
76
 
90
77
    def make_known_graph(self, ancestry):
224
211
 
225
212
class TestKnownGraphHeads(TestCaseWithKnownGraph):
226
213
 
 
214
    scenarios = caching_scenarios() + non_caching_scenarios()
227
215
    do_cache = None # Set by load_tests
228
216
 
229
217
    def test_heads_null(self):