~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

Prepare parameterised test environment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    KnitPlainFactory,
43
43
    )
44
44
from bzrlib.symbol_versioning import one_four, one_five
45
 
from bzrlib.tests import TestCaseWithMemoryTransport, TestSkipped
 
45
from bzrlib.tests import (
 
46
    TestCaseWithMemoryTransport,
 
47
    TestScenarioApplier,
 
48
    TestSkipped,
 
49
    condition_isinstance,
 
50
    split_suite_by_condition,
 
51
    iter_suite_tests,
 
52
    )
46
53
from bzrlib.tests.http_utils import TestCaseWithWebserver
47
54
from bzrlib.trace import mutter
48
55
from bzrlib.transport import get_transport
50
57
from bzrlib.tsort import topo_sort
51
58
from bzrlib.tuned_gzip import GzipFile
52
59
import bzrlib.versionedfile as versionedfile
 
60
from bzrlib.versionedfile import (
 
61
    ConstantMapper,
 
62
    HashEscapedPrefixMapper,
 
63
    PrefixMapper,
 
64
    make_pack_factory,
 
65
    make_versioned_files_factory,
 
66
    )
53
67
from bzrlib.weave import WeaveFile
54
68
from bzrlib.weavefile import read_weave, write_weave
55
69
 
56
70
 
 
71
def load_tests(standard_tests, module, loader):
 
72
    """Parameterize VersionedFiles tests for different implementations."""
 
73
    to_adapt, result = split_suite_by_condition(
 
74
        standard_tests, condition_isinstance(TestVersionedFiles))
 
75
    len_one_adapter = TestScenarioApplier()
 
76
    len_two_adapter = TestScenarioApplier()
 
77
    # We want to be sure of behaviour for:
 
78
    # weaves prefix layout (weave texts)
 
79
    # individually named weaves (weave inventories)
 
80
    # annotated knits - prefix|hash|hash-escape layout, we test the third only
 
81
    #                   as it is the most complex mapper.
 
82
    # individually named knits
 
83
    # individual no-graph knits in packs (signatures)
 
84
    # individual graph knits in packs (inventories)
 
85
    # individual graph nocompression knits in packs (revisions)
 
86
    # plain text knits in packs (texts)
 
87
    len_one_adapter.scenarios = [
 
88
        ('weave-named', {
 
89
            'factory':make_versioned_files_factory(WeaveFile,
 
90
                ConstantMapper('inventory')),
 
91
            'len':1,
 
92
            }),
 
93
        ('named-knit', {
 
94
            'factory':make_versioned_files_factory(make_file_knit,
 
95
                ConstantMapper('revisions')),
 
96
            'len':1,
 
97
            }),
 
98
        ('named-nograph-knit-pack', {
 
99
            'factory':make_pack_factory(False, False, 1),
 
100
            'len':1,
 
101
            }),
 
102
        ('named-graph-knit-pack', {
 
103
            'factory':make_pack_factory(True, True, 1),
 
104
            'len':1,
 
105
            }),
 
106
        ('named-graph-nodelta-knit-pack', {
 
107
            'factory':make_pack_factory(True, False, 1),
 
108
            'len':1,
 
109
            }),
 
110
        ]
 
111
    len_two_adapter.scenarios = [
 
112
        ('weave-prefix', {
 
113
            'factory':make_versioned_files_factory(WeaveFile,
 
114
                PrefixMapper()),
 
115
            'len':2,
 
116
            }),
 
117
        ('annotated-knit-escape', {
 
118
            'factory':make_versioned_files_factory(make_file_knit,
 
119
                HashEscapedPrefixMapper()),
 
120
            'len':2,
 
121
            }),
 
122
        ('plain-knit-pack', {
 
123
            'factory':make_pack_factory(True, True, 2),
 
124
            'len':2,
 
125
            }),
 
126
        ]
 
127
    for test in iter_suite_tests(to_adapt):
 
128
        result.addTests(len_one_adapter.adapt(test))
 
129
        result.addTests(len_two_adapter.adapt(test))
 
130
    return result
 
131
 
 
132
 
57
133
def get_diamond_vf(f, trailing_eol=True, left_only=False):
58
134
    """Get a diamond graph to exercise deltas and merges.
59
135
    
1580
1656
            "revision-id")))
1581
1657
        self.assertEqual(('filE-Id',), mapper.unmap("ed/fil%45-%49d"))
1582
1658
        self.assertEqual(('neW-Id',), mapper.unmap("88/ne%57-%49d"))
 
1659
 
 
1660
 
 
1661
class TestVersionedFiles(TestCaseWithMemoryTransport):
 
1662
    """Tests for the multiple-file variant of VersionedFile."""
 
1663
 
 
1664
    def test_construct(self):
 
1665
        """Each parameterised test can be constructed on a transport."""
 
1666
        files = self.factory(self.get_transport())