~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2011, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
16
17
1083 by Martin Pool
- add space to store revision-id in weave files
18
# TODO: tests regarding version names
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
19
# TODO: rbc 20050108 test that join does not leave an inconsistent weave
1185.13.4 by Robert Collins
make reweave visible as a weave method, and quickly integrate into fetch
20
#       if it fails.
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
21
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
22
"""test suite for weave algorithm"""
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
23
1323 by Martin Pool
- caller can pass SHA-1 to Weave.add for efficiency
24
from pprint import pformat
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
25
2024.1.1 by John Arbash Meinel
When a weave file is empty, we should get WeaveFormatError, not StopIteration
26
from bzrlib import (
27
    errors,
28
    )
29
from bzrlib.osutils import sha_string
5582.10.41 by Jelmer Vernooij
revert weavefile changes
30
from bzrlib.tests import TestCase, TestCaseInTempDir
31
from bzrlib.weave import Weave, WeaveFormatError
32
from bzrlib.weavefile import write_weave, read_weave
0.1.66 by Martin Pool
Cope without set/frozenset classes
33
34
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
35
# texts for use in testing
0.1.3 by Martin Pool
Change storage of texts for testing
36
TEXT_0 = ["Hello world"]
37
TEXT_1 = ["Hello world",
38
          "A second line"]
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
39
40
1233 by Martin Pool
- fix up weave tests for new test framework
41
class TestBase(TestCase):
2776.1.1 by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed
42
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
43
    def check_read_write(self, k):
44
        """Check the weave k can be written & re-read."""
45
        from tempfile import TemporaryFile
46
        tf = TemporaryFile()
47
48
        write_weave(k, tf)
49
        tf.seek(0)
50
        k2 = read_weave(tf)
51
52
        if k != k2:
53
            tf.seek(0)
54
            self.log('serialized weave:')
55
            self.log(tf.read())
1083 by Martin Pool
- add space to store revision-id in weave files
56
57
            self.log('')
58
            self.log('parents: %s' % (k._parents == k2._parents))
59
            self.log('         %r' % k._parents)
60
            self.log('         %r' % k2._parents)
61
            self.log('')
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
62
            self.fail('read/write check failed')
1185.16.125 by Martin Pool
Test for 'name in weave'
63
64
65
class WeaveContains(TestBase):
66
    """Weave __contains__ operator"""
5582.10.32 by Jelmer Vernooij
Cleanups.
67
1185.16.125 by Martin Pool
Test for 'name in weave'
68
    def runTest(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
69
        k = Weave(get_scope=lambda:None)
1185.16.125 by Martin Pool
Test for 'name in weave'
70
        self.assertFalse('foo' in k)
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
71
        k.add_lines('foo', [], TEXT_1)
1185.16.125 by Martin Pool
Test for 'name in weave'
72
        self.assertTrue('foo' in k)
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
73
74
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
75
class Easy(TestBase):
5582.10.32 by Jelmer Vernooij
Cleanups.
76
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
77
    def runTest(self):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
78
        k = Weave()
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
79
80
0.1.7 by Martin Pool
Add trivial annotate text
81
class AnnotateOne(TestBase):
5582.10.32 by Jelmer Vernooij
Cleanups.
82
0.1.7 by Martin Pool
Add trivial annotate text
83
    def runTest(self):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
84
        k = Weave()
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
85
        k.add_lines('text0', [], TEXT_0)
86
        self.assertEqual(k.annotate('text0'),
87
                         [('text0', TEXT_0[0])])
0.1.7 by Martin Pool
Add trivial annotate text
88
89
0.1.27 by Martin Pool
Check that version numbers passed in are reasonable
90
class InvalidAdd(TestBase):
91
    """Try to use invalid version number during add."""
5582.10.32 by Jelmer Vernooij
Cleanups.
92
0.1.27 by Martin Pool
Check that version numbers passed in are reasonable
93
    def runTest(self):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
94
        k = Weave()
0.1.27 by Martin Pool
Check that version numbers passed in are reasonable
95
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
96
        self.assertRaises(errors.RevisionNotPresent,
97
                          k.add_lines,
1083 by Martin Pool
- add space to store revision-id in weave files
98
                          'text0',
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
99
                          ['69'],
0.1.27 by Martin Pool
Check that version numbers passed in are reasonable
100
                          ['new text!'])
101
102
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
103
class RepeatedAdd(TestBase):
104
    """Add the same version twice; harmless."""
2776.1.1 by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed
105
106
    def test_duplicate_add(self):
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
107
        k = Weave()
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
108
        idx = k.add_lines('text0', [], TEXT_0)
109
        idx2 = k.add_lines('text0', [], TEXT_0)
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
110
        self.assertEqual(idx, idx2)
111
112
113
class InvalidRepeatedAdd(TestBase):
5582.10.32 by Jelmer Vernooij
Cleanups.
114
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
115
    def runTest(self):
116
        k = Weave()
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
117
        k.add_lines('basis', [], TEXT_0)
118
        idx = k.add_lines('text0', [], TEXT_0)
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
119
        self.assertRaises(errors.RevisionAlreadyPresent,
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
120
                          k.add_lines,
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
121
                          'text0',
122
                          [],
123
                          ['not the same text'])
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
124
        self.assertRaises(errors.RevisionAlreadyPresent,
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
125
                          k.add_lines,
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
126
                          'text0',
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
127
                          ['basis'],         # not the right parents
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
128
                          TEXT_0)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
129
1237 by Martin Pool
- allow the same version to be repeatedly added to a weave
130
0.1.26 by Martin Pool
Refactor parameters to add command
131
class InsertLines(TestBase):
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
132
    """Store a revision that adds one line to the original.
133
134
    Look at the annotations to make sure that the first line is matched
135
    and not stored repeatedly."""
136
    def runTest(self):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
137
        k = Weave()
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
138
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
139
        k.add_lines('text0', [], ['line 1'])
140
        k.add_lines('text1', ['text0'], ['line 1', 'line 2'])
141
142
        self.assertEqual(k.annotate('text0'),
143
                         [('text0', 'line 1')])
144
145
        self.assertEqual(k.get_lines(1),
0.1.25 by Martin Pool
Handle insertion of new weave layers that insert text on top of the basis
146
                         ['line 1',
147
                          'line 2'])
148
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
149
        self.assertEqual(k.annotate('text1'),
150
                         [('text0', 'line 1'),
151
                          ('text1', 'line 2')])
152
153
        k.add_lines('text2', ['text0'], ['line 1', 'diverged line'])
154
155
        self.assertEqual(k.annotate('text2'),
156
                         [('text0', 'line 1'),
157
                          ('text2', 'diverged line')])
0.1.28 by Martin Pool
More tests for insertion of lines in new versions.
158
0.1.54 by Martin Pool
Fix weave line calculation when making deltas
159
        text3 = ['line 1', 'middle line', 'line 2']
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
160
        k.add_lines('text3',
161
              ['text0', 'text1'],
0.1.54 by Martin Pool
Fix weave line calculation when making deltas
162
              text3)
163
937 by Martin Pool
- weave raises IndexError when an invalid revision is given
164
        # self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]), text3))))
0.1.54 by Martin Pool
Fix weave line calculation when making deltas
165
944 by Martin Pool
- refactor member names in Weave code
166
        self.log("k._weave=" + pformat(k._weave))
0.1.28 by Martin Pool
More tests for insertion of lines in new versions.
167
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
168
        self.assertEqual(k.annotate('text3'),
169
                         [('text0', 'line 1'),
170
                          ('text3', 'middle line'),
171
                          ('text1', 'line 2')])
0.1.28 by Martin Pool
More tests for insertion of lines in new versions.
172
0.1.31 by Martin Pool
Fix insertion of multiple regions, calculating the right line offset as we go.
173
        # now multiple insertions at different places
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
174
        k.add_lines('text4',
175
              ['text0', 'text1', 'text3'],
0.1.31 by Martin Pool
Fix insertion of multiple regions, calculating the right line offset as we go.
176
              ['line 1', 'aaa', 'middle line', 'bbb', 'line 2', 'ccc'])
177
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
178
        self.assertEqual(k.annotate('text4'),
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
179
                         [('text0', 'line 1'),
180
                          ('text4', 'aaa'),
181
                          ('text3', 'middle line'),
182
                          ('text4', 'bbb'),
183
                          ('text1', 'line 2'),
184
                          ('text4', 'ccc')])
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
185
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
186
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
187
class DeleteLines(TestBase):
188
    """Deletion of lines from existing text.
189
190
    Try various texts all based on a common ancestor."""
191
    def runTest(self):
192
        k = Weave()
193
194
        base_text = ['one', 'two', 'three', 'four']
195
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
196
        k.add_lines('text0', [], base_text)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
197
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
198
        texts = [['one', 'two', 'three'],
199
                 ['two', 'three', 'four'],
200
                 ['one', 'four'],
201
                 ['one', 'two', 'three', 'four'],
202
                 ]
203
1083 by Martin Pool
- add space to store revision-id in weave files
204
        i = 1
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
205
        for t in texts:
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
206
            ver = k.add_lines('text%d' % i,
207
                        ['text0'], t)
1083 by Martin Pool
- add space to store revision-id in weave files
208
            i += 1
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
209
210
        self.log('final weave:')
944 by Martin Pool
- refactor member names in Weave code
211
        self.log('k._weave=' + pformat(k._weave))
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
212
213
        for i in range(len(texts)):
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
214
            self.assertEqual(k.get_lines(i+1),
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
215
                             texts[i])
216
217
0.1.49 by Martin Pool
Add another constraint: revisions should not delete text that they
218
class SuicideDelete(TestBase):
0.1.55 by Martin Pool
doc
219
    """Invalid weave which tries to add and delete simultaneously."""
0.1.49 by Martin Pool
Add another constraint: revisions should not delete text that they
220
    def runTest(self):
221
        k = Weave()
222
944 by Martin Pool
- refactor member names in Weave code
223
        k._parents = [(),
0.1.49 by Martin Pool
Add another constraint: revisions should not delete text that they
224
                ]
944 by Martin Pool
- refactor member names in Weave code
225
        k._weave = [('{', 0),
0.1.49 by Martin Pool
Add another constraint: revisions should not delete text that they
226
                'first line',
227
                ('[', 0),
228
                'deleted in 0',
229
                (']', 0),
230
                ('}', 0),
231
                ]
891 by Martin Pool
- fix up refactoring of weave
232
        ################################### SKIPPED
233
        # Weave.get doesn't trap this anymore
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
234
        return
0.1.49 by Martin Pool
Add another constraint: revisions should not delete text that they
235
236
        self.assertRaises(WeaveFormatError,
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
237
                          k.get_lines,
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
238
                          0)
0.1.49 by Martin Pool
Add another constraint: revisions should not delete text that they
239
240
0.1.48 by Martin Pool
Basic parsing of delete instructions.
241
class CannedDelete(TestBase):
242
    """Unpack canned weave with deleted lines."""
243
    def runTest(self):
244
        k = Weave()
245
944 by Martin Pool
- refactor member names in Weave code
246
        k._parents = [(),
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
247
                frozenset([0]),
0.1.48 by Martin Pool
Basic parsing of delete instructions.
248
                ]
944 by Martin Pool
- refactor member names in Weave code
249
        k._weave = [('{', 0),
0.1.48 by Martin Pool
Basic parsing of delete instructions.
250
                'first line',
251
                ('[', 1),
252
                'line to be deleted',
253
                (']', 1),
254
                'last line',
255
                ('}', 0),
256
                ]
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
257
        k._sha1s = [sha_string('first lineline to be deletedlast line')
258
                  , sha_string('first linelast line')]
0.1.48 by Martin Pool
Basic parsing of delete instructions.
259
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
260
        self.assertEqual(k.get_lines(0),
0.1.48 by Martin Pool
Basic parsing of delete instructions.
261
                         ['first line',
262
                          'line to be deleted',
263
                          'last line',
264
                          ])
265
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
266
        self.assertEqual(k.get_lines(1),
0.1.50 by Martin Pool
Basic implementation of deletion markers
267
                         ['first line',
268
                          'last line',
269
                          ])
270
0.1.48 by Martin Pool
Basic parsing of delete instructions.
271
0.1.51 by Martin Pool
Add test for replacement lines
272
class CannedReplacement(TestBase):
273
    """Unpack canned weave with deleted lines."""
274
    def runTest(self):
275
        k = Weave()
276
944 by Martin Pool
- refactor member names in Weave code
277
        k._parents = [frozenset(),
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
278
                frozenset([0]),
0.1.51 by Martin Pool
Add test for replacement lines
279
                ]
944 by Martin Pool
- refactor member names in Weave code
280
        k._weave = [('{', 0),
0.1.51 by Martin Pool
Add test for replacement lines
281
                'first line',
282
                ('[', 1),
283
                'line to be deleted',
284
                (']', 1),
285
                ('{', 1),
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
286
                'replacement line',
0.1.51 by Martin Pool
Add test for replacement lines
287
                ('}', 1),
288
                'last line',
289
                ('}', 0),
290
                ]
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
291
        k._sha1s = [sha_string('first lineline to be deletedlast line')
292
                  , sha_string('first linereplacement linelast line')]
0.1.51 by Martin Pool
Add test for replacement lines
293
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
294
        self.assertEqual(k.get_lines(0),
0.1.51 by Martin Pool
Add test for replacement lines
295
                         ['first line',
296
                          'line to be deleted',
297
                          'last line',
298
                          ])
299
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
300
        self.assertEqual(k.get_lines(1),
0.1.51 by Martin Pool
Add test for replacement lines
301
                         ['first line',
302
                          'replacement line',
303
                          'last line',
304
                          ])
305
306
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
307
class BadWeave(TestBase):
308
    """Test that we trap an insert which should not occur."""
309
    def runTest(self):
310
        k = Weave()
311
944 by Martin Pool
- refactor member names in Weave code
312
        k._parents = [frozenset(),
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
313
                ]
944 by Martin Pool
- refactor member names in Weave code
314
        k._weave = ['bad line',
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
315
                ('{', 0),
316
                'foo {',
317
                ('{', 1),
318
                '  added in version 1',
319
                ('{', 2),
320
                '  added in v2',
321
                ('}', 2),
322
                '  also from v1',
323
                ('}', 1),
324
                '}',
325
                ('}', 0)]
326
891 by Martin Pool
- fix up refactoring of weave
327
        ################################### SKIPPED
328
        # Weave.get doesn't trap this anymore
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
329
        return
891 by Martin Pool
- fix up refactoring of weave
330
331
0.1.47 by Martin Pool
New WeaveError and WeaveFormatError rather than assertions.
332
        self.assertRaises(WeaveFormatError,
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
333
                          k.get,
334
                          0)
335
336
337
class BadInsert(TestBase):
338
    """Test that we trap an insert which should not occur."""
339
    def runTest(self):
340
        k = Weave()
341
944 by Martin Pool
- refactor member names in Weave code
342
        k._parents = [frozenset(),
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
343
                frozenset([0]),
344
                frozenset([0]),
345
                frozenset([0,1,2]),
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
346
                ]
944 by Martin Pool
- refactor member names in Weave code
347
        k._weave = [('{', 0),
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
348
                'foo {',
349
                ('{', 1),
350
                '  added in version 1',
351
                ('{', 1),
352
                '  more in 1',
353
                ('}', 1),
354
                ('}', 1),
355
                ('}', 0)]
356
891 by Martin Pool
- fix up refactoring of weave
357
358
        # this is not currently enforced by get
359
        return  ##########################################
360
0.1.47 by Martin Pool
New WeaveError and WeaveFormatError rather than assertions.
361
        self.assertRaises(WeaveFormatError,
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
362
                          k.get,
363
                          0)
364
0.1.47 by Martin Pool
New WeaveError and WeaveFormatError rather than assertions.
365
        self.assertRaises(WeaveFormatError,
0.1.46 by Martin Pool
More constraints on structure of weave, and checks that they work
366
                          k.get,
367
                          1)
368
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
369
370
class InsertNested(TestBase):
371
    """Insertion with nested instructions."""
372
    def runTest(self):
373
        k = Weave()
374
944 by Martin Pool
- refactor member names in Weave code
375
        k._parents = [frozenset(),
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
376
                frozenset([0]),
377
                frozenset([0]),
378
                frozenset([0,1,2]),
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
379
                ]
944 by Martin Pool
- refactor member names in Weave code
380
        k._weave = [('{', 0),
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
381
                'foo {',
382
                ('{', 1),
383
                '  added in version 1',
0.1.42 by Martin Pool
More tests for nested insert instructions
384
                ('{', 2),
385
                '  added in v2',
386
                ('}', 2),
387
                '  also from v1',
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
388
                ('}', 1),
389
                '}',
390
                ('}', 0)]
391
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
392
        k._sha1s = [sha_string('foo {}')
393
                  , sha_string('foo {  added in version 1  also from v1}')
394
                  , sha_string('foo {  added in v2}')
395
                  , sha_string('foo {  added in version 1  added in v2  also from v1}')
396
                  ]
397
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
398
        self.assertEqual(k.get_lines(0),
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
399
                         ['foo {',
400
                          '}'])
401
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
402
        self.assertEqual(k.get_lines(1),
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
403
                         ['foo {',
404
                          '  added in version 1',
0.1.42 by Martin Pool
More tests for nested insert instructions
405
                          '  also from v1',
0.1.40 by Martin Pool
Add test for extracting from weave with nested insertions
406
                          '}'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
407
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
408
        self.assertEqual(k.get_lines(2),
0.1.44 by Martin Pool
More tests for nested insert instructions
409
                         ['foo {',
410
                          '  added in v2',
411
                          '}'])
412
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
413
        self.assertEqual(k.get_lines(3),
0.1.44 by Martin Pool
More tests for nested insert instructions
414
                         ['foo {',
415
                          '  added in version 1',
416
                          '  added in v2',
417
                          '  also from v1',
418
                          '}'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
419
0.1.45 by Martin Pool
doc
420
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
421
class DeleteLines2(TestBase):
0.1.30 by Martin Pool
Start adding tests for line deletion
422
    """Test recording revisions that delete lines.
423
424
    This relies on the weave having a way to represent lines knocked
425
    out by a later revision."""
426
    def runTest(self):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
427
        k = Weave()
0.1.30 by Martin Pool
Start adding tests for line deletion
428
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
429
        k.add_lines('text0', [], ["line the first",
0.1.30 by Martin Pool
Start adding tests for line deletion
430
                   "line 2",
431
                   "line 3",
432
                   "fine"])
433
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
434
        self.assertEqual(len(k.get_lines(0)), 4)
0.1.30 by Martin Pool
Start adding tests for line deletion
435
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
436
        k.add_lines('text1', ['text0'], ["line the first",
0.1.30 by Martin Pool
Start adding tests for line deletion
437
                   "fine"])
438
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
439
        self.assertEqual(k.get_lines(1),
0.1.30 by Martin Pool
Start adding tests for line deletion
440
                         ["line the first",
441
                          "fine"])
442
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
443
        self.assertEqual(k.annotate('text1'),
444
                         [('text0', "line the first"),
445
                          ('text0', "fine")])
0.1.56 by Martin Pool
Handle deletion of lines by marking the region with a deletion
446
0.1.30 by Martin Pool
Start adding tests for line deletion
447
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
448
class IncludeVersions(TestBase):
449
    """Check texts that are stored across multiple revisions.
450
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
451
    Here we manually create a weave with particular encoding and make
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
452
    sure it unpacks properly.
453
454
    Text 0 includes nothing; text 1 includes text 0 and adds some
455
    lines.
456
    """
457
458
    def runTest(self):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
459
        k = Weave()
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
460
944 by Martin Pool
- refactor member names in Weave code
461
        k._parents = [frozenset(), frozenset([0])]
462
        k._weave = [('{', 0),
0.1.39 by Martin Pool
Change to a more realistic weave structure which can represent insertions and
463
                "first line",
464
                ('}', 0),
465
                ('{', 1),
466
                "second line",
467
                ('}', 1)]
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
468
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
469
        k._sha1s = [sha_string('first line')
470
                  , sha_string('first linesecond line')]
471
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
472
        self.assertEqual(k.get_lines(1),
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
473
                         ["first line",
474
                          "second line"])
475
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
476
        self.assertEqual(k.get_lines(0),
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
477
                         ["first line"])
478
0.1.5 by Martin Pool
Add test for storing two text versions.
479
0.1.14 by Martin Pool
Another test for version inclusion
480
class DivergedIncludes(TestBase):
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
481
    """Weave with two diverged texts based on version 0.
0.1.14 by Martin Pool
Another test for version inclusion
482
    """
483
    def runTest(self):
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
484
        # FIXME make the weave, dont poke at it.
0.1.38 by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.)
485
        k = Weave()
0.1.14 by Martin Pool
Another test for version inclusion
486
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
487
        k._names = ['0', '1', '2']
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
488
        k._name_map = {'0':0, '1':1, '2':2}
944 by Martin Pool
- refactor member names in Weave code
489
        k._parents = [frozenset(),
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
490
                frozenset([0]),
491
                frozenset([0]),
0.1.17 by Martin Pool
Use objects rather than tuples for tracking VerInfo for
492
                ]
944 by Martin Pool
- refactor member names in Weave code
493
        k._weave = [('{', 0),
0.1.39 by Martin Pool
Change to a more realistic weave structure which can represent insertions and
494
                "first line",
495
                ('}', 0),
496
                ('{', 1),
497
                "second line",
498
                ('}', 1),
499
                ('{', 2),
500
                "alternative second line",
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
501
                ('}', 2),
0.1.39 by Martin Pool
Change to a more realistic weave structure which can represent insertions and
502
                ]
0.1.14 by Martin Pool
Another test for version inclusion
503
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
504
        k._sha1s = [sha_string('first line')
505
                  , sha_string('first linesecond line')
506
                  , sha_string('first linealternative second line')]
507
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
508
        self.assertEqual(k.get_lines(0),
0.1.14 by Martin Pool
Another test for version inclusion
509
                         ["first line"])
510
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
511
        self.assertEqual(k.get_lines(1),
0.1.14 by Martin Pool
Another test for version inclusion
512
                         ["first line",
513
                          "second line"])
514
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
515
        self.assertEqual(k.get_lines('2'),
0.1.14 by Martin Pool
Another test for version inclusion
516
                         ["first line",
517
                          "alternative second line"])
518
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
519
        self.assertEqual(list(k.get_ancestry(['2'])),
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
520
                         ['0', '2'])
0.1.77 by Martin Pool
New Weave.get_included() does transitive expansion
521
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
522
523
class ReplaceLine(TestBase):
524
    def runTest(self):
525
        k = Weave()
526
527
        text0 = ['cheddar', 'stilton', 'gruyere']
528
        text1 = ['cheddar', 'blue vein', 'neufchatel', 'chevre']
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
529
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
530
        k.add_lines('text0', [], text0)
531
        k.add_lines('text1', ['text0'], text1)
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
532
944 by Martin Pool
- refactor member names in Weave code
533
        self.log('k._weave=' + pformat(k._weave))
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
534
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
535
        self.assertEqual(k.get_lines(0), text0)
536
        self.assertEqual(k.get_lines(1), text1)
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
537
0.1.64 by Martin Pool
Add test for merging versions
538
539
class Merge(TestBase):
0.1.95 by Martin Pool
- preliminary merge conflict detection
540
    """Storage of versions that merge diverged parents"""
5582.10.32 by Jelmer Vernooij
Cleanups.
541
0.1.64 by Martin Pool
Add test for merging versions
542
    def runTest(self):
543
        k = Weave()
544
545
        texts = [['header'],
546
                 ['header', '', 'line from 1'],
547
                 ['header', '', 'line from 2', 'more from 2'],
548
                 ['header', '', 'line from 1', 'fixup line', 'line from 2'],
549
                 ]
550
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
551
        k.add_lines('text0', [], texts[0])
552
        k.add_lines('text1', ['text0'], texts[1])
553
        k.add_lines('text2', ['text0'], texts[2])
554
        k.add_lines('merge', ['text0', 'text1', 'text2'], texts[3])
0.1.64 by Martin Pool
Add test for merging versions
555
556
        for i, t in enumerate(texts):
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
557
            self.assertEqual(k.get_lines(i), t)
0.1.64 by Martin Pool
Add test for merging versions
558
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
559
        self.assertEqual(k.annotate('merge'),
560
                         [('text0', 'header'),
561
                          ('text1', ''),
562
                          ('text1', 'line from 1'),
563
                          ('merge', 'fixup line'),
564
                          ('text2', 'line from 2'),
0.1.64 by Martin Pool
Add test for merging versions
565
                          ])
566
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
567
        self.assertEqual(list(k.get_ancestry(['merge'])),
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
568
                         ['text0', 'text1', 'text2', 'merge'])
0.1.77 by Martin Pool
New Weave.get_included() does transitive expansion
569
944 by Martin Pool
- refactor member names in Weave code
570
        self.log('k._weave=' + pformat(k._weave))
0.1.64 by Martin Pool
Add test for merging versions
571
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
572
        self.check_read_write(k)
0.1.65 by Martin Pool
Add Weave.merge_iter to get automerged lines
573
574
0.1.95 by Martin Pool
- preliminary merge conflict detection
575
class Conflicts(TestBase):
576
    """Test detection of conflicting regions during a merge.
577
578
    A base version is inserted, then two descendents try to
579
    insert different lines in the same place.  These should be
580
    reported as a possible conflict and forwarded to the user."""
581
    def runTest(self):
582
        return  # NOT RUN
583
        k = Weave()
584
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
585
        k.add_lines([], ['aaa', 'bbb'])
586
        k.add_lines([0], ['aaa', '111', 'bbb'])
587
        k.add_lines([1], ['aaa', '222', 'bbb'])
0.1.95 by Martin Pool
- preliminary merge conflict detection
588
589
        merged = k.merge([1, 2])
590
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
591
        self.assertEqual([[['aaa']],
0.1.95 by Martin Pool
- preliminary merge conflict detection
592
                           [['111'], ['222']],
593
                           [['bbb']]])
594
595
596
class NonConflict(TestBase):
597
    """Two descendants insert compatible changes.
598
599
    No conflict should be reported."""
600
    def runTest(self):
601
        return  # NOT RUN
602
        k = Weave()
603
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
604
        k.add_lines([], ['aaa', 'bbb'])
605
        k.add_lines([0], ['111', 'aaa', 'ccc', 'bbb'])
606
        k.add_lines([1], ['aaa', 'ccc', 'bbb', '222'])
0.1.95 by Martin Pool
- preliminary merge conflict detection
607
608
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
609
class Khayyam(TestBase):
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
610
    """Test changes to multi-line texts, and read/write"""
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
611
612
    def test_multi_line_merge(self):
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
613
        rawtexts = [
614
            """A Book of Verses underneath the Bough,
615
            A Jug of Wine, a Loaf of Bread, -- and Thou
616
            Beside me singing in the Wilderness --
617
            Oh, Wilderness were Paradise enow!""",
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
618
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
619
            """A Book of Verses underneath the Bough,
620
            A Jug of Wine, a Loaf of Bread, -- and Thou
621
            Beside me singing in the Wilderness --
622
            Oh, Wilderness were Paradise now!""",
0.1.59 by Martin Pool
More modification tests
623
624
            """A Book of poems underneath the tree,
625
            A Jug of Wine, a Loaf of Bread,
626
            and Thou
627
            Beside me singing in the Wilderness --
628
            Oh, Wilderness were Paradise now!
629
630
            -- O. Khayyam""",
631
632
            """A Book of Verses underneath the Bough,
633
            A Jug of Wine, a Loaf of Bread,
634
            and Thou
635
            Beside me singing in the Wilderness --
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
636
            Oh, Wilderness were Paradise now!""",
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
637
            ]
638
        texts = [[l.strip() for l in t.split('\n')] for t in rawtexts]
639
640
        k = Weave()
641
        parents = set()
1083 by Martin Pool
- add space to store revision-id in weave files
642
        i = 0
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
643
        for t in texts:
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
644
            ver = k.add_lines('text%d' % i,
1083 by Martin Pool
- add space to store revision-id in weave files
645
                        list(parents), t)
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
646
            parents.add('text%d' % i)
1083 by Martin Pool
- add space to store revision-id in weave files
647
            i += 1
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
648
944 by Martin Pool
- refactor member names in Weave code
649
        self.log("k._weave=" + pformat(k._weave))
0.1.59 by Martin Pool
More modification tests
650
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
651
        for i, t in enumerate(texts):
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
652
            self.assertEqual(k.get_lines(i), t)
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
653
0.1.75 by Martin Pool
Remove VerInfo class; just store sets directly in the list of
654
        self.check_read_write(k)
0.1.57 by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously
655
656
1393.1.48 by Martin Pool
- Add stub Weave.join() method
657
class JoinWeavesTests(TestBase):
5582.10.32 by Jelmer Vernooij
Cleanups.
658
1393.1.50 by Martin Pool
- more development of Weave.join()
659
    def setUp(self):
660
        super(JoinWeavesTests, self).setUp()
661
        self.weave1 = Weave()
662
        self.lines1 = ['hello\n']
663
        self.lines3 = ['hello\n', 'cruel\n', 'world\n']
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
664
        self.weave1.add_lines('v1', [], self.lines1)
665
        self.weave1.add_lines('v2', ['v1'], ['hello\n', 'world\n'])
666
        self.weave1.add_lines('v3', ['v2'], self.lines3)
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
667
668
    def test_written_detection(self):
1185.50.29 by John Arbash Meinel
Whitespace and other formatting cleanups suggested by Robert.
669
        # Test detection of weave file corruption.
670
        #
671
        # Make sure that we can detect if a weave file has
672
        # been corrupted. This doesn't test all forms of corruption,
673
        # but it at least helps verify the data you get, is what you want.
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
674
        from cStringIO import StringIO
675
676
        w = Weave()
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
677
        w.add_lines('v1', [], ['hello\n'])
678
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
679
680
        tmpf = StringIO()
681
        write_weave(w, tmpf)
682
683
        # Because we are corrupting, we need to make sure we have the exact text
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
684
        self.assertEqual('# bzr weave file v5\n'
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
685
                          'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
686
                          'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
687
                          'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n',
688
                          tmpf.getvalue())
689
690
        # Change a single letter
691
        tmpf = StringIO('# bzr weave file v5\n'
692
                        'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
693
                        'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
694
                        'w\n{ 0\n. hello\n}\n{ 1\n. There\n}\nW\n')
695
696
        w = read_weave(tmpf)
697
698
        self.assertEqual('hello\n', w.get_text('v1'))
5582.9.20 by Jelmer Vernooij
remove some of the weave changes.
699
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
700
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
701
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
702
703
        # Change the sha checksum
704
        tmpf = StringIO('# bzr weave file v5\n'
705
                        'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
706
                        'i 0\n1 f0f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
707
                        'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n')
708
709
        w = read_weave(tmpf)
710
711
        self.assertEqual('hello\n', w.get_text('v1'))
5582.9.20 by Jelmer Vernooij
remove some of the weave changes.
712
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
713
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
714
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
715
716
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
717
class TestWeave(TestCase):
718
719
    def test_allow_reserved_false(self):
720
        w = Weave('name', allow_reserved=False)
721
        # Add lines is checked at the WeaveFile level, not at the Weave level
722
        w.add_lines('name:', [], TEXT_1)
723
        # But get_lines is checked at this level
724
        self.assertRaises(errors.ReservedId, w.get_lines, 'name:')
725
726
    def test_allow_reserved_true(self):
727
        w = Weave('name', allow_reserved=True)
728
        w.add_lines('name:', [], TEXT_1)
729
        self.assertEqual(TEXT_1, w.get_lines('name:'))
730
731
1551.3.11 by Aaron Bentley
Merge from Robert
732
class InstrumentedWeave(Weave):
733
    """Keep track of how many times functions are called."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
734
1551.3.11 by Aaron Bentley
Merge from Robert
735
    def __init__(self, weave_name=None):
736
        self._extract_count = 0
737
        Weave.__init__(self, weave_name=weave_name)
738
739
    def _extract(self, versions):
740
        self._extract_count += 1
741
        return Weave._extract(self, versions)
742
743
1616.1.18 by Martin Pool
(weave-merge) don't treat killed-both lines as points of agreement;
744
class TestNeedsReweave(TestCase):
1563.2.24 by Robert Collins
Make join cheaper for compatibly inconsistent parents.
745
    """Internal corner cases for when reweave is needed."""
746
747
    def test_compatible_parents(self):
748
        w1 = Weave('a')
749
        my_parents = set([1, 2, 3])
750
        # subsets are ok
751
        self.assertTrue(w1._compatible_parents(my_parents, set([3])))
752
        # same sets
753
        self.assertTrue(w1._compatible_parents(my_parents, set(my_parents)))
754
        # same empty corner case
755
        self.assertTrue(w1._compatible_parents(set(), set()))
756
        # other cannot contain stuff my_parents does not
757
        self.assertFalse(w1._compatible_parents(set(), set([1])))
758
        self.assertFalse(w1._compatible_parents(my_parents, set([1, 2, 3, 4])))
759
        self.assertFalse(w1._compatible_parents(my_parents, set([4])))
2024.1.1 by John Arbash Meinel
When a weave file is empty, we should get WeaveFormatError, not StopIteration
760
761
762
class TestWeaveFile(TestCaseInTempDir):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
763
2024.1.1 by John Arbash Meinel
When a weave file is empty, we should get WeaveFormatError, not StopIteration
764
    def test_empty_file(self):
765
        f = open('empty.weave', 'wb+')
766
        try:
5582.9.20 by Jelmer Vernooij
remove some of the weave changes.
767
            self.assertRaises(errors.WeaveFormatError,
768
                              read_weave, f)
2024.1.1 by John Arbash Meinel
When a weave file is empty, we should get WeaveFormatError, not StopIteration
769
        finally:
770
            f.close()