~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tests/test_multiparent.py

  • Committer: Aaron Bentley
  • Date: 2007-04-10 16:24:05 UTC
  • mto: (2520.4.1 bzr.mpbundle) (0.9.13 temp)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070410162405-sczvbxmrwek7l2g5
Get single-parent comparison working

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import multiparent
4
4
 
5
5
LINES_1 = "a\nb\nc\nd\ne\n".splitlines(True)
 
6
LINES_2 = "a\nc\nd\ne\n".splitlines(True)
 
7
 
 
8
 
 
9
class Mock(object):
 
10
 
 
11
    def __init__(self, **kwargs):
 
12
        self.__dict__ = kwargs
 
13
 
6
14
 
7
15
class TestMulti(TestCase):
8
16
 
9
 
    def test_compare(self):
10
 
        diff = multiparent.MultiParent.from_lines(LINES_1)
11
 
        self.assertEqual(diff.hunks, [multiparent.NewText(LINES_1)])
 
17
    def test_compare_no_parent(self):
 
18
        diff = multiparent.MultiParent.from_lines(LINES_1)
 
19
        self.assertEqual([multiparent.NewText(LINES_1)], diff.hunks)
 
20
 
 
21
    def test_compare_one_parent(self):
 
22
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
 
23
        self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
 
24
                          multiparent.NewText(['b\n']),
 
25
                          multiparent.ParentText(0, 1, 2, 3)],
 
26
                         diff.hunks)
 
27
 
 
28
    def test_eq(self):
 
29
        diff = multiparent.MultiParent.from_lines(LINES_1)
 
30
        diff2 = multiparent.MultiParent.from_lines(LINES_1)
 
31
        self.assertEqual(diff, diff2)
 
32
        diff3 = multiparent.MultiParent.from_lines(LINES_2)
 
33
        self.assertFalse(diff == diff3)
 
34
        self.assertFalse(diff == Mock(hunks=[multiparent.NewText(LINES_1)]))
 
35
        self.assertEqual(multiparent.MultiParent(
 
36
                         [multiparent.NewText(LINES_1),
 
37
                          multiparent.ParentText(0, 1, 2, 3)]),
 
38
                         multiparent.MultiParent(
 
39
                         [multiparent.NewText(LINES_1),
 
40
                          multiparent.ParentText(0, 1, 2, 3)]))
12
41
 
13
42
 
14
43
class TestNewText(TestCase):
17
46
        self.assertEqual(multiparent.NewText([]), multiparent.NewText([]))
18
47
        self.assertFalse(multiparent.NewText(['a']) ==
19
48
                         multiparent.NewText(['b']))
20
 
        class ThingWithLines(object):
21
 
            def __init__(self):
22
 
                self.lines = ['a']
23
 
        self.assertFalse(multiparent.NewText(['a']) == ThingWithLines())
 
49
        self.assertFalse(multiparent.NewText(['a']) == Mock(lines=['a']))
 
50
 
 
51
 
 
52
class TestParentText(TestCase):
 
53
 
 
54
    def test_eq(self):
 
55
        self.assertEqual(multiparent.ParentText(1, 2, 3, 4),
 
56
                         multiparent.ParentText(1, 2, 3, 4))
 
57
        self.assertFalse(multiparent.ParentText(1, 2, 3, 4) ==
 
58
                         multiparent.ParentText(2, 2, 3, 4))
 
59
 
 
60
        self.assertFalse(multiparent.ParentText(1, 2, 3, 4) ==
 
61
                         Mock(parent=1, parent_pos=2, child_pos=3,
 
62
                              num_lines=4))