~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: 2006-11-28 15:11:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2152.
  • Revision ID: john@arbash-meinel.com-20061128151137-1f1z1a0qgdg3yas1
(Dmitry Vasiliev) Tune KnitContent and add tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib.errors import KnitError, RevisionAlreadyPresent, NoSuchFile
24
24
from bzrlib.knit import (
 
25
    KnitContent,
25
26
    KnitVersionedFile,
26
27
    KnitPlainFactory,
27
28
    KnitAnnotateFactory,
28
29
    WeaveToKnit)
29
30
from bzrlib.osutils import split_lines
30
 
from bzrlib.tests import TestCaseWithTransport
 
31
from bzrlib.tests import TestCase, TestCaseWithTransport
31
32
from bzrlib.transport import TransportLogger, get_transport
32
33
from bzrlib.transport.memory import MemoryTransport
33
34
from bzrlib.weave import Weave
34
35
 
35
36
 
 
37
class KnitContentTests(TestCase):
 
38
 
 
39
    def test_constructor(self):
 
40
        content = KnitContent([])
 
41
 
 
42
    def test_text(self):
 
43
        content = KnitContent([])
 
44
        self.assertEqual(content.text(), [])
 
45
 
 
46
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
47
        self.assertEqual(content.text(), ["text1", "text2"])
 
48
 
 
49
    def test_annotate(self):
 
50
        content = KnitContent([])
 
51
        self.assertEqual(content.annotate(), [])
 
52
 
 
53
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
54
        self.assertEqual(content.annotate(),
 
55
            [("origin1", "text1"), ("origin2", "text2")])
 
56
 
 
57
    def test_annotate_iter(self):
 
58
        content = KnitContent([])
 
59
        it = content.annotate_iter()
 
60
        self.assertRaises(StopIteration, it.next)
 
61
 
 
62
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
63
        it = content.annotate_iter()
 
64
        self.assertEqual(it.next(), ("origin1", "text1"))
 
65
        self.assertEqual(it.next(), ("origin2", "text2"))
 
66
        self.assertRaises(StopIteration, it.next)
 
67
 
 
68
    def test_copy(self):
 
69
        content = KnitContent([("origin1", "text1"), ("origin2", "text2")])
 
70
        copy = content.copy()
 
71
        self.assertIsInstance(copy, KnitContent)
 
72
        self.assertEqual(copy.annotate(),
 
73
            [("origin1", "text1"), ("origin2", "text2")])
 
74
 
 
75
    def test_line_delta(self):
 
76
        content1 = KnitContent([("", "a"), ("", "b")])
 
77
        content2 = KnitContent([("", "a"), ("", "a"), ("", "c")])
 
78
        self.assertEqual(content1.line_delta(content2),
 
79
            [(1, 2, 2, [("", "a"), ("", "c")])])
 
80
 
 
81
    def test_line_delta_iter(self):
 
82
        content1 = KnitContent([("", "a"), ("", "b")])
 
83
        content2 = KnitContent([("", "a"), ("", "a"), ("", "c")])
 
84
        it = content1.line_delta_iter(content2)
 
85
        self.assertEqual(it.next(), (1, 2, 2, [("", "a"), ("", "c")]))
 
86
        self.assertRaises(StopIteration, it.next)
 
87
 
36
88
class KnitTests(TestCaseWithTransport):
37
89
    """Class containing knit test helper routines."""
38
90