/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
6670.4.1 by Jelmer Vernooij
Update imports.
17
"""Tests for breezy.bzr.inventory_delta.
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
18
19
See doc/developer/inventory.txt for more information.
20
"""
21
6670.4.1 by Jelmer Vernooij
Update imports.
22
from ..bzr import (
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
23
    inventory,
24
    inventory_delta,
25
    )
6670.4.1 by Jelmer Vernooij
Update imports.
26
from ..bzr.inventory_delta import InventoryDeltaError
27
from ..bzr.inventory import Inventory
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
28
from ..revision import NULL_REVISION
29
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
30
    BytesIO,
31
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
32
from . import TestCase
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
33
34
### DO NOT REFLOW THESE TEXTS. NEW LINES ARE SIGNIFICANT. ###
6684.1.4 by Martin
Start making inventory tests pass on Python 3
35
empty_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
36
parent: null:
37
version: null:
38
versioned_root: true
39
tree_references: true
40
"""
41
6684.1.4 by Martin
Start making inventory tests pass on Python 3
42
root_only_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
43
parent: null:
44
version: entry-version
45
versioned_root: true
46
tree_references: true
4205.5.3 by Andrew Bennetts
Include oldpath in the the serialised delta
47
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
48
"""
49
50
6684.1.4 by Martin
Start making inventory tests pass on Python 3
51
root_change_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
52
parent: entry-version
53
version: changed-root
54
versioned_root: true
55
tree_references: true
56
/\x00an-id\x00\x00different-version\x00dir
57
"""
58
6684.1.4 by Martin
Start making inventory tests pass on Python 3
59
corrupt_parent_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
60
parent: entry-version
61
version: changed-root
62
versioned_root: false
63
tree_references: false
64
/\x00an-id\x00\x00different-version\x00dir
65
"""
66
6684.1.4 by Martin
Start making inventory tests pass on Python 3
67
root_only_unversioned = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
68
parent: null:
69
version: entry-version
70
versioned_root: false
71
tree_references: false
4476.3.46 by Andrew Bennetts
Make actual non-rich-root inventories (which have implicit root entries with non-None revisions) roundtrip through inventory-deltas correctly.
72
None\x00/\x00TREE_ROOT\x00\x00entry-version\x00dir
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
73
"""
74
6684.1.4 by Martin
Start making inventory tests pass on Python 3
75
reference_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
76
parent: null:
77
version: entry-version
78
versioned_root: true
79
tree_references: true
4205.5.3 by Andrew Bennetts
Include oldpath in the the serialised delta
80
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir
81
None\x00/foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
82
"""
83
6684.1.4 by Martin
Start making inventory tests pass on Python 3
84
change_tree_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
85
parent: entry-version
86
version: change-tree
87
versioned_root: false
88
tree_references: false
89
/foo\x00id\x00TREE_ROOT\x00changed-twice\x00tree\x00subtree-version2
90
"""
91
92
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
93
class TestDeserialization(TestCase):
94
    """Test InventoryDeltaSerializer.parse_text_bytes."""
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
95
96
    def test_parse_no_bytes(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
97
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
98
        err = self.assertRaises(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
99
            InventoryDeltaError, deserializer.parse_text_bytes, b'')
4476.3.26 by Andrew Bennetts
Stricter (de)serialization of leading slashes in paths in inventory deltas.
100
        self.assertContainsRe(str(err), 'last line not empty')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
101
102
    def test_parse_bad_format(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
103
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
104
        err = self.assertRaises(InventoryDeltaError,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
105
            deserializer.parse_text_bytes, b'format: foo\n')
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
106
        self.assertContainsRe(str(err), 'unknown format')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
107
108
    def test_parse_no_parent(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
109
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
110
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
111
            deserializer.parse_text_bytes,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
112
            b'format: bzr inventory delta v1 (bzr 1.14)\n')
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
113
        self.assertContainsRe(str(err), 'missing parent: marker')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
114
115
    def test_parse_no_version(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
116
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
117
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
118
            deserializer.parse_text_bytes,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
119
            b'format: bzr inventory delta v1 (bzr 1.14)\n'
120
            b'parent: null:\n')
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
121
        self.assertContainsRe(str(err), 'missing version: marker')
6684.1.4 by Martin
Start making inventory tests pass on Python 3
122
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
123
    def test_parse_duplicate_key_errors(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
124
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
125
        double_root_lines = \
6684.1.4 by Martin
Start making inventory tests pass on Python 3
126
b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
127
parent: null:
128
version: null:
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
129
versioned_root: true
130
tree_references: true
131
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
132
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
133
"""
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
134
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
135
            deserializer.parse_text_bytes, double_root_lines)
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
136
        self.assertContainsRe(str(err), 'duplicate file id')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
137
138
    def test_parse_versioned_root_only(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
139
        deserializer = inventory_delta.InventoryDeltaDeserializer()
140
        parse_result = deserializer.parse_text_bytes(root_only_lines)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
141
        expected_entry = inventory.make_entry(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
142
            'directory', u'', None, b'an-id')
143
        expected_entry.revision = b'a@e\xc3\xa5ample.com--2004'
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
144
        self.assertEqual(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
145
            (b'null:', b'entry-version', True, True,
146
             [(None, u'', b'an-id', expected_entry)]),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
147
            parse_result)
148
149
    def test_parse_special_revid_not_valid_last_mod(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
150
        deserializer = inventory_delta.InventoryDeltaDeserializer()
6684.1.4 by Martin
Start making inventory tests pass on Python 3
151
        root_only_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
152
parent: null:
153
version: null:
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
154
versioned_root: false
155
tree_references: true
156
None\x00/\x00TREE_ROOT\x00\x00null:\x00dir\x00\x00
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
157
"""
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
158
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
159
            deserializer.parse_text_bytes, root_only_lines)
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
160
        self.assertContainsRe(str(err), 'special revisionid found')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
161
162
    def test_parse_versioned_root_versioned_disabled(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
163
        deserializer = inventory_delta.InventoryDeltaDeserializer()
6684.1.4 by Martin
Start making inventory tests pass on Python 3
164
        root_only_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
165
parent: null:
166
version: null:
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
167
versioned_root: false
168
tree_references: true
169
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
170
"""
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
171
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
172
            deserializer.parse_text_bytes, root_only_lines)
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
173
        self.assertContainsRe(str(err), 'Versioned root found')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
174
175
    def test_parse_unique_root_id_root_versioned_disabled(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
176
        deserializer = inventory_delta.InventoryDeltaDeserializer()
6684.1.4 by Martin
Start making inventory tests pass on Python 3
177
        root_only_lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4476.3.61 by Andrew Bennetts
Fix test_inventory_delta for actual rich root semantics.
178
parent: parent-id
179
version: a@e\xc3\xa5ample.com--2004
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
180
versioned_root: false
181
tree_references: true
4476.3.61 by Andrew Bennetts
Fix test_inventory_delta for actual rich root semantics.
182
None\x00/\x00an-id\x00\x00parent-id\x00dir\x00\x00
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
183
"""
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
184
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
185
            deserializer.parse_text_bytes, root_only_lines)
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
186
        self.assertContainsRe(str(err), 'Versioned root found')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
187
188
    def test_parse_unversioned_root_versioning_enabled(self):
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
189
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.77 by Andrew Bennetts
Replace require_flags method with allow_versioned_root and allow_tree_references flags on InventoryDeltaSerializer.__init__, and shift some checking of delta compatibility from StreamSink to InventoryDeltaSerializer.
190
        parse_result = deserializer.parse_text_bytes(root_only_unversioned)
191
        expected_entry = inventory.make_entry(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
192
            'directory', u'', None, b'TREE_ROOT')
193
        expected_entry.revision = b'entry-version'
4476.3.77 by Andrew Bennetts
Replace require_flags method with allow_versioned_root and allow_tree_references flags on InventoryDeltaSerializer.__init__, and shift some checking of delta compatibility from StreamSink to InventoryDeltaSerializer.
194
        self.assertEqual(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
195
            (b'null:', b'entry-version', False, False,
196
             [(None, u'', b'TREE_ROOT', expected_entry)]),
4476.3.77 by Andrew Bennetts
Replace require_flags method with allow_versioned_root and allow_tree_references flags on InventoryDeltaSerializer.__init__, and shift some checking of delta compatibility from StreamSink to InventoryDeltaSerializer.
197
            parse_result)
198
199
    def test_parse_versioned_root_when_disabled(self):
200
        deserializer = inventory_delta.InventoryDeltaDeserializer(
201
            allow_versioned_root=False)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
202
        err = self.assertRaises(inventory_delta.IncompatibleInventoryDelta,
4476.3.77 by Andrew Bennetts
Replace require_flags method with allow_versioned_root and allow_tree_references flags on InventoryDeltaSerializer.__init__, and shift some checking of delta compatibility from StreamSink to InventoryDeltaSerializer.
203
            deserializer.parse_text_bytes, root_only_lines)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
204
        self.assertEqual("versioned_root not allowed", str(err))
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
205
206
    def test_parse_tree_when_disabled(self):
4476.3.77 by Andrew Bennetts
Replace require_flags method with allow_versioned_root and allow_tree_references flags on InventoryDeltaSerializer.__init__, and shift some checking of delta compatibility from StreamSink to InventoryDeltaSerializer.
207
        deserializer = inventory_delta.InventoryDeltaDeserializer(
208
            allow_tree_references=False)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
209
        err = self.assertRaises(inventory_delta.IncompatibleInventoryDelta,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
210
            deserializer.parse_text_bytes, reference_lines)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
211
        self.assertEqual("Tree reference not allowed", str(err))
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
212
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
213
    def test_parse_tree_when_header_disallows(self):
214
        # A deserializer that allows tree_references to be set or unset.
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
215
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
216
        # A serialised inventory delta with a header saying no tree refs, but
217
        # that has a tree ref in its content.
6684.1.4 by Martin
Start making inventory tests pass on Python 3
218
        lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
219
parent: null:
220
version: entry-version
221
versioned_root: false
222
tree_references: false
223
None\x00/foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version
224
"""
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
225
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
226
            deserializer.parse_text_bytes, lines)
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
227
        self.assertContainsRe(str(err), 'Tree reference found')
228
229
    def test_parse_versioned_root_when_header_disallows(self):
230
        # A deserializer that allows tree_references to be set or unset.
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
231
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
232
        # A serialised inventory delta with a header saying no tree refs, but
233
        # that has a tree ref in its content.
6684.1.4 by Martin
Start making inventory tests pass on Python 3
234
        lines = b"""format: bzr inventory delta v1 (bzr 1.14)
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
235
parent: null:
236
version: entry-version
237
versioned_root: false
238
tree_references: false
239
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir
240
"""
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
241
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
242
            deserializer.parse_text_bytes, lines)
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
243
        self.assertContainsRe(str(err), 'Versioned root found')
244
4476.3.26 by Andrew Bennetts
Stricter (de)serialization of leading slashes in paths in inventory deltas.
245
    def test_parse_last_line_not_empty(self):
246
        """newpath must start with / if it is not None."""
247
        # Trim the trailing newline from a valid serialization
248
        lines = root_only_lines[:-1]
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
249
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
250
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
251
            deserializer.parse_text_bytes, lines)
4476.3.26 by Andrew Bennetts
Stricter (de)serialization of leading slashes in paths in inventory deltas.
252
        self.assertContainsRe(str(err), 'last line not empty')
253
254
    def test_parse_invalid_newpath(self):
255
        """newpath must start with / if it is not None."""
256
        lines = empty_lines
6684.1.4 by Martin
Start making inventory tests pass on Python 3
257
        lines += b"None\x00bad\x00TREE_ROOT\x00\x00version\x00dir\n"
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
258
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
259
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
260
            deserializer.parse_text_bytes, lines)
4476.3.26 by Andrew Bennetts
Stricter (de)serialization of leading slashes in paths in inventory deltas.
261
        self.assertContainsRe(str(err), 'newpath invalid')
262
263
    def test_parse_invalid_oldpath(self):
264
        """oldpath must start with / if it is not None."""
265
        lines = root_only_lines
6684.1.4 by Martin
Start making inventory tests pass on Python 3
266
        lines += b"bad\x00/new\x00file-id\x00\x00version\x00dir\n"
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
267
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
268
        err = self.assertRaises(InventoryDeltaError,
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
269
            deserializer.parse_text_bytes, lines)
4476.3.26 by Andrew Bennetts
Stricter (de)serialization of leading slashes in paths in inventory deltas.
270
        self.assertContainsRe(str(err), 'oldpath invalid')
6684.1.4 by Martin
Start making inventory tests pass on Python 3
271
4476.3.49 by Andrew Bennetts
Start reworking inventory-delta streaming to use a separate substream.
272
    def test_parse_new_file(self):
273
        """a new file is parsed correctly"""
274
        lines = root_only_lines
6684.1.4 by Martin
Start making inventory tests pass on Python 3
275
        fake_sha = b"deadbeef" * 5
4476.3.49 by Andrew Bennetts
Start reworking inventory-delta streaming to use a separate substream.
276
        lines += (
6684.1.4 by Martin
Start making inventory tests pass on Python 3
277
            b"None\x00/new\x00file-id\x00an-id\x00version\x00file\x00123\x00" +
278
            b"\x00" + fake_sha + b"\n")
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
279
        deserializer = inventory_delta.InventoryDeltaDeserializer()
280
        parse_result = deserializer.parse_text_bytes(lines)
4476.3.49 by Andrew Bennetts
Start reworking inventory-delta streaming to use a separate substream.
281
        expected_entry = inventory.make_entry(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
282
            'file', u'new', b'an-id', b'file-id')
283
        expected_entry.revision = b'version'
4476.3.49 by Andrew Bennetts
Start reworking inventory-delta streaming to use a separate substream.
284
        expected_entry.text_size = 123
285
        expected_entry.text_sha1 = fake_sha
286
        delta = parse_result[4]
287
        self.assertEqual(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
288
             (None, u'new', b'file-id', expected_entry), delta[-1])
4476.3.4 by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out.
289
4476.3.60 by Andrew Bennetts
Add test for deserialization of deletes in inventory-deltas.
290
    def test_parse_delete(self):
291
        lines = root_only_lines
292
        lines += (
6684.1.4 by Martin
Start making inventory tests pass on Python 3
293
            b"/old-file\x00None\x00deleted-id\x00\x00null:\x00deleted\x00\x00\n")
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
294
        deserializer = inventory_delta.InventoryDeltaDeserializer()
295
        parse_result = deserializer.parse_text_bytes(lines)
4476.3.60 by Andrew Bennetts
Add test for deserialization of deletes in inventory-deltas.
296
        delta = parse_result[4]
297
        self.assertEqual(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
298
             (u'old-file', None, b'deleted-id', None), delta[-1])
4476.3.60 by Andrew Bennetts
Add test for deserialization of deletes in inventory-deltas.
299
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
300
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
301
class TestSerialization(TestCase):
4205.5.4 by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test.
302
    """Tests for InventoryDeltaSerializer.delta_to_lines."""
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
303
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
304
    def test_empty_delta_to_lines(self):
305
        old_inv = Inventory(None)
306
        new_inv = Inventory(None)
307
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
308
        serializer = inventory_delta.InventoryDeltaSerializer(
309
            versioned_root=True, tree_references=True)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
310
        self.assertEqual(BytesIO(empty_lines).readlines(),
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
311
            serializer.delta_to_lines(NULL_REVISION, NULL_REVISION, delta))
312
313
    def test_root_only_to_lines(self):
314
        old_inv = Inventory(None)
315
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
316
        root = new_inv.make_entry('directory', u'', None, b'an-id')
317
        root.revision = b'a@e\xc3\xa5ample.com--2004'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
318
        new_inv.add(root)
319
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
320
        serializer = inventory_delta.InventoryDeltaSerializer(
321
            versioned_root=True, tree_references=True)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
322
        self.assertEqual(BytesIO(root_only_lines).readlines(),
6684.1.4 by Martin
Start making inventory tests pass on Python 3
323
            serializer.delta_to_lines(NULL_REVISION, b'entry-version', delta))
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
324
325
    def test_unversioned_root(self):
326
        old_inv = Inventory(None)
327
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
328
        root = new_inv.make_entry('directory', u'', None, b'TREE_ROOT')
4476.3.46 by Andrew Bennetts
Make actual non-rich-root inventories (which have implicit root entries with non-None revisions) roundtrip through inventory-deltas correctly.
329
        # Implicit roots are considered modified in every revision.
6684.1.4 by Martin
Start making inventory tests pass on Python 3
330
        root.revision = b'entry-version'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
331
        new_inv.add(root)
332
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
333
        serializer = inventory_delta.InventoryDeltaSerializer(
334
            versioned_root=False, tree_references=False)
4476.3.46 by Andrew Bennetts
Make actual non-rich-root inventories (which have implicit root entries with non-None revisions) roundtrip through inventory-deltas correctly.
335
        serialized_lines = serializer.delta_to_lines(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
336
            NULL_REVISION, b'entry-version', delta)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
337
        self.assertEqual(BytesIO(root_only_unversioned).readlines(),
4476.3.46 by Andrew Bennetts
Make actual non-rich-root inventories (which have implicit root entries with non-None revisions) roundtrip through inventory-deltas correctly.
338
            serialized_lines)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
339
        deserializer = inventory_delta.InventoryDeltaDeserializer()
4476.3.46 by Andrew Bennetts
Make actual non-rich-root inventories (which have implicit root entries with non-None revisions) roundtrip through inventory-deltas correctly.
340
        self.assertEqual(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
341
            (NULL_REVISION, b'entry-version', False, False, delta),
342
            deserializer.parse_text_bytes(b''.join(serialized_lines)))
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
343
344
    def test_unversioned_non_root_errors(self):
345
        old_inv = Inventory(None)
346
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
347
        root = new_inv.make_entry('directory', u'', None, b'TREE_ROOT')
348
        root.revision = b'a@e\xc3\xa5ample.com--2004'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
349
        new_inv.add(root)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
350
        non_root = new_inv.make_entry('directory', u'foo', root.file_id, b'id')
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
351
        new_inv.add(non_root)
352
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
353
        serializer = inventory_delta.InventoryDeltaSerializer(
354
            versioned_root=True, tree_references=True)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
355
        err = self.assertRaises(InventoryDeltaError,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
356
            serializer.delta_to_lines, NULL_REVISION, b'entry-version', delta)
6670.3.3 by Martin
Make InventoryDeltaError use string formatting, and repr for fileids
357
        self.assertContainsRe(str(err), "^no version for fileid b?'id'$")
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
358
359
    def test_richroot_unversioned_root_errors(self):
360
        old_inv = Inventory(None)
361
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
362
        root = new_inv.make_entry('directory', '', None, b'TREE_ROOT')
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
363
        new_inv.add(root)
364
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
365
        serializer = inventory_delta.InventoryDeltaSerializer(
366
            versioned_root=True, tree_references=True)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
367
        err = self.assertRaises(InventoryDeltaError,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
368
            serializer.delta_to_lines, NULL_REVISION, b'entry-version', delta)
6670.3.3 by Martin
Make InventoryDeltaError use string formatting, and repr for fileids
369
        self.assertContainsRe(
370
            str(err), "no version for fileid b?'TREE_ROOT'$")
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
371
372
    def test_nonrichroot_versioned_root_errors(self):
373
        old_inv = Inventory(None)
374
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
375
        root = new_inv.make_entry('directory', u'', None, b'TREE_ROOT')
376
        root.revision = b'a@e\xc3\xa5ample.com--2004'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
377
        new_inv.add(root)
378
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
379
        serializer = inventory_delta.InventoryDeltaSerializer(
380
            versioned_root=False, tree_references=True)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
381
        err = self.assertRaises(InventoryDeltaError,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
382
            serializer.delta_to_lines, NULL_REVISION, b'entry-version', delta)
6670.3.3 by Martin
Make InventoryDeltaError use string formatting, and repr for fileids
383
        self.assertContainsRe(
384
            str(err), "^Version present for / in b?'TREE_ROOT'")
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
385
386
    def test_unknown_kind_errors(self):
387
        old_inv = Inventory(None)
388
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
389
        root = new_inv.make_entry('directory', u'', None, b'my-rich-root-id')
390
        root.revision = b'changed'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
391
        new_inv.add(root)
5365.2.1 by Andrew Bennetts
Reduce memory consumption of InventoryEntries by removing __slots__ entries for attributes that should never be set, e.g. symlink_target on files.
392
        class StrangeInventoryEntry(inventory.InventoryEntry):
393
            kind = 'strange'
6973.11.6 by Jelmer Vernooij
Fix more http tests.
394
        non_root = StrangeInventoryEntry(b'id', u'foo', root.file_id)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
395
        non_root.revision = b'changed'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
396
        new_inv.add(non_root)
397
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
398
        serializer = inventory_delta.InventoryDeltaSerializer(
399
            versioned_root=True, tree_references=True)
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
400
        # we expect keyerror because there is little value wrapping this.
401
        # This test aims to prove that it errors more than how it errors.
402
        err = self.assertRaises(KeyError,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
403
            serializer.delta_to_lines, NULL_REVISION, b'entry-version', delta)
5365.2.1 by Andrew Bennetts
Reduce memory consumption of InventoryEntries by removing __slots__ entries for attributes that should never be set, e.g. symlink_target on files.
404
        self.assertEqual(('strange',), err.args)
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
405
406
    def test_tree_reference_disabled(self):
407
        old_inv = Inventory(None)
408
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
409
        root = new_inv.make_entry('directory', u'', None, b'TREE_ROOT')
410
        root.revision = b'a@e\xc3\xa5ample.com--2004'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
411
        new_inv.add(root)
412
        non_root = new_inv.make_entry(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
413
            'tree-reference', u'foo', root.file_id, b'id')
414
        non_root.revision = b'changed'
415
        non_root.reference_revision = b'subtree-version'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
416
        new_inv.add(non_root)
417
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
418
        serializer = inventory_delta.InventoryDeltaSerializer(
419
            versioned_root=True, tree_references=False)
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
420
        # we expect keyerror because there is little value wrapping this.
421
        # This test aims to prove that it errors more than how it errors.
422
        err = self.assertRaises(KeyError,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
423
            serializer.delta_to_lines, NULL_REVISION, b'entry-version', delta)
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
424
        self.assertEqual(('tree-reference',), err.args)
425
426
    def test_tree_reference_enabled(self):
427
        old_inv = Inventory(None)
428
        new_inv = Inventory(None)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
429
        root = new_inv.make_entry('directory', u'', None, b'TREE_ROOT')
430
        root.revision = b'a@e\xc3\xa5ample.com--2004'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
431
        new_inv.add(root)
432
        non_root = new_inv.make_entry(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
433
            'tree-reference', u'foo', root.file_id, b'id')
434
        non_root.revision = b'changed'
435
        non_root.reference_revision = b'subtree-version'
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
436
        new_inv.add(non_root)
437
        delta = new_inv._make_delta(old_inv)
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
438
        serializer = inventory_delta.InventoryDeltaSerializer(
439
            versioned_root=True, tree_references=True)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
440
        self.assertEqual(BytesIO(reference_lines).readlines(),
6684.1.4 by Martin
Start making inventory tests pass on Python 3
441
            serializer.delta_to_lines(NULL_REVISION, b'entry-version', delta))
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
442
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
443
    def test_to_inventory_root_id_versioned_not_permitted(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
444
        root_entry = inventory.make_entry('directory', u'', None, b'TREE_ROOT')
445
        root_entry.revision = b'some-version'
446
        delta = [(None, u'', b'TREE_ROOT', root_entry)]
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
447
        serializer = inventory_delta.InventoryDeltaSerializer(
448
            versioned_root=False, tree_references=True)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
449
        self.assertRaises(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
450
            InventoryDeltaError, serializer.delta_to_lines, b'old-version',
451
            b'new-version', delta)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
452
453
    def test_to_inventory_root_id_not_versioned(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
454
        delta = [(None, u'', b'an-id', inventory.make_entry(
455
            'directory', u'', None, b'an-id'))]
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
456
        serializer = inventory_delta.InventoryDeltaSerializer(
457
            versioned_root=True, tree_references=True)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
458
        self.assertRaises(
6684.1.4 by Martin
Start making inventory tests pass on Python 3
459
            InventoryDeltaError, serializer.delta_to_lines, b'old-version',
460
            b'new-version', delta)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
461
462
    def test_to_inventory_has_tree_not_meant_to(self):
463
        make_entry = inventory.make_entry
6684.1.4 by Martin
Start making inventory tests pass on Python 3
464
        tree_ref = make_entry(
465
            'tree-reference', u'foo', b'changed-in', b'ref-id')
466
        tree_ref.reference_revision = b'ref-revision'
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
467
        delta = [
6684.1.4 by Martin
Start making inventory tests pass on Python 3
468
            (None, u'', b'an-id',
469
             make_entry('directory', u'', b'changed-in', b'an-id')),
470
            (None, u'foo', b'ref-id', tree_ref)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
471
            # a file that followed the root move
472
            ]
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
473
        serializer = inventory_delta.InventoryDeltaSerializer(
474
            versioned_root=True, tree_references=True)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
475
        self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
6684.1.4 by Martin
Start making inventory tests pass on Python 3
476
            b'old-version', b'new-version', delta)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
477
478
    def test_to_inventory_torture(self):
479
        def make_entry(kind, name, parent_id, file_id, **attrs):
480
            entry = inventory.make_entry(kind, name, parent_id, file_id)
481
            for name, value in attrs.items():
482
                setattr(entry, name, value)
483
            return entry
484
        # this delta is crafted to have all the following:
485
        # - deletes
486
        # - renamed roots
487
        # - deep dirs
488
        # - files moved after parent dir was renamed
489
        # - files with and without exec bit
490
        delta = [
491
            # new root:
6684.1.4 by Martin
Start making inventory tests pass on Python 3
492
            (None, u'', b'new-root-id',
493
                make_entry('directory', u'', None, b'new-root-id',
494
                    revision=b'changed-in')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
495
            # an old root:
6684.1.4 by Martin
Start making inventory tests pass on Python 3
496
            (u'', u'old-root', b'TREE_ROOT',
497
                make_entry('directory', u'subdir-now', b'new-root-id',
498
                b'TREE_ROOT', revision=b'moved-root')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
499
            # a file that followed the root move
6684.1.4 by Martin
Start making inventory tests pass on Python 3
500
            (u'under-old-root', u'old-root/under-old-root', b'moved-id',
501
                make_entry('file', u'under-old-root', b'TREE_ROOT',
502
                    b'moved-id', revision=b'old-rev', executable=False,
503
                    text_size=30, text_sha1=b'some-sha')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
504
            # a deleted path
6684.1.4 by Martin
Start making inventory tests pass on Python 3
505
            (u'old-file', None, b'deleted-id', None),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
506
            # a tree reference moved to the new root
6684.1.4 by Martin
Start making inventory tests pass on Python 3
507
            (u'ref', u'ref', b'ref-id',
508
                make_entry('tree-reference', u'ref', b'new-root-id', b'ref-id',
509
                    reference_revision=b'tree-reference-id',
510
                    revision=b'new-rev')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
511
            # a symlink now in a deep dir
6684.1.4 by Martin
Start making inventory tests pass on Python 3
512
            (u'dir/link', u'old-root/dir/link', b'link-id',
513
                make_entry('symlink', u'link', b'deep-id', b'link-id',
514
                   symlink_target=u'target', revision=b'new-rev')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
515
            # a deep dir
6684.1.4 by Martin
Start making inventory tests pass on Python 3
516
            (u'dir', u'old-root/dir', b'deep-id',
517
                make_entry('directory', u'dir', b'TREE_ROOT', b'deep-id',
518
                    revision=b'new-rev')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
519
            # a file with an exec bit set
6684.1.4 by Martin
Start making inventory tests pass on Python 3
520
            (None, u'configure', b'exec-id',
521
                make_entry('file', u'configure', b'new-root-id', b'exec-id',
522
                   executable=True, text_size=30, text_sha1=b'some-sha',
523
                   revision=b'old-rev')),
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
524
            ]
4476.3.76 by Andrew Bennetts
Split out InventoryDeltaDeserializer from InventoryDeltaSerializer.
525
        serializer = inventory_delta.InventoryDeltaSerializer(
526
            versioned_root=True, tree_references=True)
6684.1.4 by Martin
Start making inventory tests pass on Python 3
527
        lines = serializer.delta_to_lines(NULL_REVISION, b'something', delta)
528
        expected = b"""format: bzr inventory delta v1 (bzr 1.14)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
529
parent: null:
530
version: something
531
versioned_root: true
532
tree_references: true
4205.5.3 by Andrew Bennetts
Include oldpath in the the serialised delta
533
/\x00/old-root\x00TREE_ROOT\x00new-root-id\x00moved-root\x00dir
534
/dir\x00/old-root/dir\x00deep-id\x00TREE_ROOT\x00new-rev\x00dir
535
/dir/link\x00/old-root/dir/link\x00link-id\x00deep-id\x00new-rev\x00link\x00target
536
/old-file\x00None\x00deleted-id\x00\x00null:\x00deleted\x00\x00
537
/ref\x00/ref\x00ref-id\x00new-root-id\x00new-rev\x00tree\x00tree-reference-id
538
/under-old-root\x00/old-root/under-old-root\x00moved-id\x00TREE_ROOT\x00old-rev\x00file\x0030\x00\x00some-sha
539
None\x00/\x00new-root-id\x00\x00changed-in\x00dir
540
None\x00/configure\x00exec-id\x00new-root-id\x00old-rev\x00file\x0030\x00Y\x00some-sha
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
541
"""
6684.1.4 by Martin
Start making inventory tests pass on Python 3
542
        serialized = b''.join(lines)
543
        self.assertIsInstance(serialized, bytes)
4205.5.7 by Andrew Bennetts
Fix nits in spelling and naming.
544
        self.assertEqual(expected, serialized)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
545
546
547
class TestContent(TestCase):
4205.5.5 by Andrew Bennetts
Reorganise tests a little.
548
    """Test serialization of the content part of a line."""
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
549
550
    def test_dir(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
551
        entry = inventory.make_entry('directory', u'a dir', None)
552
        self.assertEqual(b'dir', inventory_delta._directory_content(entry))
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
553
554
    def test_file_0_short_sha(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
555
        file_entry = inventory.make_entry('file', u'a file', None, b'file-id')
556
        file_entry.text_sha1 = b''
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
557
        file_entry.text_size = 0
6684.1.4 by Martin
Start making inventory tests pass on Python 3
558
        self.assertEqual(b'file\x000\x00\x00',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
559
            inventory_delta._file_content(file_entry))
560
561
    def test_file_10_foo(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
562
        file_entry = inventory.make_entry('file', u'a file', None, b'file-id')
563
        file_entry.text_sha1 = b'foo'
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
564
        file_entry.text_size = 10
6684.1.4 by Martin
Start making inventory tests pass on Python 3
565
        self.assertEqual(b'file\x0010\x00\x00foo',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
566
            inventory_delta._file_content(file_entry))
567
568
    def test_file_executable(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
569
        file_entry = inventory.make_entry('file', u'a file', None, b'file-id')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
570
        file_entry.executable = True
6684.1.4 by Martin
Start making inventory tests pass on Python 3
571
        file_entry.text_sha1 = b'foo'
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
572
        file_entry.text_size = 10
6684.1.4 by Martin
Start making inventory tests pass on Python 3
573
        self.assertEqual(b'file\x0010\x00Y\x00foo',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
574
            inventory_delta._file_content(file_entry))
575
576
    def test_file_without_size(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
577
        file_entry = inventory.make_entry('file', u'a file', None, b'file-id')
578
        file_entry.text_sha1 = b'foo'
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
579
        self.assertRaises(InventoryDeltaError,
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
580
            inventory_delta._file_content, file_entry)
581
582
    def test_file_without_sha1(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
583
        file_entry = inventory.make_entry('file', u'a file', None, b'file-id')
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
584
        file_entry.text_size = 10
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
585
        self.assertRaises(InventoryDeltaError,
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
586
            inventory_delta._file_content, file_entry)
587
588
    def test_link_empty_target(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
589
        entry = inventory.make_entry('symlink', u'a link', None)
590
        entry.symlink_target = u''
591
        self.assertEqual(b'link\x00',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
592
            inventory_delta._link_content(entry))
593
594
    def test_link_unicode_target(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
595
        entry = inventory.make_entry('symlink', u'a link', None)
596
        entry.symlink_target = b' \xc3\xa5'.decode('utf8')
597
        self.assertEqual(b'link\x00 \xc3\xa5',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
598
            inventory_delta._link_content(entry))
599
600
    def test_link_space_target(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
601
        entry = inventory.make_entry('symlink', u'a link', None)
602
        entry.symlink_target = u' '
603
        self.assertEqual(b'link\x00 ',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
604
            inventory_delta._link_content(entry))
605
606
    def test_link_no_target(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
607
        entry = inventory.make_entry('symlink', u'a link', None)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
608
        self.assertRaises(InventoryDeltaError,
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
609
            inventory_delta._link_content, entry)
610
611
    def test_reference_null(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
612
        entry = inventory.make_entry('tree-reference', u'a tree', None)
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
613
        entry.reference_revision = NULL_REVISION
6684.1.4 by Martin
Start making inventory tests pass on Python 3
614
        self.assertEqual(b'tree\x00null:',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
615
            inventory_delta._reference_content(entry))
616
617
    def test_reference_revision(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
618
        entry = inventory.make_entry('tree-reference', u'a tree', None)
619
        entry.reference_revision = b'foo@\xc3\xa5b-lah'
620
        self.assertEqual(b'tree\x00foo@\xc3\xa5b-lah',
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
621
            inventory_delta._reference_content(entry))
622
623
    def test_reference_no_reference(self):
6684.1.4 by Martin
Start making inventory tests pass on Python 3
624
        entry = inventory.make_entry('tree-reference', u'a tree', None)
4476.3.78 by Andrew Bennetts
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.
625
        self.assertRaises(InventoryDeltaError,
4205.5.1 by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation.
626
            inventory_delta._reference_content, entry)