~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Martin Pool
  • Date: 2009-07-27 05:38:00 UTC
  • mto: This revision was merged to the branch mainline in revision 4587.
  • Revision ID: mbp@sourcefrog.net-20090727053800-bgnhmzzgo0u0314s
Remove tests for deleted LockableFiles methods

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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 Knit data structure"""
18
18
 
19
19
from cStringIO import StringIO
 
20
import difflib
 
21
import gzip
20
22
import sys
21
23
 
22
24
from bzrlib import (
23
25
    errors,
 
26
    generate_ids,
24
27
    knit,
25
28
    multiparent,
26
29
    osutils,
27
30
    pack,
28
 
    tests,
29
 
    transport,
30
 
    tuned_gzip,
31
31
    )
32
32
from bzrlib.errors import (
 
33
    RevisionAlreadyPresent,
33
34
    KnitHeaderError,
 
35
    RevisionNotPresent,
34
36
    NoSuchFile,
35
37
    )
36
38
from bzrlib.index import *
37
39
from bzrlib.knit import (
38
40
    AnnotatedKnitContent,
39
41
    KnitContent,
 
42
    KnitSequenceMatcher,
40
43
    KnitVersionedFiles,
41
44
    PlainKnitContent,
42
45
    _VFContentMapGenerator,
46
49
    _KnitKeyAccess,
47
50
    make_file_factory,
48
51
    )
49
 
from bzrlib.patiencediff import PatienceSequenceMatcher
50
52
from bzrlib.repofmt import pack_repo
51
53
from bzrlib.tests import (
 
54
    Feature,
 
55
    KnownFailure,
52
56
    TestCase,
53
57
    TestCaseWithMemoryTransport,
54
58
    TestCaseWithTransport,
55
59
    TestNotApplicable,
56
60
    )
 
61
from bzrlib.transport import get_transport
 
62
from bzrlib.transport.memory import MemoryTransport
 
63
from bzrlib.tuned_gzip import GzipFile
57
64
from bzrlib.versionedfile import (
58
65
    AbsentContentFactory,
59
66
    ConstantMapper,
62
69
    )
63
70
 
64
71
 
65
 
compiled_knit_feature = tests.ModuleAvailableFeature(
66
 
                            'bzrlib._knit_load_data_pyx')
 
72
class _CompiledKnitFeature(Feature):
 
73
 
 
74
    def _probe(self):
 
75
        try:
 
76
            import bzrlib._knit_load_data_c
 
77
        except ImportError:
 
78
            return False
 
79
        return True
 
80
 
 
81
    def feature_name(self):
 
82
        return 'bzrlib._knit_load_data_c'
 
83
 
 
84
CompiledKnitFeature = _CompiledKnitFeature()
67
85
 
68
86
 
69
87
class KnitContentTestsMixin(object):
98
116
        line_delta = source_content.line_delta(target_content)
99
117
        delta_blocks = list(KnitContent.get_line_delta_blocks(line_delta,
100
118
            source_lines, target_lines))
101
 
        matcher = PatienceSequenceMatcher(None, source_lines, target_lines)
102
 
        matcher_blocks = list(matcher.get_matching_blocks())
 
119
        matcher = KnitSequenceMatcher(None, source_lines, target_lines)
 
120
        matcher_blocks = list(list(matcher.get_matching_blocks()))
103
121
        self.assertEqual(matcher_blocks, delta_blocks)
104
122
 
105
123
    def test_get_line_delta_blocks(self):
348
366
        :return: (versioned_file, reload_counter)
349
367
            versioned_file  a KnitVersionedFiles using the packs for access
350
368
        """
351
 
        builder = self.make_branch_builder('.', format="1.9")
 
369
        builder = self.make_branch_builder('.')
352
370
        builder.start_series()
353
371
        builder.build_snapshot('rev-1', None, [
354
372
            ('add', ('', 'root-id', 'directory', None)),
692
710
 
693
711
    def create_gz_content(self, text):
694
712
        sio = StringIO()
695
 
        gz_file = tuned_gzip.GzipFile(mode='wb', fileobj=sio)
 
713
        gz_file = gzip.GzipFile(mode='wb', fileobj=sio)
696
714
        gz_file.write(text)
697
715
        gz_file.close()
698
716
        return sio.getvalue()
854
872
 
855
873
    def get_knit_index(self, transport, name, mode):
856
874
        mapper = ConstantMapper(name)
 
875
        orig = knit._load_data
 
876
        def reset():
 
877
            knit._load_data = orig
 
878
        self.addCleanup(reset)
857
879
        from bzrlib._knit_load_data_py import _load_data_py
858
 
        self.overrideAttr(knit, '_load_data', _load_data_py)
 
880
        knit._load_data = _load_data_py
859
881
        allow_writes = lambda: 'w' in mode
860
882
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
861
883
 
1286
1308
 
1287
1309
class LowLevelKnitIndexTests_c(LowLevelKnitIndexTests):
1288
1310
 
1289
 
    _test_needs_features = [compiled_knit_feature]
 
1311
    _test_needs_features = [CompiledKnitFeature]
1290
1312
 
1291
1313
    def get_knit_index(self, transport, name, mode):
1292
1314
        mapper = ConstantMapper(name)
1293
 
        from bzrlib._knit_load_data_pyx import _load_data_c
1294
 
        self.overrideAttr(knit, '_load_data', _load_data_c)
 
1315
        orig = knit._load_data
 
1316
        def reset():
 
1317
            knit._load_data = orig
 
1318
        self.addCleanup(reset)
 
1319
        from bzrlib._knit_load_data_c import _load_data_c
 
1320
        knit._load_data = _load_data_c
1295
1321
        allow_writes = lambda: mode == 'w'
1296
 
        return _KndxIndex(transport, mapper, lambda:None,
1297
 
                          allow_writes, lambda:True)
 
1322
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
1298
1323
 
1299
1324
 
1300
1325
class Test_KnitAnnotator(TestCaseWithMemoryTransport):
1571
1596
        # could leave an empty .kndx file, which bzr would later claim was a
1572
1597
        # corrupted file since the header was not present. In reality, the file
1573
1598
        # just wasn't created, so it should be ignored.
1574
 
        t = transport.get_transport('.')
 
1599
        t = get_transport('.')
1575
1600
        t.put_bytes('test.kndx', '')
1576
1601
 
1577
1602
        knit = self.make_test_knit()
1578
1603
 
1579
1604
    def test_knit_index_checks_header(self):
1580
 
        t = transport.get_transport('.')
 
1605
        t = get_transport('.')
1581
1606
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
1582
1607
        k = self.make_test_knit()
1583
1608
        self.assertRaises(KnitHeaderError, k.keys)