/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_multiparent.py

  • Committer: Aaron Bentley
  • Date: 2007-06-13 03:54:07 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: aaron.bentley@utoronto.ca-20070613035407-6tijerg0tti5wocg
Fix _get_bundle invocations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 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
 
    knit,
21
4
    multiparent,
22
 
    patiencediff,
23
5
    tests,
24
6
    )
25
7
 
27
9
LINES_1 = "a\nb\nc\nd\ne\n".splitlines(True)
28
10
LINES_2 = "a\nc\nd\ne\n".splitlines(True)
29
11
LINES_3 = "a\nb\nc\nd\n".splitlines(True)
30
 
LF_SPLIT_LINES = ['\x00\n', '\x00\r\x01\n', '\x02\r\xff']
31
12
 
32
13
 
33
14
class Mock(object):
49
30
                          multiparent.ParentText(0, 1, 2, 3)],
50
31
                         diff.hunks)
51
32
 
52
 
        diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
53
 
        self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
54
 
                          multiparent.ParentText(0, 2, 1, 3)],
55
 
                         diff.hunks)
56
 
 
57
33
    def test_compare_two_parents(self):
58
34
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
59
35
        self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
60
36
                          multiparent.ParentText(0, 3, 4, 1)],
61
37
                         diff.hunks)
62
38
 
63
 
    def test_compare_two_parents_blocks(self):
64
 
        matcher = patiencediff.PatienceSequenceMatcher(None, LINES_2, LINES_1)
65
 
        blocks = matcher.get_matching_blocks()
66
 
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3],
67
 
                                                  left_blocks=blocks)
68
 
        self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
69
 
                          multiparent.ParentText(0, 3, 4, 1)],
70
 
                         diff.hunks)
71
 
 
72
 
    def test_get_matching_blocks(self):
73
 
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
74
 
        self.assertEqual([(0, 0, 1), (1, 2, 3), (4, 5, 0)],
75
 
                         list(diff.get_matching_blocks(0, len(LINES_2))))
76
 
 
77
 
        diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
78
 
        self.assertEqual([(0, 0, 1), (2, 1, 3), (5, 4, 0)],
79
 
                         list(diff.get_matching_blocks(0, len(LINES_1))))
80
 
 
81
39
    def test_range_iterator(self):
82
40
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
83
41
        diff.hunks.append(multiparent.NewText(['q\n']))
109
67
        self.assertEqual(multiparent.MultiParent(
110
68
            [multiparent.NewText(['a\n']),
111
69
             multiparent.ParentText(0, 1, 2, 3)]),
112
 
             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']))
113
72
        self.assertEqual(multiparent.MultiParent(
114
73
            [multiparent.NewText(['a']),
115
74
             multiparent.ParentText(0, 1, 2, 3)]),
116
 
             multiparent.MultiParent.from_patch('i 1\na\nc 0 1 2 3\n'))
117
 
 
118
 
    def test_binary_content(self):
119
 
        patch = list(
120
 
            multiparent.MultiParent.from_lines(LF_SPLIT_LINES).to_patch())
121
 
        multiparent.MultiParent.from_patch(''.join(patch))
122
 
 
123
 
    def test_make_patch_from_binary(self):
124
 
        patch = multiparent.MultiParent.from_texts(''.join(LF_SPLIT_LINES))
125
 
        expected = multiparent.MultiParent([
126
 
            multiparent.NewText(LF_SPLIT_LINES)])
127
 
        self.assertEqual(expected, patch)
 
75
             multiparent.MultiParent.from_patch(
 
76
             ['i 1\n', 'a\n', 'c 0 1 2 3\n']))
128
77
 
129
78
    def test_num_lines(self):
130
79
        mp = multiparent.MultiParent([multiparent.NewText(['a\n'])])
136
85
        mp.hunks.append(multiparent.NewText(['f\n', 'g\n']))
137
86
        self.assertEqual(7, mp.num_lines())
138
87
 
139
 
    def test_to_lines(self):
140
 
        mpdiff = multiparent.MultiParent.from_texts('a\nb\nc\n', ('b\nc\n',))
141
 
        lines = mpdiff.to_lines(('b\ne\n',))
142
 
        self.assertEqual(['a\n', 'b\n', 'e\n'], lines)
143
 
 
144
88
 
145
89
class TestNewText(TestCase):
146
90
 
204
148
        self.assertEqual(REV_A, vf.get_line_list(['rev-a'])[0])
205
149
        self.assertEqual([REV_B, REV_C], vf.get_line_list(['rev-b', 'rev-c']))
206
150
 
207
 
    def test_reconstruct_empty(self):
208
 
        vf = multiparent.MultiMemoryVersionedFile()
209
 
        vf.add_version([], 'a', [])
210
 
        self.assertEqual([], self.reconstruct_version(vf, 'a'))
211
 
 
212
151
    @staticmethod
213
152
    def reconstruct(vf, revision_id, start, end):
214
153
        reconstructor = multiparent._Reconstructor(vf, vf._lines,