/brz/remove-bazaar

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