~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
31
    tests,
29
 
    transport,
30
 
    tuned_gzip,
31
32
    )
32
33
from bzrlib.errors import (
 
34
    RevisionAlreadyPresent,
33
35
    KnitHeaderError,
 
36
    RevisionNotPresent,
34
37
    NoSuchFile,
35
38
    )
36
39
from bzrlib.index import *
37
40
from bzrlib.knit import (
38
41
    AnnotatedKnitContent,
39
42
    KnitContent,
 
43
    KnitSequenceMatcher,
40
44
    KnitVersionedFiles,
41
45
    PlainKnitContent,
42
46
    _VFContentMapGenerator,
46
50
    _KnitKeyAccess,
47
51
    make_file_factory,
48
52
    )
49
 
from bzrlib.patiencediff import PatienceSequenceMatcher
50
53
from bzrlib.repofmt import pack_repo
51
54
from bzrlib.tests import (
 
55
    Feature,
 
56
    KnownFailure,
52
57
    TestCase,
53
58
    TestCaseWithMemoryTransport,
54
59
    TestCaseWithTransport,
55
60
    TestNotApplicable,
56
61
    )
 
62
from bzrlib.transport import get_transport
 
63
from bzrlib.transport.memory import MemoryTransport
 
64
from bzrlib.tuned_gzip import GzipFile
57
65
from bzrlib.versionedfile import (
58
66
    AbsentContentFactory,
59
67
    ConstantMapper,
98
106
        line_delta = source_content.line_delta(target_content)
99
107
        delta_blocks = list(KnitContent.get_line_delta_blocks(line_delta,
100
108
            source_lines, target_lines))
101
 
        matcher = PatienceSequenceMatcher(None, source_lines, target_lines)
102
 
        matcher_blocks = list(matcher.get_matching_blocks())
 
109
        matcher = KnitSequenceMatcher(None, source_lines, target_lines)
 
110
        matcher_blocks = list(list(matcher.get_matching_blocks()))
103
111
        self.assertEqual(matcher_blocks, delta_blocks)
104
112
 
105
113
    def test_get_line_delta_blocks(self):
692
700
 
693
701
    def create_gz_content(self, text):
694
702
        sio = StringIO()
695
 
        gz_file = tuned_gzip.GzipFile(mode='wb', fileobj=sio)
 
703
        gz_file = gzip.GzipFile(mode='wb', fileobj=sio)
696
704
        gz_file.write(text)
697
705
        gz_file.close()
698
706
        return sio.getvalue()
854
862
 
855
863
    def get_knit_index(self, transport, name, mode):
856
864
        mapper = ConstantMapper(name)
 
865
        orig = knit._load_data
 
866
        def reset():
 
867
            knit._load_data = orig
 
868
        self.addCleanup(reset)
857
869
        from bzrlib._knit_load_data_py import _load_data_py
858
 
        self.overrideAttr(knit, '_load_data', _load_data_py)
 
870
        knit._load_data = _load_data_py
859
871
        allow_writes = lambda: 'w' in mode
860
872
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
861
873
 
1290
1302
 
1291
1303
    def get_knit_index(self, transport, name, mode):
1292
1304
        mapper = ConstantMapper(name)
 
1305
        orig = knit._load_data
 
1306
        def reset():
 
1307
            knit._load_data = orig
 
1308
        self.addCleanup(reset)
1293
1309
        from bzrlib._knit_load_data_pyx import _load_data_c
1294
 
        self.overrideAttr(knit, '_load_data', _load_data_c)
 
1310
        knit._load_data = _load_data_c
1295
1311
        allow_writes = lambda: mode == 'w'
1296
 
        return _KndxIndex(transport, mapper, lambda:None,
1297
 
                          allow_writes, lambda:True)
 
1312
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
1298
1313
 
1299
1314
 
1300
1315
class Test_KnitAnnotator(TestCaseWithMemoryTransport):
1571
1586
        # could leave an empty .kndx file, which bzr would later claim was a
1572
1587
        # corrupted file since the header was not present. In reality, the file
1573
1588
        # just wasn't created, so it should be ignored.
1574
 
        t = transport.get_transport('.')
 
1589
        t = get_transport('.')
1575
1590
        t.put_bytes('test.kndx', '')
1576
1591
 
1577
1592
        knit = self.make_test_knit()
1578
1593
 
1579
1594
    def test_knit_index_checks_header(self):
1580
 
        t = transport.get_transport('.')
 
1595
        t = get_transport('.')
1581
1596
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
1582
1597
        k = self.make_test_knit()
1583
1598
        self.assertRaises(KnitHeaderError, k.keys)