23
from bzrlib import errors
23
24
from bzrlib.errors import KnitError, RevisionAlreadyPresent, NoSuchFile
24
25
from bzrlib.knit import (
27
29
KnitAnnotateFactory,
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
38
class KnitContentTests(TestCase):
40
def test_constructor(self):
41
content = KnitContent([])
44
content = KnitContent([])
45
self.assertEqual(content.text(), [])
47
content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
48
self.assertEqual(content.text(), ["text1", "text2"])
50
def test_annotate(self):
51
content = KnitContent([])
52
self.assertEqual(content.annotate(), [])
54
content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
55
self.assertEqual(content.annotate(),
56
[("origin1", "text1"), ("origin2", "text2")])
58
def test_annotate_iter(self):
59
content = KnitContent([])
60
it = content.annotate_iter()
61
self.assertRaises(StopIteration, it.next)
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)
70
content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
72
self.assertIsInstance(copy, KnitContent)
73
self.assertEqual(copy.annotate(),
74
[("origin1", "text1"), ("origin2", "text2")])
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")])])
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)
36
90
class KnitTests(TestCaseWithTransport):
37
91
"""Class containing knit test helper routines."""
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)
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', '')
760
knit = self.make_test_knit()
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')
766
self.assertRaises(errors.KnitHeaderError, self.make_test_knit)