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