/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import difflib
21
21
 
22
22
 
 
23
from bzrlib import errors
23
24
from bzrlib.errors import KnitError, RevisionAlreadyPresent, NoSuchFile
24
25
from bzrlib.knit import (
 
26
    KnitContent,
25
27
    KnitVersionedFile,
26
28
    KnitPlainFactory,
27
29
    KnitAnnotateFactory,
28
30
    WeaveToKnit)
29
31
from bzrlib.osutils import split_lines
30
 
from bzrlib.tests import TestCaseWithTransport
 
32
from bzrlib.tests import TestCase, TestCaseWithTransport
31
33
from bzrlib.transport import TransportLogger, get_transport
32
34
from bzrlib.transport.memory import MemoryTransport
33
35
from bzrlib.weave import Weave
34
36
 
35
37
 
 
38
class KnitContentTests(TestCase):
 
39
 
 
40
    def test_constructor(self):
 
41
        content = KnitContent([])
 
42
 
 
43
    def test_text(self):
 
44
        content = KnitContent([])
 
45
        self.assertEqual(content.text(), [])
 
46
 
 
47
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
48
        self.assertEqual(content.text(), ["text1", "text2"])
 
49
 
 
50
    def test_annotate(self):
 
51
        content = KnitContent([])
 
52
        self.assertEqual(content.annotate(), [])
 
53
 
 
54
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
55
        self.assertEqual(content.annotate(),
 
56
            [("origin1", "text1"), ("origin2", "text2")])
 
57
 
 
58
    def test_annotate_iter(self):
 
59
        content = KnitContent([])
 
60
        it = content.annotate_iter()
 
61
        self.assertRaises(StopIteration, it.next)
 
62
 
 
63
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
64
        it = content.annotate_iter()
 
65
        self.assertEqual(it.next(), ("origin1", "text1"))
 
66
        self.assertEqual(it.next(), ("origin2", "text2"))
 
67
        self.assertRaises(StopIteration, it.next)
 
68
 
 
69
    def test_copy(self):
 
70
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
71
        copy = content.copy()
 
72
        self.assertIsInstance(copy, KnitContent)
 
73
        self.assertEqual(copy.annotate(),
 
74
            [("origin1", "text1"), ("origin2", "text2")])
 
75
 
 
76
    def test_line_delta(self):
 
77
        content1 = KnitContent([("", "a"), ("", "b")])
 
78
        content2 = KnitContent([("", "a"), ("", "a"), ("", "c")])
 
79
        self.assertEqual(content1.line_delta(content2),
 
80
            [(1, 2, 2, [("", "a"), ("", "c")])])
 
81
 
 
82
    def test_line_delta_iter(self):
 
83
        content1 = KnitContent([("", "a"), ("", "b")])
 
84
        content2 = KnitContent([("", "a"), ("", "a"), ("", "c")])
 
85
        it = content1.line_delta_iter(content2)
 
86
        self.assertEqual(it.next(), (1, 2, 2, [("", "a"), ("", "c")]))
 
87
        self.assertRaises(StopIteration, it.next)
 
88
 
 
89
 
36
90
class KnitTests(TestCaseWithTransport):
37
91
    """Class containing knit test helper routines."""
38
92
 
694
748
        # And it shouldn't be modified
695
749
        self.assertEqual(['a-1'], idx._history)
696
750
        self.assertEqual({'a-1':('a-1', ['fulltext'], 0, 0, [], 0)}, idx._cache)
 
751
 
 
752
    def test_knit_index_ignores_empty_files(self):
 
753
        # There was a race condition in older bzr, where a ^C at the right time
 
754
        # could leave an empty .kndx file, which bzr would later claim was a
 
755
        # corrupted file since the header was not present. In reality, the file
 
756
        # just wasn't created, so it should be ignored.
 
757
        t = get_transport('.')
 
758
        t.put_bytes('test.kndx', '')
 
759
 
 
760
        knit = self.make_test_knit()
 
761
 
 
762
    def test_knit_index_checks_header(self):
 
763
        t = get_transport('.')
 
764
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
 
765
 
 
766
        self.assertRaises(errors.KnitHeaderError, self.make_test_knit)