~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__groupcompress.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-20 09:28:27 UTC
  • mfrom: (5050.78.2 2.2)
  • mto: (5609.48.8 2.3)
  • mto: This revision was merged to the branch mainline in revision 6090.
  • Revision ID: v.ladeuil+lp@free.fr-20110820092827-9dyakfslp0r3hb1k
Merge 2.2 into 2.3 (including fix for #614713, #609187 and #812928)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2008-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
17
17
"""Tests for the python and pyrex extensions of groupcompress"""
18
18
 
19
19
from bzrlib import (
20
 
    groupcompress,
21
20
    _groupcompress_py,
22
21
    tests,
23
22
    )
24
 
 
25
 
 
26
 
def load_tests(standard_tests, module, loader):
27
 
    """Parameterize tests for all versions of groupcompress."""
28
 
    two_way_scenarios = [
 
23
from bzrlib.tests.scenarios import (
 
24
    load_tests_apply_scenarios,
 
25
    )
 
26
 
 
27
 
 
28
def module_scenarios():
 
29
    scenarios = [
 
30
        ('python', {'_gc_module': _groupcompress_py}),
 
31
        ]
 
32
    if compiled_groupcompress_feature.available():
 
33
        gc_module = compiled_groupcompress_feature.module
 
34
        scenarios.append(('C',
 
35
            {'_gc_module': gc_module}))
 
36
    return scenarios
 
37
 
 
38
 
 
39
def two_way_scenarios():
 
40
    scenarios = [
29
41
        ('PP', {'make_delta': _groupcompress_py.make_delta,
30
42
                'apply_delta': _groupcompress_py.apply_delta})
31
43
        ]
32
 
    scenarios = [
33
 
        ('python', {'_gc_module': _groupcompress_py}),
34
 
        ]
35
 
    if CompiledGroupCompressFeature.available():
36
 
        from bzrlib import _groupcompress_pyx
37
 
        scenarios.append(('C',
38
 
            {'_gc_module': _groupcompress_pyx}))
39
 
        two_way_scenarios.extend([
40
 
            ('CC', {'make_delta': _groupcompress_pyx.make_delta,
41
 
                    'apply_delta': _groupcompress_pyx.apply_delta}),
 
44
    if compiled_groupcompress_feature.available():
 
45
        gc_module = compiled_groupcompress_feature.module
 
46
        scenarios.extend([
 
47
            ('CC', {'make_delta': gc_module.make_delta,
 
48
                    'apply_delta': gc_module.apply_delta}),
42
49
            ('PC', {'make_delta': _groupcompress_py.make_delta,
43
 
                    'apply_delta': _groupcompress_pyx.apply_delta}),
44
 
            ('CP', {'make_delta': _groupcompress_pyx.make_delta,
 
50
                    'apply_delta': gc_module.apply_delta}),
 
51
            ('CP', {'make_delta': gc_module.make_delta,
45
52
                    'apply_delta': _groupcompress_py.apply_delta}),
46
53
            ])
47
 
    to_adapt, result = tests.split_suite_by_condition(
48
 
        standard_tests, tests.condition_isinstance((TestMakeAndApplyDelta,
49
 
                                                    TestBase128Int)))
50
 
    result = tests.multiply_tests(to_adapt, scenarios, result)
51
 
    to_adapt, result = tests.split_suite_by_condition(result,
52
 
        tests.condition_isinstance(TestMakeAndApplyCompatible))
53
 
    result = tests.multiply_tests(to_adapt, two_way_scenarios, result)
54
 
    return result
55
 
 
56
 
 
57
 
class _CompiledGroupCompressFeature(tests.Feature):
58
 
 
59
 
    def _probe(self):
60
 
        try:
61
 
            import bzrlib._groupcompress_pyx
62
 
        except ImportError:
63
 
            return False
64
 
        else:
65
 
            return True
66
 
 
67
 
    def feature_name(self):
68
 
        return 'bzrlib._groupcompress_pyx'
69
 
 
70
 
 
71
 
CompiledGroupCompressFeature = _CompiledGroupCompressFeature()
 
54
    return scenarios
 
55
 
 
56
 
 
57
load_tests = load_tests_apply_scenarios
 
58
 
 
59
 
 
60
compiled_groupcompress_feature = tests.ModuleAvailableFeature(
 
61
                                    'bzrlib._groupcompress_pyx')
72
62
 
73
63
_text1 = """\
74
64
This is a bit
129
119
 
130
120
class TestMakeAndApplyDelta(tests.TestCase):
131
121
 
 
122
    scenarios = module_scenarios()
132
123
    _gc_module = None # Set by load_tests
133
124
 
134
125
    def setUp(self):
239
230
 
240
231
class TestMakeAndApplyCompatible(tests.TestCase):
241
232
 
 
233
    scenarios = two_way_scenarios()
 
234
 
242
235
    make_delta = None # Set by load_tests
243
236
    apply_delta = None # Set by load_tests
244
237
 
264
257
        # This test isn't multiplied, because we only have DeltaIndex for the
265
258
        # compiled form
266
259
        # We call this here, because _test_needs_features happens after setUp
267
 
        self.requireFeature(CompiledGroupCompressFeature)
268
 
        from bzrlib import _groupcompress_pyx
269
 
        self._gc_module = _groupcompress_pyx
 
260
        self.requireFeature(compiled_groupcompress_feature)
 
261
        self._gc_module = compiled_groupcompress_feature.module
270
262
 
271
263
    def test_repr(self):
272
264
        di = self._gc_module.DeltaIndex('test text\n')
471
463
 
472
464
class TestBase128Int(tests.TestCase):
473
465
 
 
466
    scenarios = module_scenarios()
 
467
 
474
468
    _gc_module = None # Set by load_tests
475
469
 
476
470
    def assertEqualEncode(self, bytes, val):