~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

(gz) Backslash escape selftest output when printing to non-unicode consoles
 (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
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()
1579
1571
        # could leave an empty .kndx file, which bzr would later claim was a
1580
1572
        # corrupted file since the header was not present. In reality, the file
1581
1573
        # just wasn't created, so it should be ignored.
1582
 
        t = get_transport('.')
 
1574
        t = transport.get_transport('.')
1583
1575
        t.put_bytes('test.kndx', '')
1584
1576
 
1585
1577
        knit = self.make_test_knit()
1586
1578
 
1587
1579
    def test_knit_index_checks_header(self):
1588
 
        t = get_transport('.')
 
1580
        t = transport.get_transport('.')
1589
1581
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
1590
1582
        k = self.make_test_knit()
1591
1583
        self.assertRaises(KnitHeaderError, k.keys)