/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
1
# Copyright (C) 2005-2013, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
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
#
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
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
#
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
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.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
16
6973.7.10 by Jelmer Vernooij
More fixes.
17
import bz2
18
from io import BytesIO
1711.7.27 by John Arbash Meinel
Investigating why test_bundle fails, something isn't transmitting properly.
19
import os
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
20
import sys
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from .. import (
4241.14.13 by Vincent Ladeuil
Some more cleanup.
23
    diff,
1996.3.20 by John Arbash Meinel
[merge] bzr.dev 2063
24
    errors,
4241.14.13 by Vincent Ladeuil
Some more cleanup.
25
    merge,
3638.3.2 by Vincent Ladeuil
Fix all calls to tempfile.mkdtemp to osutils.mkdtemp.
26
    osutils,
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
27
    revision as _mod_revision,
4241.14.13 by Vincent Ladeuil
Some more cleanup.
28
    tests,
1910.2.64 by Aaron Bentley
Changes from review
29
    treebuilder,
30
    )
6670.4.1 by Jelmer Vernooij
Update imports.
31
from ..bzr import (
32
    bzrdir,
33
    inventory,
34
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
35
from ..bundle.apply_bundle import install_bundle, merge_bundle
36
from ..bundle.bundle_data import BundleTree
37
from ..bundle.serializer import write_bundle, read_bundle, v09, v4
38
from ..bundle.serializer.v08 import BundleSerializerV08
39
from ..bundle.serializer.v09 import BundleSerializerV09
40
from ..bundle.serializer.v4 import BundleSerializerV4
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
41
from ..bzr import knitrepo
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
42
from . import (
6206.1.9 by Vincent Ladeuil
Simpler fix for test_smart_server_connection_reset re-using more of the existing test server infrastructure.
43
    features,
44
    test_commit,
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
45
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
46
from ..transform import TreeTransform
7325.1.2 by Jelmer Vernooij
Fix import.
47
from ..tree import find_previous_path
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
48
1185.82.90 by Aaron Bentley
Reorganized test suite
49
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
50
def get_text(vf, key):
51
    """Get the fulltext for a given revision id that is present in the vf"""
52
    stream = vf.get_record_stream([key], 'unordered', True)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
53
    record = next(stream)
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
54
    return record.get_bytes_as('fulltext')
55
56
57
def get_inventory_text(repo, revision_id):
58
    """Get the fulltext for the inventory at revision id"""
7141.7.3 by Jelmer Vernooij
Fix some bundle tests.
59
    with repo.lock_read():
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
60
        return get_text(repo.inventories, (revision_id,))
61
62
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
63
class MockTree(object):
5837.2.5 by Jelmer Vernooij
Fix two warnings.
64
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
65
    def __init__(self):
6670.4.3 by Jelmer Vernooij
Fix more imports.
66
        from ..bzr.inventory import InventoryDirectory, ROOT_ID
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
67
        object.__init__(self)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
68
        self.paths = {ROOT_ID: ""}
69
        self.ids = {"": ROOT_ID}
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
70
        self.contents = {}
1731.1.4 by Aaron Bentley
merge from bzr.dev
71
        self.root = InventoryDirectory(ROOT_ID, '', None)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
72
7143.15.2 by Jelmer Vernooij
Run autopep8.
73
    inventory = property(lambda x: x)
74
    root_inventory = property(lambda x: x)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
75
6405.2.10 by Jelmer Vernooij
Fix more tests.
76
    def get_root_id(self):
77
        return self.root.file_id
78
5837.2.5 by Jelmer Vernooij
Fix two warnings.
79
    def all_file_ids(self):
80
        return set(self.paths.keys())
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
81
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
82
    def all_versioned_paths(self):
83
        return set(self.paths.values())
84
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
85
    def is_executable(self, path):
6445.2.6 by Jelmer Vernooij
Review feedback.
86
        # Not all the files are executable.
6405.2.9 by Jelmer Vernooij
More test fixes.
87
        return False
88
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
89
    def __getitem__(self, file_id):
90
        if file_id == self.root.file_id:
91
            return self.root
92
        else:
93
            return self.make_entry(file_id, self.paths[file_id])
94
7141.7.3 by Jelmer Vernooij
Fix some bundle tests.
95
    def get_entry_by_path(self, path):
96
        return self[self.path2id(path)]
97
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
98
    def parent_id(self, file_id):
1711.7.27 by John Arbash Meinel
Investigating why test_bundle fails, something isn't transmitting properly.
99
        parent_dir = os.path.dirname(self.paths[file_id])
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
100
        if parent_dir == "":
101
            return None
102
        return self.ids[parent_dir]
103
104
    def iter_entries(self):
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
105
        for path, file_id in self.ids.items():
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
106
            yield path, self[file_id]
107
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
108
    def kind(self, path):
109
        if path in self.contents:
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
110
            kind = 'file'
111
        else:
112
            kind = 'directory'
113
        return kind
114
115
    def make_entry(self, file_id, path):
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
116
        from ..bzr.inventory import (InventoryFile, InventoryDirectory,
7143.15.2 by Jelmer Vernooij
Run autopep8.
117
                                     InventoryLink)
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
118
        if not isinstance(file_id, bytes):
119
            raise TypeError(file_id)
1711.7.27 by John Arbash Meinel
Investigating why test_bundle fails, something isn't transmitting properly.
120
        name = os.path.basename(path)
7141.7.3 by Jelmer Vernooij
Fix some bundle tests.
121
        kind = self.kind(path)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
122
        parent_id = self.parent_id(file_id)
7141.7.3 by Jelmer Vernooij
Fix some bundle tests.
123
        text_sha_1, text_size = self.contents_stats(path)
0.5.119 by John Arbash Meinel
Recreated the factory. We really need InventoryEntry.create()
124
        if kind == 'directory':
125
            ie = InventoryDirectory(file_id, name, parent_id)
126
        elif kind == 'file':
127
            ie = InventoryFile(file_id, name, parent_id)
5365.2.2 by Andrew Bennetts
Fix test failures for bundles and upgrades.
128
            ie.text_sha1 = text_sha_1
129
            ie.text_size = text_size
0.5.119 by John Arbash Meinel
Recreated the factory. We really need InventoryEntry.create()
130
        elif kind == 'symlink':
131
            ie = InventoryLink(file_id, name, parent_id)
132
        else:
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
133
            raise errors.BzrError('unknown kind %r' % kind)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
134
        return ie
135
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
136
    def add_dir(self, file_id, path):
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
137
        if not isinstance(file_id, bytes):
138
            raise TypeError(file_id)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
139
        self.paths[file_id] = path
140
        self.ids[path] = file_id
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
141
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
142
    def add_file(self, file_id, path, contents):
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
143
        if not isinstance(file_id, bytes):
144
            raise TypeError(file_id)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
145
        self.add_dir(file_id, path)
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
146
        self.contents[path] = contents
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
147
148
    def path2id(self, path):
149
        return self.ids.get(path)
150
151
    def id2path(self, file_id):
152
        return self.paths.get(file_id)
153
154
    def has_id(self, file_id):
155
        return self.id2path(file_id) is not None
156
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
157
    def get_file(self, path):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
158
        result = BytesIO()
6809.4.9 by Jelmer Vernooij
Fix some more tests.
159
        try:
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
160
            result.write(self.contents[path])
6809.4.9 by Jelmer Vernooij
Fix some more tests.
161
        except KeyError:
162
            raise errors.NoSuchFile(path)
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
163
        result.seek(0, 0)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
164
        return result
165
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
166
    def get_file_revision(self, path):
167
        return self.inventory.get_entry_by_path(path).revision
5793.2.6 by Jelmer Vernooij
Add MockTree.get_file_revision.
168
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
169
    def get_file_size(self, path):
7141.7.2 by Jelmer Vernooij
Fix more tests.
170
        return self.inventory.get_entry_by_path(path).text_size
6468.2.8 by Jelmer Vernooij
Fix remaining test.
171
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
172
    def get_file_sha1(self, path, file_id=None):
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
173
        return self.inventory.get_entry_by_path(path).text_sha1
6468.2.8 by Jelmer Vernooij
Fix remaining test.
174
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
175
    def contents_stats(self, path):
176
        if path not in self.contents:
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
177
            return None, None
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
178
        text_sha1 = osutils.sha_file(self.get_file(path))
179
        return text_sha1, len(self.contents[path])
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
180
181
4241.14.13 by Vincent Ladeuil
Some more cleanup.
182
class BTreeTester(tests.TestCase):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
183
    """A simple unittest tester for the BundleTree class."""
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
184
185
    def make_tree_1(self):
186
        mtree = MockTree()
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
187
        mtree.add_dir(b"a", "grandparent")
188
        mtree.add_dir(b"b", "grandparent/parent")
6973.7.10 by Jelmer Vernooij
More fixes.
189
        mtree.add_file(b"c", "grandparent/parent/file", b"Hello\n")
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
190
        mtree.add_dir(b"d", "grandparent/alt_parent")
7141.7.5 by Jelmer Vernooij
Fix test.
191
        return BundleTree(mtree, b''), mtree
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
192
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
193
    def test_renames(self):
194
        """Ensure that file renames have the proper effect on children"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
195
        btree = self.make_tree_1()[0]
196
        self.assertEqual(btree.old_path("grandparent"), "grandparent")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
197
        self.assertEqual(btree.old_path("grandparent/parent"),
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
198
                         "grandparent/parent")
199
        self.assertEqual(btree.old_path("grandparent/parent/file"),
200
                         "grandparent/parent/file")
201
6855.4.1 by Jelmer Vernooij
Yet more bees.
202
        self.assertEqual(btree.id2path(b"a"), "grandparent")
203
        self.assertEqual(btree.id2path(b"b"), "grandparent/parent")
204
        self.assertEqual(btree.id2path(b"c"), "grandparent/parent/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
205
6855.4.1 by Jelmer Vernooij
Yet more bees.
206
        self.assertEqual(btree.path2id("grandparent"), b"a")
207
        self.assertEqual(btree.path2id("grandparent/parent"), b"b")
208
        self.assertEqual(btree.path2id("grandparent/parent/file"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
209
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
210
        self.assertIs(btree.path2id("grandparent2"), None)
211
        self.assertIs(btree.path2id("grandparent2/parent"), None)
212
        self.assertIs(btree.path2id("grandparent2/parent/file"), None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
213
214
        btree.note_rename("grandparent", "grandparent2")
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
215
        self.assertIs(btree.old_path("grandparent"), None)
216
        self.assertIs(btree.old_path("grandparent/parent"), None)
217
        self.assertIs(btree.old_path("grandparent/parent/file"), None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
218
6855.4.1 by Jelmer Vernooij
Yet more bees.
219
        self.assertEqual(btree.id2path(b"a"), "grandparent2")
220
        self.assertEqual(btree.id2path(b"b"), "grandparent2/parent")
221
        self.assertEqual(btree.id2path(b"c"), "grandparent2/parent/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
222
6855.4.1 by Jelmer Vernooij
Yet more bees.
223
        self.assertEqual(btree.path2id("grandparent2"), b"a")
224
        self.assertEqual(btree.path2id("grandparent2/parent"), b"b")
225
        self.assertEqual(btree.path2id("grandparent2/parent/file"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
226
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
227
        self.assertTrue(btree.path2id("grandparent") is None)
228
        self.assertTrue(btree.path2id("grandparent/parent") is None)
229
        self.assertTrue(btree.path2id("grandparent/parent/file") is None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
230
231
        btree.note_rename("grandparent/parent", "grandparent2/parent2")
6855.4.1 by Jelmer Vernooij
Yet more bees.
232
        self.assertEqual(btree.id2path(b"a"), "grandparent2")
233
        self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
234
        self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
235
6855.4.1 by Jelmer Vernooij
Yet more bees.
236
        self.assertEqual(btree.path2id("grandparent2"), b"a")
237
        self.assertEqual(btree.path2id("grandparent2/parent2"), b"b")
238
        self.assertEqual(btree.path2id("grandparent2/parent2/file"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
239
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
240
        self.assertTrue(btree.path2id("grandparent2/parent") is None)
241
        self.assertTrue(btree.path2id("grandparent2/parent/file") is None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
242
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
243
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
244
                          "grandparent2/parent2/file2")
6855.4.1 by Jelmer Vernooij
Yet more bees.
245
        self.assertEqual(btree.id2path(b"a"), "grandparent2")
246
        self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
247
        self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file2")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
248
6855.4.1 by Jelmer Vernooij
Yet more bees.
249
        self.assertEqual(btree.path2id("grandparent2"), b"a")
250
        self.assertEqual(btree.path2id("grandparent2/parent2"), b"b")
251
        self.assertEqual(btree.path2id("grandparent2/parent2/file2"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
252
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
253
        self.assertTrue(btree.path2id("grandparent2/parent2/file") is None)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
254
255
    def test_moves(self):
256
        """Ensure that file moves have the proper effect on children"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
257
        btree = self.make_tree_1()[0]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
258
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
259
                          "grandparent/alt_parent/file")
6855.4.1 by Jelmer Vernooij
Yet more bees.
260
        self.assertEqual(btree.id2path(b"c"), "grandparent/alt_parent/file")
261
        self.assertEqual(btree.path2id("grandparent/alt_parent/file"), b"c")
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
262
        self.assertTrue(btree.path2id("grandparent/parent/file") is None)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
263
264
    def unified_diff(self, old, new):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
265
        out = BytesIO()
7045.2.14 by Jelmer Vernooij
Fix some bundle tests.:
266
        diff.internal_diff("old", old, "new", new, out)
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
267
        out.seek(0, 0)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
268
        return out.read()
269
270
    def make_tree_2(self):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
271
        btree = self.make_tree_1()[0]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
272
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
273
                          "grandparent/alt_parent/file")
6855.4.1 by Jelmer Vernooij
Yet more bees.
274
        self.assertTrue(btree.id2path(b"e") is None)
6973.7.10 by Jelmer Vernooij
More fixes.
275
        self.assertFalse(btree.is_versioned("grandparent/parent/file"))
276
        btree.note_id(b"e", "grandparent/parent/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
277
        return btree
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
278
279
    def test_adds(self):
280
        """File/inventory adds"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
281
        btree = self.make_tree_2()
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
282
        add_patch = self.unified_diff([], [b"Extra cheese\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
283
        btree.note_patch("grandparent/parent/file", add_patch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
284
        btree.note_id(b'f', 'grandparent/parent/symlink', kind='symlink')
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
285
        btree.note_target('grandparent/parent/symlink', 'venus')
286
        self.adds_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
287
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
288
    def adds_test(self, btree):
6855.4.1 by Jelmer Vernooij
Yet more bees.
289
        self.assertEqual(btree.id2path(b"e"), "grandparent/parent/file")
290
        self.assertEqual(btree.path2id("grandparent/parent/file"), b"e")
6973.7.10 by Jelmer Vernooij
More fixes.
291
        with btree.get_file("grandparent/parent/file") as f:
292
            self.assertEqual(f.read(), b"Extra cheese\n")
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
293
        self.assertEqual(
294
            btree.get_symlink_target('grandparent/parent/symlink'), 'venus')
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
295
296
    def test_adds2(self):
297
        """File/inventory adds, with patch-compatibile renames"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
298
        btree = self.make_tree_2()
299
        btree.contents_by_id = False
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
300
        add_patch = self.unified_diff([b"Hello\n"], [b"Extra cheese\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
301
        btree.note_patch("grandparent/parent/file", add_patch)
6973.7.10 by Jelmer Vernooij
More fixes.
302
        btree.note_id(b'f', 'grandparent/parent/symlink', kind='symlink')
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
303
        btree.note_target('grandparent/parent/symlink', 'venus')
304
        self.adds_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
305
306
    def make_tree_3(self):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
307
        btree, mtree = self.make_tree_1()
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
308
        mtree.add_file(b"e", "grandparent/parent/topping", b"Anchovies\n")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
309
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
310
                          "grandparent/alt_parent/file")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
311
        btree.note_rename("grandparent/parent/topping",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
312
                          "grandparent/alt_parent/stopping")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
313
        return btree
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
314
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
315
    def get_file_test(self, btree):
6973.7.10 by Jelmer Vernooij
More fixes.
316
        with btree.get_file(btree.id2path(b"e")) as f:
317
            self.assertEqual(f.read(), b"Lemon\n")
318
        with btree.get_file(btree.id2path(b"c")) as f:
319
            self.assertEqual(f.read(), b"Hello\n")
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
320
321
    def test_get_file(self):
322
        """Get file contents"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
323
        btree = self.make_tree_3()
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
324
        mod_patch = self.unified_diff([b"Anchovies\n"], [b"Lemon\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
325
        btree.note_patch("grandparent/alt_parent/stopping", mod_patch)
326
        self.get_file_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
327
328
    def test_get_file2(self):
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
329
        """Get file contents, with patch-compatible renames"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
330
        btree = self.make_tree_3()
331
        btree.contents_by_id = False
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
332
        mod_patch = self.unified_diff([], [b"Lemon\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
333
        btree.note_patch("grandparent/alt_parent/stopping", mod_patch)
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
334
        mod_patch = self.unified_diff([], [b"Hello\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
335
        btree.note_patch("grandparent/alt_parent/file", mod_patch)
336
        self.get_file_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
337
338
    def test_delete(self):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
339
        "Deletion by bundle"
340
        btree = self.make_tree_1()[0]
6973.7.10 by Jelmer Vernooij
More fixes.
341
        with btree.get_file(btree.id2path(b"c")) as f:
342
            self.assertEqual(f.read(), b"Hello\n")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
343
        btree.note_deletion("grandparent/parent/file")
6855.4.1 by Jelmer Vernooij
Yet more bees.
344
        self.assertTrue(btree.id2path(b"c") is None)
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
345
        self.assertFalse(btree.is_versioned("grandparent/parent/file"))
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
346
347
    def sorted_ids(self, tree):
6619.3.18 by Jelmer Vernooij
Run 2to3 idioms fixer.
348
        ids = sorted(tree.all_file_ids())
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
349
        return ids
350
351
    def test_iteration(self):
352
        """Ensure that iteration through ids works properly"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
353
        btree = self.make_tree_1()[0]
1852.6.3 by Robert Collins
Make iter(Tree) consistent for all tree types.
354
        self.assertEqual(self.sorted_ids(btree),
7143.15.2 by Jelmer Vernooij
Run autopep8.
355
                         [inventory.ROOT_ID, b'a', b'b', b'c', b'd'])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
356
        btree.note_deletion("grandparent/parent/file")
6973.7.10 by Jelmer Vernooij
More fixes.
357
        btree.note_id(b"e", "grandparent/alt_parent/fool", kind="directory")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
358
        btree.note_last_changed("grandparent/alt_parent/fool",
1185.82.95 by Aaron Bentley
Restore path-orientation of ChangesetTree
359
                                "revisionidiguess")
1852.6.3 by Robert Collins
Make iter(Tree) consistent for all tree types.
360
        self.assertEqual(self.sorted_ids(btree),
7143.15.2 by Jelmer Vernooij
Run autopep8.
361
                         [inventory.ROOT_ID, b'a', b'b', b'd', b'e'])
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
362
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
363
4241.14.13 by Vincent Ladeuil
Some more cleanup.
364
class BundleTester1(tests.TestCaseWithTransport):
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
365
366
    def test_mismatched_bundle(self):
367
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
368
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
369
        serializer = BundleSerializerV08('0.8')
370
        b = self.make_branch('.', format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
371
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
372
                          b.repository, [], {}, BytesIO())
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
373
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
374
    def test_matched_bundle(self):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
375
        """Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
376
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
377
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
378
        serializer = BundleSerializerV09('0.9')
379
        b = self.make_branch('.', format=format)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
380
        serializer.write(b.repository, [], {}, BytesIO())
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
381
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
382
    def test_mismatched_model(self):
383
        """Try copying a bundle from knit2 to knit1"""
384
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
385
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
386
        source = self.make_branch_and_tree('source', format=format)
6855.4.1 by Jelmer Vernooij
Yet more bees.
387
        source.commit('one', rev_id=b'one-id')
388
        source.commit('two', rev_id=b'two-id')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
389
        text = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
390
        write_bundle(source.branch.repository, b'two-id', b'null:', text,
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
391
                     format='0.9')
392
        text.seek(0)
393
394
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
395
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
396
        target = self.make_branch('target', format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
397
        self.assertRaises(errors.IncompatibleRevision, install_bundle,
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
398
                          target.repository, read_bundle(text))
399
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
400
2520.4.43 by Aaron Bentley
Fix test suite
401
class BundleTester(object):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
402
403
    def bzrdir_format(self):
404
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
405
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
406
        return format
407
408
    def make_branch_and_tree(self, path, format=None):
409
        if format is None:
410
            format = self.bzrdir_format()
4241.14.13 by Vincent Ladeuil
Some more cleanup.
411
        return tests.TestCaseWithTransport.make_branch_and_tree(
412
            self, path, format)
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
413
414
    def make_branch(self, path, format=None):
415
        if format is None:
416
            format = self.bzrdir_format()
4241.14.13 by Vincent Ladeuil
Some more cleanup.
417
        return tests.TestCaseWithTransport.make_branch(self, path, format)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
418
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
419
    def create_bundle_text(self, base_rev_id, rev_id):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
420
        bundle_txt = BytesIO()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
421
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
422
                               bundle_txt, format=self.format)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
423
        bundle_txt.seek(0)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
424
        self.assertEqual(bundle_txt.readline(),
6973.7.10 by Jelmer Vernooij
More fixes.
425
                         b'# Bazaar revision bundle v%s\n' % self.format.encode('ascii'))
426
        self.assertEqual(bundle_txt.readline(), b'#\n')
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
427
1185.82.14 by Aaron Bentley
API updates
428
        rev = self.b1.repository.get_revision(rev_id)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
429
        self.assertEqual(bundle_txt.readline().decode('utf-8'),
430
                         u'# message:\n')
431
        bundle_txt.seek(0)
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
432
        return bundle_txt, rev_ids
433
434
    def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
435
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
436
        Make sure that the text generated is valid, and that it
437
        can be applied against the base, and generate the same information.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
438
439
        :return: The in-memory bundle
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
440
        """
441
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
442
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
443
        # This should also validate the generated bundle
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
444
        bundle = read_bundle(bundle_txt)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
445
        repository = self.b1.repository
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
446
        for bundle_rev in bundle.real_revisions:
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
447
            # These really should have already been checked when we read the
448
            # bundle, since it computes the sha1 hash for the revision, which
449
            # only will match if everything is okay, but lets be explicit about
450
            # it
451
            branch_rev = repository.get_revision(bundle_rev.revision_id)
1185.82.33 by Aaron Bentley
Strengthen tests
452
            for a in ('inventory_sha1', 'revision_id', 'parent_ids',
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
453
                      'timestamp', 'timezone', 'message', 'committer',
1185.82.33 by Aaron Bentley
Strengthen tests
454
                      'parent_ids', 'properties'):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
455
                self.assertEqual(getattr(branch_rev, a),
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
456
                                 getattr(bundle_rev, a))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
457
            self.assertEqual(len(branch_rev.parent_ids),
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
458
                             len(bundle_rev.parent_ids))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
459
        self.assertEqual(rev_ids,
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
460
                         [r.revision_id for r in bundle.real_revisions])
7029.2.1 by Jelmer Vernooij
don't make assumptions about the order in which revision ids are returned by write_bundle.
461
        self.valid_apply_bundle(base_rev_id, bundle, checkout_dir=checkout_dir)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
462
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
463
        return bundle
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
464
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
465
    def get_invalid_bundle(self, base_rev_id, rev_id):
466
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
467
        Munge the text so that it's invalid.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
468
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
469
        :return: The in-memory bundle
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
470
        """
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
471
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
472
        new_text = bundle_txt.getvalue().replace(b'executable:no',
473
                                                 b'executable:yes')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
474
        bundle_txt = BytesIO(new_text)
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
475
        bundle = read_bundle(bundle_txt)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
476
        self.valid_apply_bundle(base_rev_id, bundle)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
477
        return bundle
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
478
1185.82.139 by Aaron Bentley
Raise NotABundle when a non-bundle is supplied
479
    def test_non_bundle(self):
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
480
        self.assertRaises(errors.NotABundle,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
481
                          read_bundle, BytesIO(b'#!/bin/sh\n'))
1185.82.139 by Aaron Bentley
Raise NotABundle when a non-bundle is supplied
482
1793.2.7 by Aaron Bentley
Fix reporting of malformed, (especially, crlf) bundles
483
    def test_malformed(self):
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
484
        self.assertRaises(errors.BadBundle, read_bundle,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
485
                          BytesIO(b'# Bazaar revision bundle v'))
1793.2.7 by Aaron Bentley
Fix reporting of malformed, (especially, crlf) bundles
486
487
    def test_crlf_bundle(self):
1793.2.9 by Aaron Bentley
Don't use assertNotRaises-- instead, catch BadBundle and pass
488
        try:
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
489
            read_bundle(BytesIO(b'# Bazaar revision bundle v0.8\r\n'))
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
490
        except errors.BadBundle:
1793.2.9 by Aaron Bentley
Don't use assertNotRaises-- instead, catch BadBundle and pass
491
            # It is currently permitted for bundles with crlf line endings to
492
            # make read_bundle raise a BadBundle, but this should be fixed.
1793.2.10 by Aaron Bentley
Whitespace/comment fix
493
            # Anything else, especially NotABundle, is an error.
1793.2.9 by Aaron Bentley
Don't use assertNotRaises-- instead, catch BadBundle and pass
494
            pass
495
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
496
    def get_checkout(self, rev_id, checkout_dir=None):
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
497
        """Get a new tree, with the specified revision in it.
498
        """
499
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
500
        if checkout_dir is None:
3638.3.2 by Vincent Ladeuil
Fix all calls to tempfile.mkdtemp to osutils.mkdtemp.
501
            checkout_dir = osutils.mkdtemp(prefix='test-branch-', dir='.')
0.5.89 by John Arbash Meinel
Updating for explicitly defined directories.
502
        else:
503
            if not os.path.exists(checkout_dir):
504
                os.mkdir(checkout_dir)
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
505
        tree = self.make_branch_and_tree(checkout_dir)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
506
        s = BytesIO()
6973.7.8 by Jelmer Vernooij
Fix more tests.
507
        ancestors = write_bundle(self.b1.repository, rev_id, b'null:', s,
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
508
                                 format=self.format)
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
509
        s.seek(0)
6973.7.10 by Jelmer Vernooij
More fixes.
510
        self.assertIsInstance(s.getvalue(), bytes)
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
511
        install_bundle(tree.branch.repository, read_bundle(s))
1185.82.41 by Aaron Bentley
More work on installing changesets
512
        for ancestor in ancestors:
513
            old = self.b1.repository.revision_tree(ancestor)
514
            new = tree.branch.repository.revision_tree(ancestor)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
515
            old.lock_read()
516
            new.lock_read()
517
            try:
518
                # Check that there aren't any inventory level changes
519
                delta = new.changes_from(old)
520
                self.assertFalse(delta.has_changed(),
521
                                 'Revision %s not copied correctly.'
522
                                 % (ancestor,))
523
524
                # Now check that the file contents are all correct
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
525
                for path in old.all_versioned_paths():
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
526
                    try:
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
527
                        old_file = old.get_file(path)
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
528
                    except errors.NoSuchFile:
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
529
                        continue
6809.4.21 by Jelmer Vernooij
Fix long lines.
530
                    self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
531
                        old_file.read(), new.get_file(path).read())
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
532
            finally:
533
                new.unlock()
534
                old.unlock()
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
535
        if not _mod_revision.is_null(rev_id):
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
536
            tree.branch.generate_revision_history(rev_id)
1185.82.44 by Aaron Bentley
Switch to merge_changeset in test suite
537
            tree.update()
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
538
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
1711.7.32 by John Arbash Meinel
Switch from a trailing space to a beginning space, which is supported everywhere.
539
            self.assertFalse(delta.has_changed(),
2255.10.5 by John Arbash Meinel
Fix a small bug when we have a symlink that does not need to be re-read.
540
                             'Working tree has modifications: %s' % delta)
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
541
        return tree
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
542
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
543
    def valid_apply_bundle(self, base_rev_id, info, checkout_dir=None):
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
544
        """Get the base revision, apply the changes, and make
545
        sure everything matches the builtin branch.
546
        """
1185.82.17 by Aaron Bentley
More API updates
547
        to_tree = self.get_checkout(base_rev_id, checkout_dir=checkout_dir)
3146.4.11 by Aaron Bentley
Fix lock errors in bundle tests
548
        to_tree.lock_write()
549
        try:
550
            self._valid_apply_bundle(base_rev_id, info, to_tree)
551
        finally:
552
            to_tree.unlock()
553
554
    def _valid_apply_bundle(self, base_rev_id, info, to_tree):
1908.6.4 by Robert Collins
Update to replaced parent checking api bzrlib/merge.py
555
        original_parents = to_tree.get_parent_ids()
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
556
        repository = to_tree.branch.repository
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
557
        original_parents = to_tree.get_parent_ids()
1185.82.41 by Aaron Bentley
More work on installing changesets
558
        self.assertIs(repository.has_revision(base_rev_id), True)
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
559
        for rev in info.real_revisions:
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
560
            self.assertTrue(not repository.has_revision(rev.revision_id),
561
                            'Revision {%s} present before applying bundle'
562
                            % rev.revision_id)
4241.14.13 by Vincent Ladeuil
Some more cleanup.
563
        merge_bundle(info, to_tree, True, merge.Merge3Merger, False, False)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
564
565
        for rev in info.real_revisions:
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
566
            self.assertTrue(repository.has_revision(rev.revision_id),
567
                            'Missing revision {%s} after applying bundle'
568
                            % rev.revision_id)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
569
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
570
        self.assertTrue(to_tree.branch.repository.has_revision(info.target))
0.5.117 by John Arbash Meinel
Almost there. Just need to track down a few remaining bugs.
571
        # Do we also want to verify that all the texts have been added?
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
572
1908.6.4 by Robert Collins
Update to replaced parent checking api bzrlib/merge.py
573
        self.assertEqual(original_parents + [info.target],
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
574
                         to_tree.get_parent_ids())
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
575
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
576
        rev = info.real_revisions[-1]
1185.82.17 by Aaron Bentley
More API updates
577
        base_tree = self.b1.repository.revision_tree(rev.revision_id)
578
        to_tree = to_tree.branch.repository.revision_tree(rev.revision_id)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
579
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
580
        # TODO: make sure the target tree is identical to base tree
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
581
        #       we might also check the working tree.
582
583
        base_files = list(base_tree.list_files())
584
        to_files = list(to_tree.list_files())
585
        self.assertEqual(len(base_files), len(to_files))
1185.82.66 by Aaron Bentley
Handle new executable files
586
        for base_file, to_file in zip(base_files, to_files):
587
            self.assertEqual(base_file, to_file)
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
588
7143.19.5 by Jelmer Vernooij
Undo removal of kind.
589
        for path, status, kind, entry in base_files:
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
590
            # Check that the meta information is the same
7325.1.1 by Jelmer Vernooij
Get rid of file_id arguments to get_file_sha1.
591
            to_path = find_previous_path(base_tree, to_tree, path)
7143.16.21 by Jelmer Vernooij
Fix regressions.
592
            self.assertEqual(
593
                base_tree.get_file_size(path),
7325.1.1 by Jelmer Vernooij
Get rid of file_id arguments to get_file_sha1.
594
                to_tree.get_file_size(to_path))
7143.16.21 by Jelmer Vernooij
Fix regressions.
595
            self.assertEqual(
7325.1.1 by Jelmer Vernooij
Get rid of file_id arguments to get_file_sha1.
596
                base_tree.get_file_sha1(path),
597
                to_tree.get_file_sha1(to_path))
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
598
            # Check that the contents are the same
599
            # This is pretty expensive
600
            # self.assertEqual(base_tree.get_file(fileid).read(),
601
            #         to_tree.get_file(fileid).read())
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
602
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
603
    def test_bundle(self):
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
604
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.14 by Aaron Bentley
API updates
605
        self.b1 = self.tree1.branch
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
606
6855.3.1 by Jelmer Vernooij
Several more fixes.
607
        self.build_tree_contents([('b1/one', b'one\n')])
6855.4.1 by Jelmer Vernooij
Yet more bees.
608
        self.tree1.add('one', b'one-id')
609
        self.tree1.set_root_id(b'root-id')
610
        self.tree1.commit('add one', rev_id=b'a@cset-0-1')
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
611
6973.7.8 by Jelmer Vernooij
Fix more tests.
612
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-1')
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
613
614
        # Make sure we can handle files with spaces, tabs, other
615
        # bogus characters
0.5.82 by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids
616
        self.build_tree([
7143.15.2 by Jelmer Vernooij
Run autopep8.
617
            'b1/with space.txt', 'b1/dir/', 'b1/dir/filein subdir.c', 'b1/dir/WithCaps.txt', 'b1/dir/ pre space', 'b1/sub/', 'b1/sub/sub/', 'b1/sub/sub/nonempty.txt'
618
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
619
        self.build_tree_contents([('b1/sub/sub/emptyfile.txt', b''),
620
                                  ('b1/dir/nolastnewline.txt', b'bloop')])
1185.82.66 by Aaron Bentley
Handle new executable files
621
        tt = TreeTransform(self.tree1)
6973.7.10 by Jelmer Vernooij
More fixes.
622
        tt.new_file('executable', tt.root, [b'#!/bin/sh\n'], b'exe-1', True)
1185.82.66 by Aaron Bentley
Handle new executable files
623
        tt.apply()
2520.4.84 by Aaron Bentley
Fix heisenbug record-rewriting test
624
        # have to fix length of file-id so that we can predictably rewrite
625
        # a (length-prefixed) record containing it later.
6855.4.1 by Jelmer Vernooij
Yet more bees.
626
        self.tree1.add('with space.txt', b'withspace-id')
1185.82.14 by Aaron Bentley
API updates
627
        self.tree1.add([
7143.15.2 by Jelmer Vernooij
Run autopep8.
628
            'dir', 'dir/filein subdir.c', 'dir/WithCaps.txt', 'dir/ pre space', 'dir/nolastnewline.txt', 'sub', 'sub/sub', 'sub/sub/nonempty.txt', 'sub/sub/emptyfile.txt'
629
            ])
6855.4.1 by Jelmer Vernooij
Yet more bees.
630
        self.tree1.commit('add whitespace', rev_id=b'a@cset-0-2')
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
631
6973.7.8 by Jelmer Vernooij
Fix more tests.
632
        bundle = self.get_valid_bundle(b'a@cset-0-1', b'a@cset-0-2')
0.5.117 by John Arbash Meinel
Almost there. Just need to track down a few remaining bugs.
633
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
634
        # Check a rollup bundle
6973.7.10 by Jelmer Vernooij
More fixes.
635
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-2')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
636
637
        # Now delete entries
1185.82.21 by Aaron Bentley
Stop using deprecated function
638
        self.tree1.remove(
7143.15.2 by Jelmer Vernooij
Run autopep8.
639
            ['sub/sub/nonempty.txt', 'sub/sub/emptyfile.txt', 'sub/sub'
640
             ])
1185.82.68 by Aaron Bentley
Handle execute bit on modified files
641
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
642
        trans_id = tt.trans_id_tree_path('executable')
1185.82.68 by Aaron Bentley
Handle execute bit on modified files
643
        tt.set_executability(False, trans_id)
644
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
645
        self.tree1.commit('removed', rev_id=b'a@cset-0-3')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
646
6973.7.8 by Jelmer Vernooij
Fix more tests.
647
        bundle = self.get_valid_bundle(b'a@cset-0-2', b'a@cset-0-3')
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
648
        self.assertRaises((errors.TestamentMismatch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
649
                           errors.VersionedFileInvalidChecksum,
650
                           errors.BadBundle), self.get_invalid_bundle,
651
                          b'a@cset-0-2', b'a@cset-0-3')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
652
        # Check a rollup bundle
6973.7.8 by Jelmer Vernooij
Fix more tests.
653
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-3')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
654
655
        # Now move the directory
1185.82.19 by Aaron Bentley
More API updates
656
        self.tree1.rename_one('dir', 'sub/dir')
6855.4.1 by Jelmer Vernooij
Yet more bees.
657
        self.tree1.commit('rename dir', rev_id=b'a@cset-0-4')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
658
6973.7.8 by Jelmer Vernooij
Fix more tests.
659
        bundle = self.get_valid_bundle(b'a@cset-0-3', b'a@cset-0-4')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
660
        # Check a rollup bundle
6973.7.8 by Jelmer Vernooij
Fix more tests.
661
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-4')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
662
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
663
        # Modified files
7143.15.2 by Jelmer Vernooij
Run autopep8.
664
        with open('b1/sub/dir/WithCaps.txt', 'ab') as f:
665
            f.write(b'\nAdding some text\n')
666
        with open('b1/sub/dir/ pre space', 'ab') as f:
667
            f.write(
668
                b'\r\nAdding some\r\nDOS format lines\r\n')
669
        with open('b1/sub/dir/nolastnewline.txt', 'ab') as f:
670
            f.write(b'\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
671
        self.tree1.rename_one('sub/dir/ pre space',
1711.7.32 by John Arbash Meinel
Switch from a trailing space to a beginning space, which is supported everywhere.
672
                              'sub/ start space')
6855.4.1 by Jelmer Vernooij
Yet more bees.
673
        self.tree1.commit('Modified files', rev_id=b'a@cset-0-5')
6973.7.8 by Jelmer Vernooij
Fix more tests.
674
        bundle = self.get_valid_bundle(b'a@cset-0-4', b'a@cset-0-5')
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
675
1185.82.70 by Aaron Bentley
Handle renamed files better
676
        self.tree1.rename_one('sub/dir/WithCaps.txt', 'temp')
677
        self.tree1.rename_one('with space.txt', 'WithCaps.txt')
678
        self.tree1.rename_one('temp', 'with space.txt')
6855.4.1 by Jelmer Vernooij
Yet more bees.
679
        self.tree1.commit(u'swap filenames', rev_id=b'a@cset-0-6',
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
680
                          verbose=False)
6973.7.8 by Jelmer Vernooij
Fix more tests.
681
        bundle = self.get_valid_bundle(b'a@cset-0-5', b'a@cset-0-6')
682
        other = self.get_checkout(b'a@cset-0-5')
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
683
        tree1_inv = get_inventory_text(self.tree1.branch.repository,
6973.7.8 by Jelmer Vernooij
Fix more tests.
684
                                       b'a@cset-0-5')
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
685
        tree2_inv = get_inventory_text(other.branch.repository,
6973.7.8 by Jelmer Vernooij
Fix more tests.
686
                                       b'a@cset-0-5')
1910.2.54 by Aaron Bentley
Implement testament format 3 strict
687
        self.assertEqualDiff(tree1_inv, tree2_inv)
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
688
        other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
6855.4.1 by Jelmer Vernooij
Yet more bees.
689
        other.commit('rename file', rev_id=b'a@cset-0-6b')
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
690
        self.tree1.merge_from_branch(other.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
691
        self.tree1.commit(u'Merge', rev_id=b'a@cset-0-7',
1185.82.70 by Aaron Bentley
Handle renamed files better
692
                          verbose=False)
6973.7.8 by Jelmer Vernooij
Fix more tests.
693
        bundle = self.get_valid_bundle(b'a@cset-0-6', b'a@cset-0-7')
1185.82.72 by Aaron Bentley
Always use leftmost base for changesets
694
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
695
    def _test_symlink_bundle(self, link_name, link_target, new_link_target):
6973.7.8 by Jelmer Vernooij
Fix more tests.
696
        link_id = b'link-1'
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
697
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
698
        self.requireFeature(features.SymlinkFeature)
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
699
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.87 by Aaron Bentley
Got symlink adding working
700
        self.b1 = self.tree1.branch
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
701
1185.82.87 by Aaron Bentley
Got symlink adding working
702
        tt = TreeTransform(self.tree1)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
703
        tt.new_symlink(link_name, tt.root, link_target, link_id)
1185.82.87 by Aaron Bentley
Got symlink adding working
704
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
705
        self.tree1.commit('add symlink', rev_id=b'l@cset-0-1')
6973.7.8 by Jelmer Vernooij
Fix more tests.
706
        bundle = self.get_valid_bundle(b'null:', b'l@cset-0-1')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
707
        if getattr(bundle, 'revision_tree', None) is not None:
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
708
            # Not all bundle formats supports revision_tree
6973.7.8 by Jelmer Vernooij
Fix more tests.
709
            bund_tree = bundle.revision_tree(self.b1.repository, b'l@cset-0-1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
710
            self.assertEqual(
711
                link_target, bund_tree.get_symlink_target(link_name))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
712
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
713
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
714
        trans_id = tt.trans_id_tree_path(link_name)
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
715
        tt.adjust_path('link2', tt.root, trans_id)
716
        tt.delete_contents(trans_id)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
717
        tt.create_symlink(new_link_target, trans_id)
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
718
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
719
        self.tree1.commit('rename and change symlink', rev_id=b'l@cset-0-2')
6973.7.8 by Jelmer Vernooij
Fix more tests.
720
        bundle = self.get_valid_bundle(b'l@cset-0-1', b'l@cset-0-2')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
721
        if getattr(bundle, 'revision_tree', None) is not None:
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
722
            # Not all bundle formats supports revision_tree
6973.7.8 by Jelmer Vernooij
Fix more tests.
723
            bund_tree = bundle.revision_tree(self.b1.repository, b'l@cset-0-2')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
724
            self.assertEqual(new_link_target,
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
725
                             bund_tree.get_symlink_target('link2'))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
726
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
727
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
728
        trans_id = tt.trans_id_tree_path('link2')
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
729
        tt.delete_contents(trans_id)
730
        tt.create_symlink('jupiter', trans_id)
731
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
732
        self.tree1.commit('just change symlink target', rev_id=b'l@cset-0-3')
6973.7.8 by Jelmer Vernooij
Fix more tests.
733
        bundle = self.get_valid_bundle(b'l@cset-0-2', b'l@cset-0-3')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
734
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
735
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
736
        trans_id = tt.trans_id_tree_path('link2')
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
737
        tt.delete_contents(trans_id)
738
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
739
        self.tree1.commit('Delete symlink', rev_id=b'l@cset-0-4')
6973.7.8 by Jelmer Vernooij
Fix more tests.
740
        bundle = self.get_valid_bundle(b'l@cset-0-3', b'l@cset-0-4')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
741
742
    def test_symlink_bundle(self):
743
        self._test_symlink_bundle('link', 'bar/foo', 'mars')
744
745
    def test_unicode_symlink_bundle(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
746
        self.requireFeature(features.UnicodeFilenameFeature)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
747
        self._test_symlink_bundle(u'\N{Euro Sign}link',
748
                                  u'bar/\N{Euro Sign}foo',
749
                                  u'mars\N{Euro Sign}')
1185.82.96 by Aaron Bentley
Got first binary test passing
750
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
751
    def test_binary_bundle(self):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
752
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.96 by Aaron Bentley
Got first binary test passing
753
        self.b1 = self.tree1.branch
754
        tt = TreeTransform(self.tree1)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
755
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
756
        # Add
7143.15.2 by Jelmer Vernooij
Run autopep8.
757
        tt.new_file('file', tt.root, [
758
                    b'\x00\n\x00\r\x01\n\x02\r\xff'], b'binary-1')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
759
        tt.new_file('file2', tt.root, [b'\x01\n\x02\r\x03\n\x04\r\xff'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
760
                    b'binary-2')
1185.82.96 by Aaron Bentley
Got first binary test passing
761
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
762
        self.tree1.commit('add binary', rev_id=b'b@cset-0-1')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
763
        self.get_valid_bundle(b'null:', b'b@cset-0-1')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
764
765
        # Delete
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
766
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
767
        trans_id = tt.trans_id_tree_path('file')
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
768
        tt.delete_contents(trans_id)
769
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
770
        self.tree1.commit('delete binary', rev_id=b'b@cset-0-2')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
771
        self.get_valid_bundle(b'b@cset-0-1', b'b@cset-0-2')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
772
773
        # Rename & modify
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
774
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
775
        trans_id = tt.trans_id_tree_path('file2')
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
776
        tt.adjust_path('file3', tt.root, trans_id)
777
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
778
        tt.create_file([b'file\rcontents\x00\n\x00'], trans_id)
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
779
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
780
        self.tree1.commit('rename and modify binary', rev_id=b'b@cset-0-3')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
781
        self.get_valid_bundle(b'b@cset-0-2', b'b@cset-0-3')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
782
783
        # Modify
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
784
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
785
        trans_id = tt.trans_id_tree_path('file3')
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
786
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
787
        tt.create_file([b'\x00file\rcontents'], trans_id)
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
788
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
789
        self.tree1.commit('just modify binary', rev_id=b'b@cset-0-4')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
790
        self.get_valid_bundle(b'b@cset-0-3', b'b@cset-0-4')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
791
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
792
        # Rollup
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
793
        self.get_valid_bundle(b'null:', b'b@cset-0-4')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
794
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
795
    def test_last_modified(self):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
796
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
797
        self.b1 = self.tree1.branch
798
        tt = TreeTransform(self.tree1)
6973.7.10 by Jelmer Vernooij
More fixes.
799
        tt.new_file('file', tt.root, [b'file'], b'file')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
800
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
801
        self.tree1.commit('create file', rev_id=b'a@lmod-0-1')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
802
803
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
804
        trans_id = tt.trans_id_tree_path('file')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
805
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
806
        tt.create_file([b'file2'], trans_id)
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
807
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
808
        self.tree1.commit('modify text', rev_id=b'a@lmod-0-2a')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
809
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
810
        other = self.get_checkout(b'a@lmod-0-1')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
811
        tt = TreeTransform(other)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
812
        trans_id = tt.trans_id_tree_path('file2')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
813
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
814
        tt.create_file([b'file2'], trans_id)
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
815
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
816
        other.commit('modify text in another tree', rev_id=b'a@lmod-0-2b')
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
817
        self.tree1.merge_from_branch(other.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
818
        self.tree1.commit(u'Merge', rev_id=b'a@lmod-0-3',
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
819
                          verbose=False)
6855.4.1 by Jelmer Vernooij
Yet more bees.
820
        self.tree1.commit(u'Merge', rev_id=b'a@lmod-0-4')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
821
        bundle = self.get_valid_bundle(b'a@lmod-0-2a', b'a@lmod-0-4')
1185.84.3 by Aaron Bentley
Hide diffs for old revisions in bundles
822
823
    def test_hide_history(self):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
824
        self.tree1 = self.make_branch_and_tree('b1')
1185.84.3 by Aaron Bentley
Hide diffs for old revisions in bundles
825
        self.b1 = self.tree1.branch
826
7143.15.2 by Jelmer Vernooij
Run autopep8.
827
        with open('b1/one', 'wb') as f:
828
            f.write(b'one\n')
1185.84.3 by Aaron Bentley
Hide diffs for old revisions in bundles
829
        self.tree1.add('one')
6855.4.1 by Jelmer Vernooij
Yet more bees.
830
        self.tree1.commit('add file', rev_id=b'a@cset-0-1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
831
        with open('b1/one', 'wb') as f:
832
            f.write(b'two\n')
6855.4.1 by Jelmer Vernooij
Yet more bees.
833
        self.tree1.commit('modify', rev_id=b'a@cset-0-2')
7143.15.2 by Jelmer Vernooij
Run autopep8.
834
        with open('b1/one', 'wb') as f:
835
            f.write(b'three\n')
6855.4.1 by Jelmer Vernooij
Yet more bees.
836
        self.tree1.commit('modify', rev_id=b'a@cset-0-3')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
837
        bundle_file = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
838
        rev_ids = write_bundle(self.tree1.branch.repository, b'a@cset-0-3',
839
                               b'a@cset-0-1', bundle_file, format=self.format)
840
        self.assertNotContainsRe(bundle_file.getvalue(), b'\btwo\b')
841
        self.assertContainsRe(self.get_raw(bundle_file), b'one')
842
        self.assertContainsRe(self.get_raw(bundle_file), b'three')
2520.4.32 by Aaron Bentley
Fix test case
843
2520.4.75 by Aaron Bentley
Fix traceback on empty bundles.
844
    def test_bundle_same_basis(self):
845
        """Ensure using the basis as the target doesn't cause an error"""
846
        self.tree1 = self.make_branch_and_tree('b1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
847
        self.tree1.commit('add file', rev_id=b'a@cset-0-1')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
848
        bundle_file = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
849
        rev_ids = write_bundle(self.tree1.branch.repository, b'a@cset-0-1',
850
                               b'a@cset-0-1', bundle_file)
2520.4.75 by Aaron Bentley
Fix traceback on empty bundles.
851
2520.4.32 by Aaron Bentley
Fix test case
852
    @staticmethod
853
    def get_raw(bundle_file):
854
        return bundle_file.getvalue()
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
855
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
856
    def test_unicode_bundle(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
857
        self.requireFeature(features.UnicodeFilenameFeature)
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
858
        # Handle international characters
859
        os.mkdir('b1')
4241.14.13 by Vincent Ladeuil
Some more cleanup.
860
        f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
861
862
        self.tree1 = self.make_branch_and_tree('b1')
863
        self.b1 = self.tree1.branch
864
865
        f.write((u'A file\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
866
                 u'With international man of mystery\n'
867
                 u'William Dod\xe9\n').encode('utf-8'))
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
868
        f.close()
869
6855.4.1 by Jelmer Vernooij
Yet more bees.
870
        self.tree1.add([u'with Dod\N{Euro Sign}'], [b'withdod-id'])
2386.1.1 by John Arbash Meinel
Update test_unicode_bundle, since we know how it fails on Mac OSX
871
        self.tree1.commit(u'i18n commit from William Dod\xe9',
6855.4.1 by Jelmer Vernooij
Yet more bees.
872
                          rev_id=b'i18n-1', committer=u'William Dod\xe9')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
873
874
        # Add
6973.7.10 by Jelmer Vernooij
More fixes.
875
        bundle = self.get_valid_bundle(b'null:', b'i18n-1')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
876
877
        # Modified
3638.3.18 by Vincent Ladeuil
Fixed as per jam's review.
878
        f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
879
        f.write(u'Modified \xb5\n'.encode('utf8'))
880
        f.close()
6855.4.1 by Jelmer Vernooij
Yet more bees.
881
        self.tree1.commit(u'modified', rev_id=b'i18n-2')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
882
6973.7.10 by Jelmer Vernooij
More fixes.
883
        bundle = self.get_valid_bundle(b'i18n-1', b'i18n-2')
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
884
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
885
        # Renamed
3638.3.18 by Vincent Ladeuil
Fixed as per jam's review.
886
        self.tree1.rename_one(u'with Dod\N{Euro Sign}', u'B\N{Euro Sign}gfors')
6855.4.1 by Jelmer Vernooij
Yet more bees.
887
        self.tree1.commit(u'renamed, the new i18n man', rev_id=b'i18n-3',
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
888
                          committer=u'Erik B\xe5gfors')
889
6973.7.10 by Jelmer Vernooij
More fixes.
890
        bundle = self.get_valid_bundle(b'i18n-2', b'i18n-3')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
891
892
        # Removed
3638.3.18 by Vincent Ladeuil
Fixed as per jam's review.
893
        self.tree1.remove([u'B\N{Euro Sign}gfors'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
894
        self.tree1.commit(u'removed', rev_id=b'i18n-4')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
895
6973.7.10 by Jelmer Vernooij
More fixes.
896
        bundle = self.get_valid_bundle(b'i18n-3', b'i18n-4')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
897
898
        # Rollup
6973.7.10 by Jelmer Vernooij
More fixes.
899
        bundle = self.get_valid_bundle(b'null:', b'i18n-4')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
900
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
901
    def test_whitespace_bundle(self):
902
        if sys.platform in ('win32', 'cygwin'):
4241.14.13 by Vincent Ladeuil
Some more cleanup.
903
            raise tests.TestSkipped('Windows doesn\'t support filenames'
904
                                    ' with tabs or trailing spaces')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
905
        self.tree1 = self.make_branch_and_tree('b1')
906
        self.b1 = self.tree1.branch
907
908
        self.build_tree(['b1/trailing space '])
909
        self.tree1.add(['trailing space '])
910
        # TODO: jam 20060701 Check for handling files with '\t' characters
911
        #       once we actually support them
912
913
        # Added
6855.4.1 by Jelmer Vernooij
Yet more bees.
914
        self.tree1.commit('funky whitespace', rev_id=b'white-1')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
915
6973.7.10 by Jelmer Vernooij
More fixes.
916
        bundle = self.get_valid_bundle(b'null:', b'white-1')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
917
918
        # Modified
7143.15.2 by Jelmer Vernooij
Run autopep8.
919
        with open('b1/trailing space ', 'ab') as f:
920
            f.write(b'add some text\n')
6855.4.1 by Jelmer Vernooij
Yet more bees.
921
        self.tree1.commit('add text', rev_id=b'white-2')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
922
6973.7.10 by Jelmer Vernooij
More fixes.
923
        bundle = self.get_valid_bundle(b'white-1', b'white-2')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
924
925
        # Renamed
926
        self.tree1.rename_one('trailing space ', ' start and end space ')
6855.4.1 by Jelmer Vernooij
Yet more bees.
927
        self.tree1.commit('rename', rev_id=b'white-3')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
928
6973.7.10 by Jelmer Vernooij
More fixes.
929
        bundle = self.get_valid_bundle(b'white-2', b'white-3')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
930
931
        # Removed
932
        self.tree1.remove([' start and end space '])
6855.4.1 by Jelmer Vernooij
Yet more bees.
933
        self.tree1.commit('removed', rev_id=b'white-4')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
934
6973.7.10 by Jelmer Vernooij
More fixes.
935
        bundle = self.get_valid_bundle(b'white-3', b'white-4')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
936
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
937
        # Now test a complet roll-up
6973.7.10 by Jelmer Vernooij
More fixes.
938
        bundle = self.get_valid_bundle(b'null:', b'white-4')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
939
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
940
    def test_alt_timezone_bundle(self):
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
941
        self.tree1 = self.make_branch_and_memory_tree('b1')
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
942
        self.b1 = self.tree1.branch
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
943
        builder = treebuilder.TreeBuilder()
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
944
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
945
        self.tree1.lock_write()
946
        builder.start_tree(self.tree1)
947
        builder.build(['newfile'])
948
        builder.finish_tree()
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
949
950
        # Asia/Colombo offset = 5 hours 30 minutes
6855.4.1 by Jelmer Vernooij
Yet more bees.
951
        self.tree1.commit('non-hour offset timezone', rev_id=b'tz-1',
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
952
                          timezone=19800, timestamp=1152544886.0)
953
6973.7.10 by Jelmer Vernooij
More fixes.
954
        bundle = self.get_valid_bundle(b'null:', b'tz-1')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
955
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
956
        rev = bundle.revisions[0]
957
        self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
958
        self.assertEqual(19800, rev.timezone)
959
        self.assertEqual(1152544886.0, rev.timestamp)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
960
        self.tree1.unlock()
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
961
1910.2.1 by Aaron Bentley
Ensure root entry always has a revision
962
    def test_bundle_root_id(self):
963
        self.tree1 = self.make_branch_and_tree('b1')
964
        self.b1 = self.tree1.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
965
        self.tree1.commit('message', rev_id=b'revid1')
6973.7.8 by Jelmer Vernooij
Fix more tests.
966
        bundle = self.get_valid_bundle(b'null:', b'revid1')
967
        tree = self.get_bundle_tree(bundle, b'revid1')
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
968
        root_revision = tree.get_file_revision(u'')
6973.7.10 by Jelmer Vernooij
More fixes.
969
        self.assertEqual(b'revid1', root_revision)
1910.2.1 by Aaron Bentley
Ensure root entry always has a revision
970
1551.14.9 by Aaron Bentley
rename get_target_revision to install_revisions
971
    def test_install_revisions(self):
1551.14.4 by Aaron Bentley
Change bundle reader and merge directive to both be 'mergeables'
972
        self.tree1 = self.make_branch_and_tree('b1')
973
        self.b1 = self.tree1.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
974
        self.tree1.commit('message', rev_id=b'rev2a')
6973.5.2 by Jelmer Vernooij
Add more bees.
975
        bundle = self.get_valid_bundle(b'null:', b'rev2a')
1551.14.4 by Aaron Bentley
Change bundle reader and merge directive to both be 'mergeables'
976
        branch2 = self.make_branch('b2')
6973.5.2 by Jelmer Vernooij
Add more bees.
977
        self.assertFalse(branch2.repository.has_revision(b'rev2a'))
1551.14.9 by Aaron Bentley
rename get_target_revision to install_revisions
978
        target_revision = bundle.install_revisions(branch2.repository)
6973.5.2 by Jelmer Vernooij
Add more bees.
979
        self.assertTrue(branch2.repository.has_revision(b'rev2a'))
980
        self.assertEqual(b'rev2a', target_revision)
1551.14.4 by Aaron Bentley
Change bundle reader and merge directive to both be 'mergeables'
981
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
982
    def test_bundle_empty_property(self):
983
        """Test serializing revision properties with an empty value."""
984
        tree = self.make_branch_and_memory_tree('tree')
985
        tree.lock_write()
986
        self.addCleanup(tree.unlock)
6973.5.2 by Jelmer Vernooij
Add more bees.
987
        tree.add([''], [b'TREE_ROOT'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
988
        tree.commit('One', revprops={u'one': 'two',
989
                                     u'empty': ''}, rev_id=b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
990
        self.b1 = tree.branch
6973.5.2 by Jelmer Vernooij
Add more bees.
991
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
992
        bundle = read_bundle(bundle_sio)
993
        revision_info = bundle.revisions[0]
6973.5.2 by Jelmer Vernooij
Add more bees.
994
        self.assertEqual(b'rev1', revision_info.revision_id)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
995
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
996
        self.assertEqual({'branch-nick': 'tree', 'empty': '', 'one': 'two'},
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
997
                         rev.properties)
998
999
    def test_bundle_sorted_properties(self):
1000
        """For stability the writer should write properties in sorted order."""
1001
        tree = self.make_branch_and_memory_tree('tree')
1002
        tree.lock_write()
1003
        self.addCleanup(tree.unlock)
1004
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1005
        tree.add([''], [b'TREE_ROOT'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1006
        tree.commit('One', rev_id=b'rev1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1007
                    revprops={u'a': '4', u'b': '3', u'c': '2', u'd': '1'})
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1008
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1009
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1010
        bundle = read_bundle(bundle_sio)
1011
        revision_info = bundle.revisions[0]
6973.7.10 by Jelmer Vernooij
More fixes.
1012
        self.assertEqual(b'rev1', revision_info.revision_id)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1013
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1014
        self.assertEqual({'branch-nick': 'tree', 'a': '4', 'b': '3', 'c': '2',
1015
                          'd': '1'}, rev.properties)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1016
1017
    def test_bundle_unicode_properties(self):
1018
        """We should be able to round trip a non-ascii property."""
1019
        tree = self.make_branch_and_memory_tree('tree')
1020
        tree.lock_write()
1021
        self.addCleanup(tree.unlock)
1022
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1023
        tree.add([''], [b'TREE_ROOT'])
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1024
        # Revisions themselves do not require anything about revision property
1025
        # keys, other than that they are a basestring, and do not contain
1026
        # whitespace.
1027
        # However, Testaments assert than they are str(), and thus should not
1028
        # be Unicode.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1029
        tree.commit('One', rev_id=b'rev1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1030
                    revprops={u'omega': u'\u03a9', u'alpha': u'\u03b1'})
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1031
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1032
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1033
        bundle = read_bundle(bundle_sio)
1034
        revision_info = bundle.revisions[0]
6973.7.10 by Jelmer Vernooij
More fixes.
1035
        self.assertEqual(b'rev1', revision_info.revision_id)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1036
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1037
        self.assertEqual({'branch-nick': 'tree', 'omega': u'\u03a9',
1038
                          'alpha': u'\u03b1'}, rev.properties)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1039
2520.4.43 by Aaron Bentley
Fix test suite
1040
    def test_bundle_with_ghosts(self):
1041
        tree = self.make_branch_and_tree('tree')
1042
        self.b1 = tree.branch
6855.3.1 by Jelmer Vernooij
Several more fixes.
1043
        self.build_tree_contents([('tree/file', b'content1')])
2520.4.43 by Aaron Bentley
Fix test suite
1044
        tree.add(['file'])
1045
        tree.commit('rev1')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1046
        self.build_tree_contents([('tree/file', b'content2')])
1047
        tree.add_parent_tree_id(b'ghost')
1048
        tree.commit('rev2', rev_id=b'rev2')
1049
        bundle = self.get_valid_bundle(b'null:', b'rev2')
2520.4.43 by Aaron Bentley
Fix test suite
1050
2520.4.97 by Aaron Bentley
Hack in support for inventory conversion
1051
    def make_simple_tree(self, format=None):
1052
        tree = self.make_branch_and_tree('b1', format=format)
1053
        self.b1 = tree.branch
1054
        self.build_tree(['b1/file'])
1055
        tree.add('file')
1056
        return tree
1057
1058
    def test_across_serializers(self):
1059
        tree = self.make_simple_tree('knit')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1060
        tree.commit('hello', rev_id=b'rev1')
1061
        tree.commit('hello', rev_id=b'rev2')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1062
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
2520.4.97 by Aaron Bentley
Hack in support for inventory conversion
1063
        repo = self.make_repository('repo', format='dirstate-with-subtree')
1064
        bundle.install_revisions(repo)
6973.7.10 by Jelmer Vernooij
More fixes.
1065
        inv_text = repo._get_inventory_xml(b'rev2')
1066
        self.assertNotContainsRe(inv_text, b'format="5"')
1067
        self.assertContainsRe(inv_text, b'format="7"')
2520.4.99 by Aaron Bentley
Test conversion across models
1068
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1069
    def make_repo_with_installed_revisions(self):
1070
        tree = self.make_simple_tree('knit')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1071
        tree.commit('hello', rev_id=b'rev1')
1072
        tree.commit('hello', rev_id=b'rev2')
6973.5.2 by Jelmer Vernooij
Add more bees.
1073
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1074
        repo = self.make_repository('repo', format='dirstate-with-subtree')
1075
        bundle.install_revisions(repo)
1076
        return repo
1077
2520.4.99 by Aaron Bentley
Test conversion across models
1078
    def test_across_models(self):
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1079
        repo = self.make_repo_with_installed_revisions()
6973.5.2 by Jelmer Vernooij
Add more bees.
1080
        inv = repo.get_inventory(b'rev2')
1081
        self.assertEqual(b'rev2', inv.root.revision)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1082
        root_id = inv.root.file_id
1083
        repo.lock_read()
1084
        self.addCleanup(repo.unlock)
7143.15.2 by Jelmer Vernooij
Run autopep8.
1085
        self.assertEqual({(root_id, b'rev1'): (),
1086
                          (root_id, b'rev2'): ((root_id, b'rev1'),)},
1087
                         repo.texts.get_parent_map([(root_id, b'rev1'), (root_id, b'rev2')]))
2520.4.99 by Aaron Bentley
Test conversion across models
1088
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1089
    def test_inv_hash_across_serializers(self):
1090
        repo = self.make_repo_with_installed_revisions()
6973.5.2 by Jelmer Vernooij
Add more bees.
1091
        recorded_inv_sha1 = repo.get_revision(b'rev2').inventory_sha1
1092
        xml = repo._get_inventory_xml(b'rev2')
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1093
        self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1)
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1094
2520.4.99 by Aaron Bentley
Test conversion across models
1095
    def test_across_models_incompatible(self):
1096
        tree = self.make_simple_tree('dirstate-with-subtree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1097
        tree.commit('hello', rev_id=b'rev1')
1098
        tree.commit('hello', rev_id=b'rev2')
2520.4.99 by Aaron Bentley
Test conversion across models
1099
        try:
6973.7.8 by Jelmer Vernooij
Fix more tests.
1100
            bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
2520.4.99 by Aaron Bentley
Test conversion across models
1101
        except errors.IncompatibleBundleFormat:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1102
            raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
2520.4.99 by Aaron Bentley
Test conversion across models
1103
        repo = self.make_repository('repo', format='knit')
1104
        bundle.install_revisions(repo)
1105
6973.7.8 by Jelmer Vernooij
Fix more tests.
1106
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
2520.4.99 by Aaron Bentley
Test conversion across models
1107
        self.assertRaises(errors.IncompatibleRevision,
1108
                          bundle.install_revisions, repo)
2520.4.97 by Aaron Bentley
Hack in support for inventory conversion
1109
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
1110
    def test_get_merge_request(self):
1111
        tree = self.make_simple_tree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
1112
        tree.commit('hello', rev_id=b'rev1')
1113
        tree.commit('hello', rev_id=b'rev2')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1114
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
1115
        result = bundle.get_merge_request(tree.branch.repository)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1116
        self.assertEqual((None, b'rev1', 'inapplicable'), result)
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
1117
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1118
    def test_with_subtree(self):
1119
        tree = self.make_branch_and_tree('tree',
1120
                                         format='dirstate-with-subtree')
1121
        self.b1 = tree.branch
1122
        subtree = self.make_branch_and_tree('tree/subtree',
1123
                                            format='dirstate-with-subtree')
1124
        tree.add('subtree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1125
        tree.commit('hello', rev_id=b'rev1')
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1126
        try:
6973.7.8 by Jelmer Vernooij
Fix more tests.
1127
            bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1128
        except errors.IncompatibleBundleFormat:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1129
            raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1130
        if isinstance(bundle, v09.BundleInfo09):
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1131
            raise tests.TestSkipped("Format 0.9 doesn't work with subtrees")
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1132
        repo = self.make_repository('repo', format='knit')
1133
        self.assertRaises(errors.IncompatibleRevision,
1134
                          bundle.install_revisions, repo)
1135
        repo2 = self.make_repository('repo2', format='dirstate-with-subtree')
1136
        bundle.install_revisions(repo2)
1137
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1138
    def test_revision_id_with_slash(self):
1139
        self.tree1 = self.make_branch_and_tree('tree')
1140
        self.b1 = self.tree1.branch
1141
        try:
6855.4.1 by Jelmer Vernooij
Yet more bees.
1142
            self.tree1.commit('Revision/id/with/slashes', rev_id=b'rev/id')
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1143
        except ValueError:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1144
            raise tests.TestSkipped(
1145
                "Repository doesn't support revision ids with slashes")
6973.7.8 by Jelmer Vernooij
Fix more tests.
1146
        bundle = self.get_valid_bundle(b'null:', b'rev/id')
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1147
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1148
    def test_skip_file(self):
1149
        """Make sure we don't accidentally write to the wrong versionedfile"""
1150
        self.tree1 = self.make_branch_and_tree('tree')
1151
        self.b1 = self.tree1.branch
1152
        # rev1 is not present in bundle, done by fetch
6855.4.1 by Jelmer Vernooij
Yet more bees.
1153
        self.build_tree_contents([('tree/file2', b'contents1')])
1154
        self.tree1.add('file2', b'file2-id')
1155
        self.tree1.commit('rev1', rev_id=b'reva')
1156
        self.build_tree_contents([('tree/file3', b'contents2')])
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1157
        # rev2 is present in bundle, and done by fetch
1158
        # having file1 in the bunle causes file1's versionedfile to be opened.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1159
        self.tree1.add('file3', b'file3-id')
7058.3.5 by Jelmer Vernooij
Fix flappy skip_file test.
1160
        rev2 = self.tree1.commit('rev2')
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1161
        # Updating file2 should not cause an attempt to add to file1's vf
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1162
        target = self.tree1.controldir.sprout('target').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
1163
        self.build_tree_contents([('tree/file2', b'contents3')])
1164
        self.tree1.commit('rev3', rev_id=b'rev3')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1165
        bundle = self.get_valid_bundle(b'reva', b'rev3')
2520.6.5 by Aaron Bentley
Skip for bundle formats that don't provide get_bundle_reader
1166
        if getattr(bundle, 'get_bundle_reader', None) is None:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1167
            raise tests.TestSkipped('Bundle format cannot provide reader')
7058.3.5 by Jelmer Vernooij
Fix flappy skip_file test.
1168
        file_ids = set(
1169
            (f, r) for b, m, k, r, f in bundle.get_bundle_reader().iter_records()
1170
            if f is not None)
7143.15.2 by Jelmer Vernooij
Run autopep8.
1171
        self.assertEqual(
1172
            {(b'file2-id', b'rev3'), (b'file3-id', rev2)}, file_ids)
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1173
        bundle.install_revisions(target.branch.repository)
1174
2520.4.43 by Aaron Bentley
Fix test suite
1175
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1176
class V08BundleTester(BundleTester, tests.TestCaseWithTransport):
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1177
1178
    format = '0.8'
1179
1180
    def test_bundle_empty_property(self):
1181
        """Test serializing revision properties with an empty value."""
1182
        tree = self.make_branch_and_memory_tree('tree')
1183
        tree.lock_write()
1184
        self.addCleanup(tree.unlock)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1185
        tree.add([''], [b'TREE_ROOT'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
1186
        tree.commit('One', revprops={u'one': 'two',
1187
                                     u'empty': ''}, rev_id=b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1188
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1189
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1190
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1191
                              b'# properties:\n'
1192
                              b'#   branch-nick: tree\n'
1193
                              b'#   empty: \n'
1194
                              b'#   one: two\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1195
                              )
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1196
        bundle = read_bundle(bundle_sio)
1197
        revision_info = bundle.revisions[0]
7045.2.14 by Jelmer Vernooij
Fix some bundle tests.:
1198
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1199
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1200
        self.assertEqual({'branch-nick': 'tree', 'empty': '', 'one': 'two'},
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1201
                         rev.properties)
1202
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1203
    def get_bundle_tree(self, bundle, revision_id):
1204
        repository = self.make_repository('repo')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1205
        return bundle.revision_tree(repository, b'revid1')
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1206
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1207
    def test_bundle_empty_property_alt(self):
2447.1.3 by John Arbash Meinel
Change the default serializer to include a trailing whitespace for empty properties.
1208
        """Test serializing revision properties with an empty value.
1209
1210
        Older readers had a bug when reading an empty property.
1211
        They assumed that all keys ended in ': \n'. However they would write an
1212
        empty value as ':\n'. This tests make sure that all newer bzr versions
1213
        can handle th second form.
1214
        """
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1215
        tree = self.make_branch_and_memory_tree('tree')
1216
        tree.lock_write()
1217
        self.addCleanup(tree.unlock)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1218
        tree.add([''], [b'TREE_ROOT'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
1219
        tree.commit('One', revprops={u'one': 'two',
1220
                                     u'empty': ''}, rev_id=b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1221
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1222
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1223
        txt = bundle_sio.getvalue()
6973.7.10 by Jelmer Vernooij
More fixes.
1224
        loc = txt.find(b'#   empty: ') + len(b'#   empty:')
2447.1.3 by John Arbash Meinel
Change the default serializer to include a trailing whitespace for empty properties.
1225
        # Create a new bundle, which strips the trailing space after empty
7143.15.2 by Jelmer Vernooij
Run autopep8.
1226
        bundle_sio = BytesIO(txt[:loc] + txt[loc + 1:])
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1227
1228
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1229
                              b'# properties:\n'
1230
                              b'#   branch-nick: tree\n'
1231
                              b'#   empty:\n'
1232
                              b'#   one: two\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1233
                              )
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1234
        bundle = read_bundle(bundle_sio)
1235
        revision_info = bundle.revisions[0]
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
1236
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1237
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1238
        self.assertEqual({'branch-nick': 'tree', 'empty': '', 'one': 'two'},
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1239
                         rev.properties)
1240
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1241
    def test_bundle_sorted_properties(self):
1242
        """For stability the writer should write properties in sorted order."""
1243
        tree = self.make_branch_and_memory_tree('tree')
1244
        tree.lock_write()
1245
        self.addCleanup(tree.unlock)
1246
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1247
        tree.add([''], [b'TREE_ROOT'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1248
        tree.commit('One', rev_id=b'rev1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1249
                    revprops={u'a': '4', u'b': '3', u'c': '2', u'd': '1'})
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1250
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1251
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1252
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1253
                              b'# properties:\n'
1254
                              b'#   a: 4\n'
1255
                              b'#   b: 3\n'
1256
                              b'#   branch-nick: tree\n'
1257
                              b'#   c: 2\n'
1258
                              b'#   d: 1\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1259
                              )
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1260
        bundle = read_bundle(bundle_sio)
1261
        revision_info = bundle.revisions[0]
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
1262
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1263
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1264
        self.assertEqual({'branch-nick': 'tree', 'a': '4', 'b': '3', 'c': '2',
1265
                          'd': '1'}, rev.properties)
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1266
1267
    def test_bundle_unicode_properties(self):
1268
        """We should be able to round trip a non-ascii property."""
1269
        tree = self.make_branch_and_memory_tree('tree')
1270
        tree.lock_write()
1271
        self.addCleanup(tree.unlock)
1272
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1273
        tree.add([''], [b'TREE_ROOT'])
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1274
        # Revisions themselves do not require anything about revision property
1275
        # keys, other than that they are a basestring, and do not contain
1276
        # whitespace.
1277
        # However, Testaments assert than they are str(), and thus should not
1278
        # be Unicode.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1279
        tree.commit('One', rev_id=b'rev1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1280
                    revprops={u'omega': u'\u03a9', u'alpha': u'\u03b1'})
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1281
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1282
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1283
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1284
                              b'# properties:\n'
1285
                              b'#   alpha: \xce\xb1\n'
1286
                              b'#   branch-nick: tree\n'
1287
                              b'#   omega: \xce\xa9\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1288
                              )
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1289
        bundle = read_bundle(bundle_sio)
1290
        revision_info = bundle.revisions[0]
6973.7.10 by Jelmer Vernooij
More fixes.
1291
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1292
        rev = revision_info.as_revision()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1293
        self.assertEqual({'branch-nick': 'tree', 'omega': u'\u03a9',
1294
                          'alpha': u'\u03b1'}, rev.properties)
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1295
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1296
1910.2.59 by Aaron Bentley
Test 0.9 bundles for knit format1 and knit format2
1297
class V09BundleKnit2Tester(V08BundleTester):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
1298
1299
    format = '0.9'
1300
1301
    def bzrdir_format(self):
1302
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
1303
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
1304
        return format
1305
1306
1910.2.59 by Aaron Bentley
Test 0.9 bundles for knit format1 and knit format2
1307
class V09BundleKnit1Tester(V08BundleTester):
1308
1309
    format = '0.9'
1310
1311
    def bzrdir_format(self):
1312
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
1313
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.59 by Aaron Bentley
Test 0.9 bundles for knit format1 and knit format2
1314
        return format
1315
1316
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1317
class V4BundleTester(BundleTester, tests.TestCaseWithTransport):
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1318
2520.4.136 by Aaron Bentley
Fix format strings
1319
    format = '4'
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1320
1321
    def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
1322
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1323
        Make sure that the text generated is valid, and that it
1324
        can be applied against the base, and generate the same information.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1325
1326
        :return: The in-memory bundle
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1327
        """
1328
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1329
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1330
        # This should also validate the generated bundle
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1331
        bundle = read_bundle(bundle_txt)
1332
        repository = self.b1.repository
1333
        for bundle_rev in bundle.real_revisions:
1334
            # These really should have already been checked when we read the
1335
            # bundle, since it computes the sha1 hash for the revision, which
1336
            # only will match if everything is okay, but lets be explicit about
1337
            # it
1338
            branch_rev = repository.get_revision(bundle_rev.revision_id)
1339
            for a in ('inventory_sha1', 'revision_id', 'parent_ids',
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1340
                      'timestamp', 'timezone', 'message', 'committer',
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1341
                      'parent_ids', 'properties'):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1342
                self.assertEqual(getattr(branch_rev, a),
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1343
                                 getattr(bundle_rev, a))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1344
            self.assertEqual(len(branch_rev.parent_ids),
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1345
                             len(bundle_rev.parent_ids))
2520.4.29 by Aaron Bentley
Reactivate some testing, fix topo_iter
1346
        self.assertEqual(set(rev_ids),
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
1347
                         {r.revision_id for r in bundle.real_revisions})
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1348
        self.valid_apply_bundle(base_rev_id, bundle,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1349
                                checkout_dir=checkout_dir)
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1350
1351
        return bundle
1352
2520.4.34 by Aaron Bentley
Add signature support
1353
    def get_invalid_bundle(self, base_rev_id, rev_id):
1354
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1355
        Munge the text so that it's invalid.
1356
1357
        :return: The in-memory bundle
1358
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1359
        from ..bundle import serializer
2520.4.34 by Aaron Bentley
Add signature support
1360
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1361
        new_text = self.get_raw(BytesIO(b''.join(bundle_txt)))
6973.7.10 by Jelmer Vernooij
More fixes.
1362
        new_text = new_text.replace(b'<file file_id="exe-1"',
1363
                                    b'<file executable="y" file_id="exe-1"')
1364
        new_text = new_text.replace(b'B260', b'B275')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1365
        bundle_txt = BytesIO()
2520.4.136 by Aaron Bentley
Fix format strings
1366
        bundle_txt.write(serializer._get_bundle_header('4'))
6973.7.5 by Jelmer Vernooij
s/file/open.
1367
        bundle_txt.write(b'\n')
6973.7.10 by Jelmer Vernooij
More fixes.
1368
        bundle_txt.write(bz2.compress(new_text))
2520.4.34 by Aaron Bentley
Add signature support
1369
        bundle_txt.seek(0)
1370
        bundle = read_bundle(bundle_txt)
1371
        self.valid_apply_bundle(base_rev_id, bundle)
1372
        return bundle
1373
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1374
    def create_bundle_text(self, base_rev_id, rev_id):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1375
        bundle_txt = BytesIO()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1376
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1377
                               bundle_txt, format=self.format)
1378
        bundle_txt.seek(0)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1379
        self.assertEqual(bundle_txt.readline(),
6973.7.8 by Jelmer Vernooij
Fix more tests.
1380
                         b'# Bazaar revision bundle v%s\n' % self.format.encode('ascii'))
1381
        self.assertEqual(bundle_txt.readline(), b'#\n')
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1382
        rev = self.b1.repository.get_revision(rev_id)
1383
        bundle_txt.seek(0)
1384
        return bundle_txt, rev_ids
2520.4.4 by Aaron Bentley
Get basis support for a new bundle format in place
1385
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1386
    def get_bundle_tree(self, bundle, revision_id):
1387
        repository = self.make_repository('repo')
1388
        bundle.install_revisions(repository)
1389
        return repository.revision_tree(revision_id)
1390
2520.4.4 by Aaron Bentley
Get basis support for a new bundle format in place
1391
    def test_creation(self):
1392
        tree = self.make_branch_and_tree('tree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1393
        self.build_tree_contents([('tree/file', b'contents1\nstatic\n')])
6973.5.2 by Jelmer Vernooij
Add more bees.
1394
        tree.add('file', b'fileid-2')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1395
        tree.commit('added file', rev_id=b'rev1')
1396
        self.build_tree_contents([('tree/file', b'contents2\nstatic\n')])
1397
        tree.commit('changed file', rev_id=b'rev2')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1398
        s = BytesIO()
2520.4.72 by Aaron Bentley
Rename format to 4alpha
1399
        serializer = BundleSerializerV4('1.0')
7029.2.2 by Jelmer Vernooij
Fix two tests.
1400
        with tree.lock_read():
7143.15.2 by Jelmer Vernooij
Run autopep8.
1401
            serializer.write_bundle(
1402
                tree.branch.repository, b'rev2', b'null:', s)
2520.4.5 by Aaron Bentley
Start work on reading mpbundles
1403
        s.seek(0)
2520.4.6 by Aaron Bentley
Get installation started
1404
        tree2 = self.make_branch_and_tree('target')
1405
        target_repo = tree2.branch.repository
1406
        install_bundle(target_repo, serializer.read(s))
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1407
        target_repo.lock_read()
1408
        self.addCleanup(target_repo.unlock)
4202.1.1 by John Arbash Meinel
Update Repository.iter_files_bytes() to return an iterable of bytestrings.
1409
        # Turn the 'iterators_of_bytes' back into simple strings for comparison
6973.7.10 by Jelmer Vernooij
More fixes.
1410
        repo_texts = dict((i, b''.join(content)) for i, content
4202.1.1 by John Arbash Meinel
Update Repository.iter_files_bytes() to return an iterable of bytestrings.
1411
                          in target_repo.iter_files_bytes(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1412
            [(b'fileid-2', b'rev1', '1'),
1413
             (b'fileid-2', b'rev2', '2')]))
1414
        self.assertEqual({'1': b'contents1\nstatic\n',
1415
                          '2': b'contents2\nstatic\n'},
4202.1.1 by John Arbash Meinel
Update Repository.iter_files_bytes() to return an iterable of bytestrings.
1416
                         repo_texts)
6973.5.2 by Jelmer Vernooij
Add more bees.
1417
        rtree = target_repo.revision_tree(b'rev2')
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1418
        inventory_vf = target_repo.inventories
1419
        # If the inventory store has a graph, it must match the revision graph.
1420
        self.assertSubset(
6973.5.2 by Jelmer Vernooij
Add more bees.
1421
            [inventory_vf.get_parent_map([(b'rev2',)])[(b'rev2',)]],
1422
            [None, ((b'rev1',),)])
2520.4.10 by Aaron Bentley
Enable installation of revisions
1423
        self.assertEqual('changed file',
6973.5.2 by Jelmer Vernooij
Add more bees.
1424
                         target_repo.get_revision(b'rev2').message)
2520.4.6 by Aaron Bentley
Get installation started
1425
2520.4.32 by Aaron Bentley
Fix test case
1426
    @staticmethod
1427
    def get_raw(bundle_file):
1428
        bundle_file.seek(0)
2520.4.70 by Aaron Bentley
Yank patch-handling functionality
1429
        line = bundle_file.readline()
1430
        line = bundle_file.readline()
2520.4.32 by Aaron Bentley
Fix test case
1431
        lines = bundle_file.readlines()
6973.7.10 by Jelmer Vernooij
More fixes.
1432
        return bz2.decompress(b''.join(lines))
2520.4.32 by Aaron Bentley
Fix test case
1433
2520.4.34 by Aaron Bentley
Add signature support
1434
    def test_copy_signatures(self):
1435
        tree_a = self.make_branch_and_tree('tree_a')
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1436
        import breezy.gpg
1437
        import breezy.commit as commit
1438
        oldstrategy = breezy.gpg.GPGStrategy
2520.4.34 by Aaron Bentley
Add signature support
1439
        branch = tree_a.branch
1440
        repo_a = branch.repository
6855.4.1 by Jelmer Vernooij
Yet more bees.
1441
        tree_a.commit("base", allow_pointless=True, rev_id=b'A')
6973.7.10 by Jelmer Vernooij
More fixes.
1442
        self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
2520.4.34 by Aaron Bentley
Add signature support
1443
        try:
7206.4.1 by Jelmer Vernooij
Move breezy.testament to breezy.bzr.testament.
1444
            from ..bzr.testament import Testament
2520.4.34 by Aaron Bentley
Add signature support
1445
            # monkey patch gpg signing mechanism
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1446
            breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
6393.1.1 by Vincent Ladeuil
Provides MemoryStack to simplify configuration setup in tests
1447
            new_config = test_commit.MustSignConfig()
6351.3.3 by Jelmer Vernooij
Convert more stuff to use config stacks.
1448
            commit.Commit(config_stack=new_config).commit(message="base",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1449
                                                          allow_pointless=True,
1450
                                                          rev_id=b'B',
1451
                                                          working_tree=tree_a)
1452
2520.4.34 by Aaron Bentley
Add signature support
1453
            def sign(text):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1454
                return breezy.gpg.LoopbackGPGStrategy(None).sign(text)
6973.7.10 by Jelmer Vernooij
More fixes.
1455
            self.assertTrue(repo_a.has_signature_for_revision_id(b'B'))
2520.4.34 by Aaron Bentley
Add signature support
1456
        finally:
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1457
            breezy.gpg.GPGStrategy = oldstrategy
2520.4.34 by Aaron Bentley
Add signature support
1458
        tree_b = self.make_branch_and_tree('tree_b')
1459
        repo_b = tree_b.branch.repository
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1460
        s = BytesIO()
2520.4.136 by Aaron Bentley
Fix format strings
1461
        serializer = BundleSerializerV4('4')
7029.2.2 by Jelmer Vernooij
Fix two tests.
1462
        with tree_a.lock_read():
7143.15.2 by Jelmer Vernooij
Run autopep8.
1463
            serializer.write_bundle(
1464
                tree_a.branch.repository, b'B', b'null:', s)
2520.4.34 by Aaron Bentley
Add signature support
1465
        s.seek(0)
1466
        install_bundle(repo_b, serializer.read(s))
6973.7.10 by Jelmer Vernooij
More fixes.
1467
        self.assertTrue(repo_b.has_signature_for_revision_id(b'B'))
1468
        self.assertEqual(repo_b.get_signature_text(b'B'),
1469
                         repo_a.get_signature_text(b'B'))
2520.4.100 by Aaron Bentley
Fix repeat signature installs
1470
        s.seek(0)
1471
        # ensure repeat installs are harmless
1472
        install_bundle(repo_b, serializer.read(s))
2520.4.34 by Aaron Bentley
Add signature support
1473
2520.4.4 by Aaron Bentley
Get basis support for a new bundle format in place
1474
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1475
class V4_2aBundleTester(V4BundleTester):
1476
1477
    def bzrdir_format(self):
1478
        return '2a'
1479
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1480
    def get_invalid_bundle(self, base_rev_id, rev_id):
1481
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1482
        Munge the text so that it's invalid.
1483
1484
        :return: The in-memory bundle
1485
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1486
        from ..bundle import serializer
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1487
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1488
        new_text = self.get_raw(BytesIO(b''.join(bundle_txt)))
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
1489
        # We are going to be replacing some text to set the executable bit on a
1490
        # file. Make sure the text replacement actually works correctly.
6973.7.10 by Jelmer Vernooij
More fixes.
1491
        self.assertContainsRe(new_text, b'(?m)B244\n\ni 1\n<inventory')
1492
        new_text = new_text.replace(b'<file file_id="exe-1"',
1493
                                    b'<file executable="y" file_id="exe-1"')
1494
        new_text = new_text.replace(b'B244', b'B259')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1495
        bundle_txt = BytesIO()
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1496
        bundle_txt.write(serializer._get_bundle_header('4'))
6973.7.5 by Jelmer Vernooij
s/file/open.
1497
        bundle_txt.write(b'\n')
6973.7.10 by Jelmer Vernooij
More fixes.
1498
        bundle_txt.write(bz2.compress(new_text))
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1499
        bundle_txt.seek(0)
1500
        bundle = read_bundle(bundle_txt)
1501
        self.valid_apply_bundle(base_rev_id, bundle)
1502
        return bundle
1503
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1504
    def make_merged_branch(self):
4543.2.6 by John Arbash Meinel
redefinning self.bzrdir_format() automatically sets the default format.
1505
        builder = self.make_branch_builder('source')
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1506
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1507
        builder.build_snapshot(None, [
6973.7.10 by Jelmer Vernooij
More fixes.
1508
            ('add', ('', b'root-id', 'directory', None)),
1509
            ('add', ('file', b'file-id', 'file', b'original content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1510
            ], revision_id=b'a@cset-0-1')
6973.7.10 by Jelmer Vernooij
More fixes.
1511
        builder.build_snapshot([b'a@cset-0-1'], [
1512
            ('modify', ('file', b'new-content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1513
            ], revision_id=b'a@cset-0-2a')
6973.7.10 by Jelmer Vernooij
More fixes.
1514
        builder.build_snapshot([b'a@cset-0-1'], [
1515
            ('add', ('other-file', b'file2-id', 'file', b'file2-content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1516
            ], revision_id=b'a@cset-0-2b')
6973.7.10 by Jelmer Vernooij
More fixes.
1517
        builder.build_snapshot([b'a@cset-0-2a', b'a@cset-0-2b'], [
1518
            ('add', ('other-file', b'file2-id', 'file', b'file2-content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1519
            ], revision_id=b'a@cset-0-3')
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1520
        builder.finish_series()
1521
        self.b1 = builder.get_branch()
1522
        self.b1.lock_read()
1523
        self.addCleanup(self.b1.unlock)
1524
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1525
    def make_bundle_just_inventories(self, base_revision_id,
1526
                                     target_revision_id,
1527
                                     revision_ids):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1528
        sio = BytesIO()
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1529
        writer = v4.BundleWriteOperation(base_revision_id, target_revision_id,
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1530
                                         self.b1.repository, sio)
1531
        writer.bundle.begin()
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1532
        writer._add_inventory_mpdiffs_from_serializer(revision_ids)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1533
        writer.bundle.end()
1534
        sio.seek(0)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1535
        return sio
1536
1537
    def test_single_inventory_multiple_parents_as_xml(self):
1538
        self.make_merged_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1539
        sio = self.make_bundle_just_inventories(b'a@cset-0-1', b'a@cset-0-3',
1540
                                                [b'a@cset-0-3'])
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1541
        reader = v4.BundleReader(sio, stream_input=False)
1542
        records = list(reader.iter_records())
1543
        self.assertEqual(1, len(records))
1544
        (bytes, metadata, repo_kind, revision_id,
1545
         file_id) = records[0]
1546
        self.assertIs(None, file_id)
6973.7.10 by Jelmer Vernooij
More fixes.
1547
        self.assertEqual(b'a@cset-0-3', revision_id)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1548
        self.assertEqual('inventory', repo_kind)
6973.7.10 by Jelmer Vernooij
More fixes.
1549
        self.assertEqual({b'parents': [b'a@cset-0-2a', b'a@cset-0-2b'],
1550
                          b'sha1': b'09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1551
                          b'storage_kind': b'mpdiff',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1552
                          }, metadata)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1553
        # We should have an mpdiff that takes some lines from both parents.
1554
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1555
            b'i 1\n'
1556
            b'<inventory format="10" revision_id="a@cset-0-3">\n'
1557
            b'\n'
1558
            b'c 0 1 1 2\n'
1559
            b'c 1 3 3 2\n', bytes)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1560
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1561
    def test_single_inv_no_parents_as_xml(self):
1562
        self.make_merged_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1563
        sio = self.make_bundle_just_inventories(b'null:', b'a@cset-0-1',
1564
                                                [b'a@cset-0-1'])
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1565
        reader = v4.BundleReader(sio, stream_input=False)
1566
        records = list(reader.iter_records())
1567
        self.assertEqual(1, len(records))
1568
        (bytes, metadata, repo_kind, revision_id,
1569
         file_id) = records[0]
1570
        self.assertIs(None, file_id)
6973.7.10 by Jelmer Vernooij
More fixes.
1571
        self.assertEqual(b'a@cset-0-1', revision_id)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1572
        self.assertEqual('inventory', repo_kind)
6973.7.10 by Jelmer Vernooij
More fixes.
1573
        self.assertEqual({b'parents': [],
1574
                          b'sha1': b'a13f42b142d544aac9b085c42595d304150e31a2',
1575
                          b'storage_kind': b'mpdiff',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1576
                          }, metadata)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1577
        # We should have an mpdiff that takes some lines from both parents.
1578
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1579
            b'i 4\n'
1580
            b'<inventory format="10" revision_id="a@cset-0-1">\n'
1581
            b'<directory file_id="root-id" name=""'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1582
            b' revision="a@cset-0-1" />\n'
6973.7.10 by Jelmer Vernooij
More fixes.
1583
            b'<file file_id="file-id" name="file" parent_id="root-id"'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1584
            b' revision="a@cset-0-1"'
1585
            b' text_sha1="09c2f8647e14e49e922b955c194102070597c2d1"'
1586
            b' text_size="17" />\n'
6973.7.10 by Jelmer Vernooij
More fixes.
1587
            b'</inventory>\n'
1588
            b'\n', bytes)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1589
1590
    def test_multiple_inventories_as_xml(self):
1591
        self.make_merged_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1592
        sio = self.make_bundle_just_inventories(b'a@cset-0-1', b'a@cset-0-3',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1593
                                                [b'a@cset-0-2a', b'a@cset-0-2b', b'a@cset-0-3'])
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1594
        reader = v4.BundleReader(sio, stream_input=False)
1595
        records = list(reader.iter_records())
1596
        self.assertEqual(3, len(records))
1597
        revision_ids = [rev_id for b, m, k, rev_id, f in records]
6973.7.10 by Jelmer Vernooij
More fixes.
1598
        self.assertEqual([b'a@cset-0-2a', b'a@cset-0-2b', b'a@cset-0-3'],
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1599
                         revision_ids)
1600
        metadata_2a = records[0][1]
6973.7.10 by Jelmer Vernooij
More fixes.
1601
        self.assertEqual({b'parents': [b'a@cset-0-1'],
1602
                          b'sha1': b'1e105886d62d510763e22885eec733b66f5f09bf',
1603
                          b'storage_kind': b'mpdiff',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1604
                          }, metadata_2a)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1605
        metadata_2b = records[1][1]
6973.7.10 by Jelmer Vernooij
More fixes.
1606
        self.assertEqual({b'parents': [b'a@cset-0-1'],
1607
                          b'sha1': b'f03f12574bdb5ed2204c28636c98a8547544ccd8',
1608
                          b'storage_kind': b'mpdiff',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1609
                          }, metadata_2b)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1610
        metadata_3 = records[2][1]
6973.7.10 by Jelmer Vernooij
More fixes.
1611
        self.assertEqual({b'parents': [b'a@cset-0-2a', b'a@cset-0-2b'],
1612
                          b'sha1': b'09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1613
                          b'storage_kind': b'mpdiff',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1614
                          }, metadata_3)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1615
        bytes_2a = records[0][0]
1616
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1617
            b'i 1\n'
1618
            b'<inventory format="10" revision_id="a@cset-0-2a">\n'
1619
            b'\n'
1620
            b'c 0 1 1 1\n'
1621
            b'i 1\n'
1622
            b'<file file_id="file-id" name="file" parent_id="root-id"'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1623
            b' revision="a@cset-0-2a"'
1624
            b' text_sha1="50f545ff40e57b6924b1f3174b267ffc4576e9a9"'
1625
            b' text_size="12" />\n'
6973.7.10 by Jelmer Vernooij
More fixes.
1626
            b'\n'
1627
            b'c 0 3 3 1\n', bytes_2a)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1628
        bytes_2b = records[1][0]
1629
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1630
            b'i 1\n'
1631
            b'<inventory format="10" revision_id="a@cset-0-2b">\n'
1632
            b'\n'
1633
            b'c 0 1 1 2\n'
1634
            b'i 1\n'
1635
            b'<file file_id="file2-id" name="other-file" parent_id="root-id"'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1636
            b' revision="a@cset-0-2b"'
1637
            b' text_sha1="b46c0c8ea1e5ef8e46fc8894bfd4752a88ec939e"'
1638
            b' text_size="14" />\n'
6973.7.10 by Jelmer Vernooij
More fixes.
1639
            b'\n'
1640
            b'c 0 3 4 1\n', bytes_2b)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1641
        bytes_3 = records[2][0]
1642
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1643
            b'i 1\n'
1644
            b'<inventory format="10" revision_id="a@cset-0-3">\n'
1645
            b'\n'
1646
            b'c 0 1 1 2\n'
1647
            b'c 1 3 3 2\n', bytes_3)
4543.2.7 by John Arbash Meinel
It turns out CHKSerializer was inheriting from xml5
1648
1649
    def test_creating_bundle_preserves_chk_pages(self):
1650
        self.make_merged_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1651
        target = self.b1.controldir.sprout('target',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1652
                                           revision_id=b'a@cset-0-2a').open_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1653
        bundle_txt, rev_ids = self.create_bundle_text(b'a@cset-0-2a',
1654
                                                      b'a@cset-0-3')
7029.2.1 by Jelmer Vernooij
don't make assumptions about the order in which revision ids are returned by write_bundle.
1655
        self.assertEqual(set([b'a@cset-0-2b', b'a@cset-0-3']), set(rev_ids))
4543.2.7 by John Arbash Meinel
It turns out CHKSerializer was inheriting from xml5
1656
        bundle = read_bundle(bundle_txt)
1657
        target.lock_write()
1658
        self.addCleanup(target.unlock)
1659
        install_bundle(target.repository, bundle)
7018.3.10 by Jelmer Vernooij
Consistent return values in PreviewTree.list_files.
1660
        inv1 = next(self.b1.repository.inventories.get_record_stream([
1661
            (b'a@cset-0-3',)], 'unordered',
1662
            True)).get_bytes_as('fulltext')
1663
        inv2 = next(target.repository.inventories.get_record_stream([
1664
            (b'a@cset-0-3',)], 'unordered',
1665
            True)).get_bytes_as('fulltext')
4543.2.7 by John Arbash Meinel
It turns out CHKSerializer was inheriting from xml5
1666
        self.assertEqualDiff(inv1, inv2)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1667
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1668
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1669
class MungedBundleTester(object):
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1670
1671
    def build_test_bundle(self):
1672
        wt = self.make_branch_and_tree('b1')
1673
1674
        self.build_tree(['b1/one'])
1675
        wt.add('one')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1676
        wt.commit('add one', rev_id=b'a@cset-0-1')
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1677
        self.build_tree(['b1/two'])
1678
        wt.add('two')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1679
        wt.commit('add two', rev_id=b'a@cset-0-2',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1680
                  revprops={u'branch-nick': 'test'})
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1681
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1682
        bundle_txt = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
1683
        rev_ids = write_bundle(wt.branch.repository, b'a@cset-0-2',
1684
                               b'a@cset-0-1', bundle_txt, self.format)
1685
        self.assertEqual({b'a@cset-0-2'}, set(rev_ids))
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1686
        bundle_txt.seek(0, 0)
1687
        return bundle_txt
1688
1689
    def check_valid(self, bundle):
1690
        """Check that after whatever munging, the final object is valid."""
6973.7.10 by Jelmer Vernooij
More fixes.
1691
        self.assertEqual([b'a@cset-0-2'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1692
                         [r.revision_id for r in bundle.real_revisions])
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1693
1694
    def test_extra_whitespace(self):
1695
        bundle_txt = self.build_test_bundle()
1696
1697
        # Seek to the end of the file
1698
        # Adding one extra newline used to give us
1699
        # TypeError: float() argument must be a string or a number
1700
        bundle_txt.seek(0, 2)
6973.7.5 by Jelmer Vernooij
s/file/open.
1701
        bundle_txt.write(b'\n')
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1702
        bundle_txt.seek(0)
1703
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1704
        bundle = read_bundle(bundle_txt)
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1705
        self.check_valid(bundle)
1706
1707
    def test_extra_whitespace_2(self):
1708
        bundle_txt = self.build_test_bundle()
1709
1710
        # Seek to the end of the file
1711
        # Adding two extra newlines used to give us
1712
        # MalformedPatches: The first line of all patches should be ...
1713
        bundle_txt.seek(0, 2)
6973.7.5 by Jelmer Vernooij
s/file/open.
1714
        bundle_txt.write(b'\n\n')
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1715
        bundle_txt.seek(0)
1716
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1717
        bundle = read_bundle(bundle_txt)
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1718
        self.check_valid(bundle)
1719
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1720
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1721
class MungedBundleTesterV09(tests.TestCaseWithTransport, MungedBundleTester):
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1722
1723
    format = '0.9'
1724
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1725
    def test_missing_trailing_whitespace(self):
1726
        bundle_txt = self.build_test_bundle()
1727
1728
        # Remove a trailing newline, it shouldn't kill the parser
1729
        raw = bundle_txt.getvalue()
1730
        # The contents of the bundle don't have to be this, but this
1731
        # test is concerned with the exact case where the serializer
1732
        # creates a blank line at the end, and fails if that
1733
        # line is stripped
6973.7.10 by Jelmer Vernooij
More fixes.
1734
        self.assertEqual(b'\n\n', raw[-2:])
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1735
        bundle_txt = BytesIO(raw[:-1])
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1736
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1737
        bundle = read_bundle(bundle_txt)
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1738
        self.check_valid(bundle)
1793.3.14 by John Arbash Meinel
Actually fix the bug with missing trailing newline bug #49182
1739
1793.3.16 by John Arbash Meinel
Add tests to ensure that we gracefully handle opening and trailing non-bundle text.
1740
    def test_opening_text(self):
1741
        bundle_txt = self.build_test_bundle()
1742
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1743
        bundle_txt = BytesIO(
1744
            b"Some random\nemail comments\n" + bundle_txt.getvalue())
1793.3.16 by John Arbash Meinel
Add tests to ensure that we gracefully handle opening and trailing non-bundle text.
1745
1746
        bundle = read_bundle(bundle_txt)
1747
        self.check_valid(bundle)
1748
1749
    def test_trailing_text(self):
1750
        bundle_txt = self.build_test_bundle()
1751
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1752
        bundle_txt = BytesIO(
1753
            bundle_txt.getvalue() + b"Some trailing\nrandom\ntext\n")
1793.3.16 by John Arbash Meinel
Add tests to ensure that we gracefully handle opening and trailing non-bundle text.
1754
1755
        bundle = read_bundle(bundle_txt)
1756
        self.check_valid(bundle)
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1757
1758
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1759
class MungedBundleTesterV4(tests.TestCaseWithTransport, MungedBundleTester):
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1760
2520.4.136 by Aaron Bentley
Fix format strings
1761
    format = '4'
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1762
1763
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1764
class TestBundleWriterReader(tests.TestCase):
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1765
1766
    def test_roundtrip_record(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1767
        fileobj = BytesIO()
2520.4.72 by Aaron Bentley
Rename format to 4alpha
1768
        writer = v4.BundleWriter(fileobj)
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1769
        writer.begin()
6973.7.8 by Jelmer Vernooij
Fix more tests.
1770
        writer.add_info_record({b'foo': b'bar'})
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
1771
        writer._add_record(b"Record body", {b'parents': [b'1', b'3'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1772
                                            b'storage_kind': b'fulltext'}, 'file', b'revid', b'fileid')
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1773
        writer.end()
1774
        fileobj.seek(0)
2520.4.148 by Aaron Bentley
Updates from review
1775
        reader = v4.BundleReader(fileobj, stream_input=True)
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1776
        record_iter = reader.iter_records()
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1777
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1778
        self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
7143.15.2 by Jelmer Vernooij
Run autopep8.
1779
                          'info', None, None), record)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1780
        record = next(record_iter)
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
1781
        self.assertEqual((b"Record body", {b'storage_kind': b'fulltext',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1782
                                           b'parents': [b'1', b'3']}, 'file', b'revid', b'fileid'),
1783
                         record)
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1784
1785
    def test_roundtrip_record_memory_hungry(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1786
        fileobj = BytesIO()
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1787
        writer = v4.BundleWriter(fileobj)
1788
        writer.begin()
6973.7.8 by Jelmer Vernooij
Fix more tests.
1789
        writer.add_info_record({b'foo': b'bar'})
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
1790
        writer._add_record(b"Record body", {b'parents': [b'1', b'3'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1791
                                            b'storage_kind': b'fulltext'}, 'file', b'revid', b'fileid')
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1792
        writer.end()
1793
        fileobj.seek(0)
2520.4.148 by Aaron Bentley
Updates from review
1794
        reader = v4.BundleReader(fileobj, stream_input=False)
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1795
        record_iter = reader.iter_records()
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1796
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1797
        self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
7143.15.2 by Jelmer Vernooij
Run autopep8.
1798
                          'info', None, None), record)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1799
        record = next(record_iter)
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
1800
        self.assertEqual((b"Record body", {b'storage_kind': b'fulltext',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1801
                                           b'parents': [b'1', b'3']}, 'file', b'revid', b'fileid'),
1802
                         record)
2520.4.95 by Aaron Bentley
Add support for header/info records
1803
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1804
    def test_encode_name(self):
6973.7.8 by Jelmer Vernooij
Fix more tests.
1805
        self.assertEqual(b'revision/rev1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1806
                         v4.BundleWriter.encode_name('revision', b'rev1'))
6973.7.8 by Jelmer Vernooij
Fix more tests.
1807
        self.assertEqual(b'file/rev//1/file-id-1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1808
                         v4.BundleWriter.encode_name('file', b'rev/1', b'file-id-1'))
6973.7.8 by Jelmer Vernooij
Fix more tests.
1809
        self.assertEqual(b'info',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1810
                         v4.BundleWriter.encode_name('info', None, None))
2520.4.95 by Aaron Bentley
Add support for header/info records
1811
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1812
    def test_decode_name(self):
6973.7.8 by Jelmer Vernooij
Fix more tests.
1813
        self.assertEqual(('revision', b'rev1', None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1814
                         v4.BundleReader.decode_name(b'revision/rev1'))
6973.7.8 by Jelmer Vernooij
Fix more tests.
1815
        self.assertEqual(('file', b'rev/1', b'file-id-1'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1816
                         v4.BundleReader.decode_name(b'file/rev//1/file-id-1'))
2520.4.95 by Aaron Bentley
Add support for header/info records
1817
        self.assertEqual(('info', None, None),
6973.7.8 by Jelmer Vernooij
Fix more tests.
1818
                         v4.BundleReader.decode_name(b'info'))
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1819
1820
    def test_too_many_names(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1821
        fileobj = BytesIO()
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1822
        writer = v4.BundleWriter(fileobj)
1823
        writer.begin()
6973.7.8 by Jelmer Vernooij
Fix more tests.
1824
        writer.add_info_record({b'foo': b'bar'})
7065.3.11 by Jelmer Vernooij
Fix bundle tests.
1825
        writer._container.add_bytes_record(b'blah', [(b'two', ), (b'names', )])
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1826
        writer.end()
1827
        fileobj.seek(0)
1828
        record_iter = v4.BundleReader(fileobj).iter_records()
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1829
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1830
        self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
7143.15.2 by Jelmer Vernooij
Run autopep8.
1831
                          'info', None, None), record)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1832
        self.assertRaises(errors.BadBundle, next, record_iter)