~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_multiparent.py

  • Committer: Aaron Bentley
  • Date: 2007-06-11 14:59:52 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070611145952-cwt4480gphdhen6l
Get installation started

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2011 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
1
from unittest import TestCase
18
2
 
19
3
from bzrlib import (
20
4
    multiparent,
21
 
    patiencediff,
22
5
    tests,
23
6
    )
24
7
 
26
9
LINES_1 = "a\nb\nc\nd\ne\n".splitlines(True)
27
10
LINES_2 = "a\nc\nd\ne\n".splitlines(True)
28
11
LINES_3 = "a\nb\nc\nd\n".splitlines(True)
29
 
LF_SPLIT_LINES = ['\x00\n', '\x00\r\x01\n', '\x02\r\xff']
30
12
 
31
13
 
32
14
class Mock(object):
48
30
                          multiparent.ParentText(0, 1, 2, 3)],
49
31
                         diff.hunks)
50
32
 
51
 
        diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
52
 
        self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
53
 
                          multiparent.ParentText(0, 2, 1, 3)],
54
 
                         diff.hunks)
55
 
 
56
33
    def test_compare_two_parents(self):
57
34
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
58
35
        self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
59
36
                          multiparent.ParentText(0, 3, 4, 1)],
60
37
                         diff.hunks)
61
38
 
62
 
    def test_compare_two_parents_blocks(self):
63
 
        matcher = patiencediff.PatienceSequenceMatcher(None, LINES_2, LINES_1)
64
 
        blocks = matcher.get_matching_blocks()
65
 
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3],
66
 
                                                  left_blocks=blocks)
67
 
        self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
68
 
                          multiparent.ParentText(0, 3, 4, 1)],
69
 
                         diff.hunks)
70
 
 
71
 
    def test_get_matching_blocks(self):
72
 
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
73
 
        self.assertEqual([(0, 0, 1), (1, 2, 3), (4, 5, 0)],
74
 
                         list(diff.get_matching_blocks(0, len(LINES_2))))
75
 
 
76
 
        diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
77
 
        self.assertEqual([(0, 0, 1), (2, 1, 3), (5, 4, 0)],
78
 
                         list(diff.get_matching_blocks(0, len(LINES_1))))
79
 
 
80
39
    def test_range_iterator(self):
81
40
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
82
41
        diff.hunks.append(multiparent.NewText(['q\n']))
108
67
        self.assertEqual(multiparent.MultiParent(
109
68
            [multiparent.NewText(['a\n']),
110
69
             multiparent.ParentText(0, 1, 2, 3)]),
111
 
             multiparent.MultiParent.from_patch('i 1\na\n\nc 0 1 2 3'))
 
70
             multiparent.MultiParent.from_patch(
 
71
             ['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n']))
112
72
        self.assertEqual(multiparent.MultiParent(
113
73
            [multiparent.NewText(['a']),
114
74
             multiparent.ParentText(0, 1, 2, 3)]),
115
 
             multiparent.MultiParent.from_patch('i 1\na\nc 0 1 2 3\n'))
116
 
 
117
 
    def test_binary_content(self):
118
 
        patch = list(
119
 
            multiparent.MultiParent.from_lines(LF_SPLIT_LINES).to_patch())
120
 
        multiparent.MultiParent.from_patch(''.join(patch))
121
 
 
122
 
    def test_make_patch_from_binary(self):
123
 
        patch = multiparent.MultiParent.from_texts(''.join(LF_SPLIT_LINES))
124
 
        expected = multiparent.MultiParent([
125
 
            multiparent.NewText(LF_SPLIT_LINES)])
126
 
        self.assertEqual(expected, patch)
 
75
             multiparent.MultiParent.from_patch(
 
76
             ['i 1\n', 'a\n', 'c 0 1 2 3\n']))
127
77
 
128
78
    def test_num_lines(self):
129
79
        mp = multiparent.MultiParent([multiparent.NewText(['a\n'])])
135
85
        mp.hunks.append(multiparent.NewText(['f\n', 'g\n']))
136
86
        self.assertEqual(7, mp.num_lines())
137
87
 
138
 
    def test_to_lines(self):
139
 
        mpdiff = multiparent.MultiParent.from_texts('a\nb\nc\n', ('b\nc\n',))
140
 
        lines = mpdiff.to_lines(('b\ne\n',))
141
 
        self.assertEqual(['a\n', 'b\n', 'e\n'], lines)
142
 
 
143
88
 
144
89
class TestNewText(TestCase):
145
90
 
203
148
        self.assertEqual(REV_A, vf.get_line_list(['rev-a'])[0])
204
149
        self.assertEqual([REV_B, REV_C], vf.get_line_list(['rev-b', 'rev-c']))
205
150
 
206
 
    def test_reconstruct_empty(self):
207
 
        vf = multiparent.MultiMemoryVersionedFile()
208
 
        vf.add_version([], 'a', [])
209
 
        self.assertEqual([], self.reconstruct_version(vf, 'a'))
210
 
 
211
151
    @staticmethod
212
152
    def reconstruct(vf, revision_id, start, end):
213
153
        reconstructor = multiparent._Reconstructor(vf, vf._lines,
265
205
    def test_filenames(self):
266
206
        vf = multiparent.MultiVersionedFile('foop')
267
207
        vf.add_version('a\nb\nc\nd'.splitlines(True), 'a', [])
268
 
        self.assertPathExists('foop.mpknit')
269
 
        self.assertPathDoesNotExist('foop.mpidx')
 
208
        self.failUnlessExists('foop.mpknit')
 
209
        self.failIfExists('foop.mpidx')
270
210
        vf.save()
271
 
        self.assertPathExists('foop.mpidx')
 
211
        self.failUnlessExists('foop.mpidx')
272
212
        vf.destroy()
273
 
        self.assertPathDoesNotExist('foop.mpknit')
274
 
        self.assertPathDoesNotExist('foop.mpidx')
 
213
        self.failIfExists('foop.mpknit')
 
214
        self.failIfExists('foop.mpidx')