~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

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