/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2005-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
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
#
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
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
#
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
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
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
16
7479.2.1 by Jelmer Vernooij
Drop python2 support.
17
from io import BytesIO
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
20
    errors,
4849.4.2 by John Arbash Meinel
Change from being a per-serializer attribute to being a per-repo attribute.
21
    fifo_cache,
6670.4.1 by Jelmer Vernooij
Update imports.
22
    )
23
from ..bzr import (
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
24
    inventory,
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
25
    xml6,
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
26
    xml7,
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
27
    xml8,
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
28
    )
6670.4.1 by Jelmer Vernooij
Update imports.
29
from ..bzr.inventory import Inventory
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from . import TestCase
6670.4.1 by Jelmer Vernooij
Update imports.
31
import breezy.bzr.xml5
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
32
6855.3.1 by Jelmer Vernooij
Several more fixes.
33
_revision_v5 = b"""<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
1183 by Martin Pool
- implement version 5 xml storage, and tests
34
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
35
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
2102.4.1 by John Arbash Meinel
Switch to using millisecond resolution in Revision XML
36
    timestamp="1125907235.212"
1183 by Martin Pool
- implement version 5 xml storage, and tests
37
    timezone="36000">
38
<message>- start splitting code for xml (de)serialization away from objects
39
  preparatory to supporting multiple formats by a single library
40
</message>
41
<parents>
42
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92"/>
43
</parents>
44
</revision>
45
"""
46
6855.3.1 by Jelmer Vernooij
Several more fixes.
47
_revision_v5_utc = b"""\
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
48
<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
49
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
50
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
2102.4.1 by John Arbash Meinel
Switch to using millisecond resolution in Revision XML
51
    timestamp="1125907235.212"
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
52
    timezone="0">
53
<message>- start splitting code for xml (de)serialization away from objects
54
  preparatory to supporting multiple formats by a single library
55
</message>
56
<parents>
57
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92"/>
58
</parents>
59
</revision>
60
"""
61
6855.3.1 by Jelmer Vernooij
Several more fixes.
62
_committed_inv_v5 = b"""<inventory>
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
63
<file file_id="bar-20050901064931-73b4b1138abc9cd2"
64
      name="bar" parent_id="TREE_ROOT"
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
65
      revision="mbp@foo-123123"
66
      text_sha1="A" text_size="1"/>
1183 by Martin Pool
- implement version 5 xml storage, and tests
67
<directory name="subdir"
68
           file_id="foo-20050801201819-4139aa4a272f4250"
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
69
           parent_id="TREE_ROOT"
1092.2.21 by Robert Collins
convert name_version to revision in inventory entries
70
           revision="mbp@foo-00"/>
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
71
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134"
72
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250"
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
73
      revision="mbp@foo-00"
74
      text_sha1="B" text_size="0"/>
1183 by Martin Pool
- implement version 5 xml storage, and tests
75
</inventory>
76
"""
77
6855.3.1 by Jelmer Vernooij
Several more fixes.
78
_basis_inv_v5 = b"""<inventory revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92">
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
79
<file file_id="bar-20050901064931-73b4b1138abc9cd2"
80
      name="bar" parent_id="TREE_ROOT"
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
81
      revision="mbp@foo-123123"/>
82
<directory name="subdir"
83
           file_id="foo-20050801201819-4139aa4a272f4250"
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
84
           parent_id="TREE_ROOT"
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
85
           revision="mbp@foo-00"/>
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
86
<file file_id="bar-20050824000535-6bc48cfad47ed134"
87
      name="bar" parent_id="foo-20050801201819-4139aa4a272f4250"
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
88
      revision="mbp@foo-00"/>
89
</inventory>
90
"""
91
1886.1.1 by John Arbash Meinel
Fix bug #47782,
92
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
93
# DO NOT REFLOW THIS. Its the exact revision we want.
6855.3.1 by Jelmer Vernooij
Several more fixes.
94
_expected_rev_v5 = b"""<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;" format="5" inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41" revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9" timestamp="1125907235.212" timezone="36000">
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
95
<message>- start splitting code for xml (de)serialization away from objects
96
  preparatory to supporting multiple formats by a single library
97
</message>
98
<parents>
99
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92" />
100
</parents>
101
</revision>
102
"""
103
104
105
# DO NOT REFLOW THIS. Its the exact inventory we want.
6855.3.1 by Jelmer Vernooij
Several more fixes.
106
_expected_inv_v5 = b"""<inventory format="5">
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
107
<file file_id="bar-20050901064931-73b4b1138abc9cd2" name="bar" revision="mbp@foo-123123" text_sha1="A" text_size="1" />
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
108
<directory file_id="foo-20050801201819-4139aa4a272f4250" name="subdir" revision="mbp@foo-00" />
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
109
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" text_sha1="B" text_size="0" />
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
110
</inventory>
111
"""
112
113
6855.3.1 by Jelmer Vernooij
Several more fixes.
114
_expected_inv_v5_root = b"""<inventory file_id="f&lt;" format="5" revision_id="mother!">
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
115
<file file_id="bar-20050901064931-73b4b1138abc9cd2" name="bar" parent_id="f&lt;" revision="mbp@foo-123123" text_sha1="A" text_size="1" />
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
116
<directory file_id="foo-20050801201819-4139aa4a272f4250" name="subdir" parent_id="f&lt;" revision="mbp@foo-00" />
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
117
<file executable="yes" file_id="bar-20050824000535-6bc48cfad47ed134" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" text_sha1="B" text_size="0" />
118
<symlink file_id="link-1" name="link" parent_id="foo-20050801201819-4139aa4a272f4250" revision="mbp@foo-00" symlink_target="a" />
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
119
</inventory>
120
"""
121
6855.3.1 by Jelmer Vernooij
Several more fixes.
122
_expected_inv_v6 = b"""<inventory format="6" revision_id="rev_outer">
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
123
<directory file_id="tree-root-321" name="" revision="rev_outer" />
124
<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
125
<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" text_sha1="A" text_size="1" />
126
<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" symlink_target="a" />
127
</inventory>
128
"""
129
6855.3.1 by Jelmer Vernooij
Several more fixes.
130
_expected_inv_v7 = b"""<inventory format="7" revision_id="rev_outer">
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
131
<directory file_id="tree-root-321" name="" revision="rev_outer" />
132
<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
133
<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" text_sha1="A" text_size="1" />
134
<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" symlink_target="a" />
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
135
<tree-reference file_id="nested-id" name="nested" parent_id="tree-root-321" revision="rev_outer" reference_revision="rev_inner" />
136
</inventory>
137
"""
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
138
6855.3.1 by Jelmer Vernooij
Several more fixes.
139
_expected_rev_v8 = b"""<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;" format="8" inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41" revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9" timestamp="1125907235.212" timezone="36000">
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
140
<message>- start splitting code for xml (de)serialization away from objects
141
  preparatory to supporting multiple formats by a single library
142
</message>
143
<parents>
144
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92" />
145
</parents>
146
</revision>
147
"""
148
6855.3.1 by Jelmer Vernooij
Several more fixes.
149
_expected_inv_v8 = b"""<inventory format="8" revision_id="rev_outer">
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
150
<directory file_id="tree-root-321" name="" revision="rev_outer" />
151
<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
152
<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" text_sha1="A" text_size="1" />
153
<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" symlink_target="a" />
154
</inventory>
155
"""
156
6855.3.1 by Jelmer Vernooij
Several more fixes.
157
_revision_utf8_v5 = b"""<revision committer="Erik B&#229;gfors &lt;erik@foo.net&gt;"
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
158
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
159
    revision_id="erik@b&#229;gfors-02"
160
    timestamp="1125907235.212"
161
    timezone="36000">
162
<message>Include &#181;nicode characters
163
</message>
164
<parents>
165
<revision_ref revision_id="erik@b&#229;gfors-01"/>
166
</parents>
167
</revision>
168
"""
169
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
170
_expected_rev_v8_complex = b"""<revision committer="Erik B&#229;gfors &lt;erik@foo.net&gt;" format="8" inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41" revision_id="erik@b&#229;gfors-02" timestamp="1125907235.212" timezone="36000">
171
<message>Include &#181;nicode characters
172
</message>
173
<parents>
174
<revision_ref revision_id="erik@b&#229;gfors-01" />
175
<revision_ref revision_id="erik@bagfors-02" />
176
</parents>
177
<properties><property name="bar" />
178
<property name="foo">this has a
179
newline in it</property>
180
</properties>
181
</revision>
182
"""
183
184
185
6855.3.1 by Jelmer Vernooij
Several more fixes.
186
_inventory_utf8_v5 = b"""<inventory file_id="TRE&#233;_ROOT" format="5"
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
187
                                   revision_id="erik@b&#229;gfors-02">
188
<file file_id="b&#229;r-01"
2294.1.9 by John Arbash Meinel
Minor performance improvement, use None as signal rather than ROOT_ID
189
      name="b&#229;r" parent_id="TRE&#233;_ROOT"
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
190
      revision="erik@b&#229;gfors-01"/>
191
<directory name="s&#181;bdir"
192
           file_id="s&#181;bdir-01"
2294.1.9 by John Arbash Meinel
Minor performance improvement, use None as signal rather than ROOT_ID
193
           parent_id="TRE&#233;_ROOT"
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
194
           revision="erik@b&#229;gfors-01"/>
195
<file executable="yes" file_id="b&#229;r-02"
196
      name="b&#229;r" parent_id="s&#181;bdir-01"
197
      revision="erik@b&#229;gfors-02"/>
198
</inventory>
199
"""
200
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
201
# Before revision_id was always stored as an attribute
6855.3.1 by Jelmer Vernooij
Several more fixes.
202
_inventory_v5a = b"""<inventory format="5">
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
203
</inventory>
204
"""
205
206
# Before revision_id was always stored as an attribute
6855.3.1 by Jelmer Vernooij
Several more fixes.
207
_inventory_v5b = b"""<inventory format="5" revision_id="a-rev-id">
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
208
</inventory>
209
"""
210
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
211
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
212
class TestSerializer(TestCase):
213
    """Test XML serialization"""
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
214
1183 by Martin Pool
- implement version 5 xml storage, and tests
215
    def test_unpack_revision_5(self):
216
        """Test unpacking a canned revision v5"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
217
        inp = BytesIO(_revision_v5)
6670.4.1 by Jelmer Vernooij
Update imports.
218
        rev = breezy.bzr.xml5.serializer_v5.read_revision(inp)
1183 by Martin Pool
- implement version 5 xml storage, and tests
219
        eq = self.assertEqual
220
        eq(rev.committer,
221
           "Martin Pool <mbp@sourcefrog.net>")
1313 by Martin Pool
- rename to Revision.parent_ids to avoid confusion with old usage
222
        eq(len(rev.parent_ids), 1)
1183 by Martin Pool
- implement version 5 xml storage, and tests
223
        eq(rev.timezone, 36000)
1313 by Martin Pool
- rename to Revision.parent_ids to avoid confusion with old usage
224
        eq(rev.parent_ids[0],
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
225
           b"mbp@sourcefrog.net-20050905063503-43948f59fa127d92")
1183 by Martin Pool
- implement version 5 xml storage, and tests
226
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
227
    def test_unpack_revision_5_utc(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
228
        inp = BytesIO(_revision_v5_utc)
6670.4.1 by Jelmer Vernooij
Update imports.
229
        rev = breezy.bzr.xml5.serializer_v5.read_revision(inp)
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
230
        eq = self.assertEqual
231
        eq(rev.committer,
232
           "Martin Pool <mbp@sourcefrog.net>")
233
        eq(len(rev.parent_ids), 1)
234
        eq(rev.timezone, 0)
235
        eq(rev.parent_ids[0],
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
236
           b"mbp@sourcefrog.net-20050905063503-43948f59fa127d92")
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
237
1183 by Martin Pool
- implement version 5 xml storage, and tests
238
    def test_unpack_inventory_5(self):
239
        """Unpack canned new-style inventory"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
240
        inp = BytesIO(_committed_inv_v5)
6670.4.1 by Jelmer Vernooij
Update imports.
241
        inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
1183 by Martin Pool
- implement version 5 xml storage, and tests
242
        eq = self.assertEqual
243
        eq(len(inv), 4)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
244
        ie = inv.get_entry(b'bar-20050824000535-6bc48cfad47ed134')
1183 by Martin Pool
- implement version 5 xml storage, and tests
245
        eq(ie.kind, 'file')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
246
        eq(ie.revision, b'mbp@foo-00')
1183 by Martin Pool
- implement version 5 xml storage, and tests
247
        eq(ie.name, 'bar')
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
248
        eq(inv.get_entry(ie.parent_id).kind, 'directory')
1184 by Martin Pool
- fix v5 packing of inventory entries
249
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
250
    def test_unpack_basis_inventory_5(self):
251
        """Unpack canned new-style inventory"""
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
252
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
253
            breezy.osutils.split_lines(_basis_inv_v5))
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
254
        eq = self.assertEqual
255
        eq(len(inv), 4)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
256
        eq(inv.revision_id,
257
           b'mbp@sourcefrog.net-20050905063503-43948f59fa127d92')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
258
        ie = inv.get_entry(b'bar-20050824000535-6bc48cfad47ed134')
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
259
        eq(ie.kind, 'file')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
260
        eq(ie.revision, b'mbp@foo-00')
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
261
        eq(ie.name, 'bar')
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
262
        eq(inv.get_entry(ie.parent_id).kind, 'directory')
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
263
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
264
    def test_unpack_inventory_5a(self):
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
265
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
266
            breezy.osutils.split_lines(_inventory_v5a), revision_id=b'test-rev-id')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
267
        self.assertEqual(b'test-rev-id', inv.root.revision)
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
268
4849.4.2 by John Arbash Meinel
Change from being a per-serializer attribute to being a per-repo attribute.
269
    def test_unpack_inventory_5a_cache_and_copy(self):
270
        # Passing an entry_cache should get populated with the objects
271
        # But the returned objects should be copies if return_from_cache is
272
        # False
273
        entry_cache = fifo_cache.FIFOCache()
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
274
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
275
            breezy.osutils.split_lines(_inventory_v5a), revision_id=b'test-rev-id',
4849.4.2 by John Arbash Meinel
Change from being a per-serializer attribute to being a per-repo attribute.
276
            entry_cache=entry_cache, return_from_cache=False)
277
        for entry in inv.iter_just_entries():
278
            key = (entry.file_id, entry.revision)
279
            if entry.file_id is inv.root.file_id:
280
                # The root id is inferred for xml v5
281
                self.assertFalse(key in entry_cache)
282
            else:
283
                self.assertIsNot(entry, entry_cache[key])
284
285
    def test_unpack_inventory_5a_cache_no_copy(self):
286
        # Passing an entry_cache should get populated with the objects
287
        # The returned objects should be exact if return_from_cache is
288
        # True
289
        entry_cache = fifo_cache.FIFOCache()
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
290
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
291
            breezy.osutils.split_lines(_inventory_v5a), revision_id=b'test-rev-id',
4849.4.2 by John Arbash Meinel
Change from being a per-serializer attribute to being a per-repo attribute.
292
            entry_cache=entry_cache, return_from_cache=True)
293
        for entry in inv.iter_just_entries():
294
            key = (entry.file_id, entry.revision)
295
            if entry.file_id is inv.root.file_id:
296
                # The root id is inferred for xml v5
297
                self.assertFalse(key in entry_cache)
298
            else:
299
                self.assertIs(entry, entry_cache[key])
300
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
301
    def test_unpack_inventory_5b(self):
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
302
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
303
            breezy.osutils.split_lines(_inventory_v5b), revision_id=b'test-rev-id')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
304
        self.assertEqual(b'a-rev-id', inv.root.revision)
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
305
1184 by Martin Pool
- fix v5 packing of inventory entries
306
    def test_repack_inventory_5(self):
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
307
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
308
            breezy.osutils.split_lines(_committed_inv_v5))
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
309
        outp = BytesIO()
6670.4.1 by Jelmer Vernooij
Update imports.
310
        breezy.bzr.xml5.serializer_v5.write_inventory(inv, outp)
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
311
        self.assertEqualDiff(_expected_inv_v5, outp.getvalue())
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
312
        inv2 = breezy.bzr.xml5.serializer_v5.read_inventory_from_lines(
313
            breezy.osutils.split_lines(outp.getvalue()))
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
314
        self.assertEqual(inv, inv2)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
315
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
316
    def assertRoundTrips(self, xml_string):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
317
        inp = BytesIO(xml_string)
6670.4.1 by Jelmer Vernooij
Update imports.
318
        inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
319
        outp = BytesIO()
6670.4.1 by Jelmer Vernooij
Update imports.
320
        breezy.bzr.xml5.serializer_v5.write_inventory(inv, outp)
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
321
        self.assertEqualDiff(xml_string, outp.getvalue())
6670.4.1 by Jelmer Vernooij
Update imports.
322
        lines = breezy.bzr.xml5.serializer_v5.write_inventory_to_lines(inv)
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
323
        outp.seek(0)
324
        self.assertEqual(outp.readlines(), lines)
7143.15.2 by Jelmer Vernooij
Run autopep8.
325
        inv2 = breezy.bzr.xml5.serializer_v5.read_inventory(
326
            BytesIO(outp.getvalue()))
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
327
        self.assertEqual(inv, inv2)
328
329
    def tests_serialize_inventory_v5_with_root(self):
330
        self.assertRoundTrips(_expected_inv_v5_root)
1185 by Martin Pool
- add xml round-trip test for revisions
331
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
332
    def check_repack_revision(self, txt):
333
        """Check that repacking a revision yields the same information"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
334
        inp = BytesIO(txt)
6670.4.1 by Jelmer Vernooij
Update imports.
335
        rev = breezy.bzr.xml5.serializer_v5.read_revision(inp)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
336
        outfile_contents = breezy.bzr.xml5.serializer_v5.write_revision_to_string(rev)
7143.15.2 by Jelmer Vernooij
Run autopep8.
337
        rev2 = breezy.bzr.xml5.serializer_v5.read_revision(
338
            BytesIO(outfile_contents))
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
339
        self.assertEqual(rev, rev2)
340
1185 by Martin Pool
- add xml round-trip test for revisions
341
    def test_repack_revision_5(self):
1185.16.123 by Martin Pool
Fix syntax of serializer_v5.pack_revision_to_string
342
        """Round-trip revision to XML v5"""
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
343
        self.check_repack_revision(_revision_v5)
344
345
    def test_repack_revision_5_utc(self):
346
        self.check_repack_revision(_revision_v5_utc)
1185 by Martin Pool
- add xml round-trip test for revisions
347
1185.16.123 by Martin Pool
Fix syntax of serializer_v5.pack_revision_to_string
348
    def test_pack_revision_5(self):
349
        """Pack revision to XML v5"""
350
        # fixed 20051025, revisions should have final newline
7143.15.2 by Jelmer Vernooij
Run autopep8.
351
        rev = breezy.bzr.xml5.serializer_v5.read_revision_from_string(
352
            _revision_v5)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
353
        outfile_contents = breezy.bzr.xml5.serializer_v5.write_revision_to_string(rev)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
354
        self.assertEqual(outfile_contents[-1:], b'\n')
7143.15.2 by Jelmer Vernooij
Run autopep8.
355
        self.assertEqualDiff(
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
356
            outfile_contents,
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
357
            b''.join(breezy.bzr.xml5.serializer_v5.write_revision_to_lines(rev)))
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
358
        self.assertEqualDiff(outfile_contents, _expected_rev_v5)
1886.1.1 by John Arbash Meinel
Fix bug #47782,
359
360
    def test_empty_property_value(self):
361
        """Create an empty property value check that it serializes correctly"""
6670.4.1 by Jelmer Vernooij
Update imports.
362
        s_v5 = breezy.bzr.xml5.serializer_v5
1886.1.1 by John Arbash Meinel
Fix bug #47782,
363
        rev = s_v5.read_revision_from_string(_revision_v5)
7143.15.2 by Jelmer Vernooij
Run autopep8.
364
        props = {'empty': '', 'one': 'one'}
1886.1.1 by John Arbash Meinel
Fix bug #47782,
365
        rev.properties = props
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
366
        txt = b''.join(s_v5.write_revision_to_lines(rev))
1886.1.1 by John Arbash Meinel
Fix bug #47782,
367
        new_rev = s_v5.read_revision_from_string(txt)
368
        self.assertEqual(props, new_rev.properties)
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
369
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
370
    def get_sample_inventory(self):
6855.4.1 by Jelmer Vernooij
Yet more bees.
371
        inv = Inventory(b'tree-root-321', revision_id=b'rev_outer')
372
        inv.add(inventory.InventoryFile(b'file-id', 'file', b'tree-root-321'))
373
        inv.add(inventory.InventoryDirectory(b'dir-id', 'dir',
374
                                             b'tree-root-321'))
375
        inv.add(inventory.InventoryLink(b'link-id', 'link', b'tree-root-321'))
6855.4.10 by Jelmer Vernooij
merge trunk
376
        inv.get_entry(b'tree-root-321').revision = b'rev_outer'
377
        inv.get_entry(b'dir-id').revision = b'rev_outer'
378
        inv.get_entry(b'file-id').revision = b'rev_outer'
6973.7.8 by Jelmer Vernooij
Fix more tests.
379
        inv.get_entry(b'file-id').text_sha1 = b'A'
6855.4.10 by Jelmer Vernooij
merge trunk
380
        inv.get_entry(b'file-id').text_size = 1
381
        inv.get_entry(b'link-id').revision = b'rev_outer'
382
        inv.get_entry(b'link-id').symlink_target = 'a'
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
383
        return inv
384
385
    def test_roundtrip_inventory_v7(self):
386
        inv = self.get_sample_inventory()
6855.4.1 by Jelmer Vernooij
Yet more bees.
387
        inv.add(inventory.TreeReference(b'nested-id', 'nested', b'tree-root-321',
388
                                        b'rev_outer', b'rev_inner'))
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
389
        lines = xml7.serializer_v7.write_inventory_to_lines(inv)
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
390
        self.assertEqualDiff(_expected_inv_v7, b''.join(lines))
391
        inv2 = xml7.serializer_v7.read_inventory_from_lines(lines)
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
392
        self.assertEqual(5, len(inv2))
393
        for path, ie in inv.iter_entries():
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
394
            self.assertEqual(ie, inv2.get_entry(ie.file_id))
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
395
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
396
    def test_roundtrip_inventory_v6(self):
397
        inv = self.get_sample_inventory()
398
        lines = xml6.serializer_v6.write_inventory_to_lines(inv)
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
399
        self.assertEqualDiff(_expected_inv_v6, b''.join(lines))
400
        inv2 = xml6.serializer_v6.read_inventory_from_lines(lines)
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
401
        self.assertEqual(4, len(inv2))
402
        for path, ie in inv.iter_entries():
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
403
            self.assertEqual(ie, inv2.get_entry(ie.file_id))
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
404
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
405
    def test_wrong_format_v7(self):
406
        """Can't accidentally open a file with wrong serializer"""
6670.4.1 by Jelmer Vernooij
Update imports.
407
        s_v6 = breezy.bzr.xml6.serializer_v6
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
408
        s_v7 = xml7.serializer_v7
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
409
        self.assertRaises(errors.UnexpectedInventoryFormat,
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
410
                          s_v7.read_inventory_from_lines,
411
                          breezy.osutils.split_lines(_expected_inv_v5))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
412
        self.assertRaises(errors.UnexpectedInventoryFormat,
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
413
                          s_v6.read_inventory_from_lines,
414
                          breezy.osutils.split_lines(_expected_inv_v7))
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
415
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
416
    def test_tree_reference(self):
6670.4.1 by Jelmer Vernooij
Update imports.
417
        s_v5 = breezy.bzr.xml5.serializer_v5
418
        s_v6 = breezy.bzr.xml6.serializer_v6
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
419
        s_v7 = xml7.serializer_v7
6855.4.1 by Jelmer Vernooij
Yet more bees.
420
        inv = Inventory(b'tree-root-321', revision_id=b'rev-outer')
421
        inv.root.revision = b'root-rev'
422
        inv.add(inventory.TreeReference(b'nested-id', 'nested', b'tree-root-321',
423
                                        b'rev-outer', b'rev-inner'))
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
424
        self.assertRaises(errors.UnsupportedInventoryKind,
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
425
                          s_v5.write_inventory_to_lines, inv)
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
426
        self.assertRaises(errors.UnsupportedInventoryKind,
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
427
                          s_v6.write_inventory_to_lines, inv)
428
        lines = s_v7.write_inventory_to_chunks(inv)
429
        inv2 = s_v7.read_inventory_from_lines(lines)
7143.15.2 by Jelmer Vernooij
Run autopep8.
430
        self.assertEqual(b'tree-root-321',
431
                         inv2.get_entry(b'nested-id').parent_id)
6855.4.10 by Jelmer Vernooij
merge trunk
432
        self.assertEqual(b'rev-outer', inv2.get_entry(b'nested-id').revision)
7143.15.2 by Jelmer Vernooij
Run autopep8.
433
        self.assertEqual(
434
            b'rev-inner', inv2.get_entry(b'nested-id').reference_revision)
2255.6.1 by Aaron Bentley
Merge from by-reference-trees
435
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
436
    def test_roundtrip_inventory_v8(self):
437
        inv = self.get_sample_inventory()
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
438
        lines = xml8.serializer_v8.write_inventory_to_lines(inv)
439
        inv2 = xml8.serializer_v8.read_inventory_from_lines(lines)
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
440
        self.assertEqual(4, len(inv2))
441
        for path, ie in inv.iter_entries():
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
442
            self.assertEqual(ie, inv2.get_entry(ie.file_id))
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
443
444
    def test_inventory_text_v8(self):
445
        inv = self.get_sample_inventory()
446
        lines = xml8.serializer_v8.write_inventory_to_lines(inv)
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
447
        self.assertEqualDiff(_expected_inv_v8, b''.join(lines))
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
448
3311.3.3 by Aaron Bentley
Handle format 5 revision
449
    def test_revision_text_v6(self):
450
        """Pack revision to XML v6"""
6670.4.1 by Jelmer Vernooij
Update imports.
451
        rev = breezy.bzr.xml6.serializer_v6.read_revision_from_string(
3311.3.3 by Aaron Bentley
Handle format 5 revision
452
            _expected_rev_v5)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
453
        serialized = breezy.bzr.xml6.serializer_v6.write_revision_to_lines(
7143.15.2 by Jelmer Vernooij
Run autopep8.
454
            rev)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
455
        self.assertEqualDiff(b''.join(serialized), _expected_rev_v5)
3311.3.3 by Aaron Bentley
Handle format 5 revision
456
457
    def test_revision_text_v7(self):
458
        """Pack revision to XML v7"""
6670.4.1 by Jelmer Vernooij
Update imports.
459
        rev = breezy.bzr.xml7.serializer_v7.read_revision_from_string(
3311.3.3 by Aaron Bentley
Handle format 5 revision
460
            _expected_rev_v5)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
461
        serialized = breezy.bzr.xml7.serializer_v7.write_revision_to_lines(
7143.15.2 by Jelmer Vernooij
Run autopep8.
462
            rev)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
463
        self.assertEqualDiff(b''.join(serialized), _expected_rev_v5)
3311.3.3 by Aaron Bentley
Handle format 5 revision
464
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
465
    def test_revision_text_v8(self):
466
        """Pack revision to XML v8"""
6670.4.1 by Jelmer Vernooij
Update imports.
467
        rev = breezy.bzr.xml8.serializer_v8.read_revision_from_string(
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
468
            _expected_rev_v8)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
469
        serialized = breezy.bzr.xml8.serializer_v8.write_revision_to_lines(
7143.15.2 by Jelmer Vernooij
Run autopep8.
470
            rev)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
471
        self.assertEqualDiff(b''.join(serialized), _expected_rev_v8)
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
472
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
473
    def test_revision_text_v8_complex(self):
474
        """Pack revision to XML v8"""
475
        rev = breezy.bzr.xml8.serializer_v8.read_revision_from_string(
476
            _expected_rev_v8_complex)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
477
        serialized = breezy.bzr.xml8.serializer_v8.write_revision_to_lines(
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
478
            rev)
7290.46.2 by Jelmer Vernooij
Drop Serializer.write_revision.
479
        self.assertEqualDiff(b''.join(serialized), _expected_rev_v8_complex)
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
480
2249.5.4 by John Arbash Meinel
When reading XML, always return utf-8 revision ids.
481
    def test_revision_ids_are_utf8(self):
482
        """Parsed revision_ids should all be utf-8 strings, not unicode."""
6670.4.1 by Jelmer Vernooij
Update imports.
483
        s_v5 = breezy.bzr.xml5.serializer_v5
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
484
        rev = s_v5.read_revision_from_string(_revision_utf8_v5)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
485
        self.assertEqual(b'erik@b\xc3\xa5gfors-02', rev.revision_id)
486
        self.assertIsInstance(rev.revision_id, bytes)
487
        self.assertEqual([b'erik@b\xc3\xa5gfors-01'], rev.parent_ids)
2249.5.4 by John Arbash Meinel
When reading XML, always return utf-8 revision ids.
488
        for parent_id in rev.parent_ids:
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
489
            self.assertIsInstance(parent_id, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
490
        self.assertEqual(u'Include \xb5nicode characters\n', rev.message)
7479.2.1 by Jelmer Vernooij
Drop python2 support.
491
        self.assertIsInstance(rev.message, str)
2249.5.4 by John Arbash Meinel
When reading XML, always return utf-8 revision ids.
492
493
        # ie.revision should either be None or a utf-8 revision id
7467.2.2 by Jelmer Vernooij
Use chunks rather than fulltexts for inventories where possible.
494
        inv = s_v5.read_inventory_from_lines(breezy.osutils.split_lines(_inventory_utf8_v5))
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
495
        rev_id_1 = u'erik@b\xe5gfors-01'.encode('utf8')
496
        rev_id_2 = u'erik@b\xe5gfors-02'.encode('utf8')
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
497
        fid_root = u'TRE\xe9_ROOT'.encode('utf8')
498
        fid_bar1 = u'b\xe5r-01'.encode('utf8')
499
        fid_sub = u's\xb5bdir-01'.encode('utf8')
500
        fid_bar2 = u'b\xe5r-02'.encode('utf8')
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
501
        expected = [(u'', fid_root, None, rev_id_2),
2294.1.6 by John Arbash Meinel
Include parent_id checks in the xml serializer tests.
502
                    (u'b\xe5r', fid_bar1, fid_root, rev_id_1),
503
                    (u's\xb5bdir', fid_sub, fid_root, rev_id_1),
504
                    (u's\xb5bdir/b\xe5r', fid_bar2, fid_sub, rev_id_2),
7143.15.2 by Jelmer Vernooij
Run autopep8.
505
                    ]
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
506
        self.assertEqual(rev_id_2, inv.revision_id)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
507
        self.assertIsInstance(inv.revision_id, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
508
509
        actual = list(inv.iter_entries_by_dir())
2294.1.6 by John Arbash Meinel
Include parent_id checks in the xml serializer tests.
510
        for ((exp_path, exp_file_id, exp_parent_id, exp_rev_id),
511
             (act_path, act_ie)) in zip(expected, actual):
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
512
            self.assertEqual(exp_path, act_path)
7479.2.1 by Jelmer Vernooij
Drop python2 support.
513
            self.assertIsInstance(act_path, str)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
514
            self.assertEqual(exp_file_id, act_ie.file_id)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
515
            self.assertIsInstance(act_ie.file_id, bytes)
2294.1.6 by John Arbash Meinel
Include parent_id checks in the xml serializer tests.
516
            self.assertEqual(exp_parent_id, act_ie.parent_id)
517
            if exp_parent_id is not None:
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
518
                self.assertIsInstance(act_ie.parent_id, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
519
            self.assertEqual(exp_rev_id, act_ie.revision)
520
            if exp_rev_id is not None:
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
521
                self.assertIsInstance(act_ie.revision, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
522
523
        self.assertEqual(len(expected), len(actual))
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
524
7122.5.2 by Jelmer Vernooij
Properly format UnexpectedInventoryFormat errors.
525
    def test_serialization_error(self):
526
        s_v5 = breezy.bzr.xml5.serializer_v5
527
        e = self.assertRaises(
528
            errors.UnexpectedInventoryFormat,
7467.2.1 by Jelmer Vernooij
Replace write_inventory_to_string with write_inventory_to_chunks.
529
            s_v5.read_inventory_from_lines, [b"<Notquitexml"])
7122.5.2 by Jelmer Vernooij
Properly format UnexpectedInventoryFormat errors.
530
        self.assertEqual(str(e), "unclosed token: line 1, column 0")
531
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
532
533
class TestEncodeAndEscape(TestCase):
534
    """Whitebox testing of the _encode_and_escape function."""
535
536
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
537
        super(TestEncodeAndEscape, self).setUp()
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
538
        # Keep the cache clear before and after the test
6670.4.1 by Jelmer Vernooij
Update imports.
539
        breezy.bzr.xml_serializer._clear_cache()
540
        self.addCleanup(breezy.bzr.xml_serializer._clear_cache)
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
541
542
    def test_simple_ascii(self):
543
        # _encode_and_escape always appends a final ", because these parameters
544
        # are being used in xml attributes, and by returning it now, we have to
545
        # do fewer string operations later.
6670.4.1 by Jelmer Vernooij
Update imports.
546
        val = breezy.bzr.xml_serializer.encode_and_escape('foo bar')
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
547
        self.assertEqual(b'foo bar', val)
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
548
        # The second time should be cached
6670.4.1 by Jelmer Vernooij
Update imports.
549
        val2 = breezy.bzr.xml_serializer.encode_and_escape('foo bar')
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
550
        self.assertIs(val2, val)
551
552
    def test_ascii_with_xml(self):
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
553
        self.assertEqual(b'&amp;&apos;&quot;&lt;&gt;',
6670.4.1 by Jelmer Vernooij
Update imports.
554
                         breezy.bzr.xml_serializer.encode_and_escape('&\'"<>'))
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
555
556
    def test_utf8_with_xml(self):
557
        # u'\xb5\xe5&\u062c'
6973.4.2 by Jelmer Vernooij
Port breezy.bzr.xml* to python3.
558
        utf8_str = b'\xc2\xb5\xc3\xa5&\xd8\xac'
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
559
        self.assertEqual(b'&#181;&#229;&amp;&#1580;',
6670.4.1 by Jelmer Vernooij
Update imports.
560
                         breezy.bzr.xml_serializer.encode_and_escape(utf8_str))
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
561
562
    def test_unicode(self):
563
        uni_str = u'\xb5\xe5&\u062c'
7290.46.1 by Jelmer Vernooij
Add custom generator for XML revisions.
564
        self.assertEqual(b'&#181;&#229;&amp;&#1580;',
6670.4.1 by Jelmer Vernooij
Update imports.
565
                         breezy.bzr.xml_serializer.encode_and_escape(uni_str))
5671.2.4 by Jelmer Vernooij
Fix unescape_xml test.
566
567
568
class TestMisc(TestCase):
569
570
    def test_unescape_xml(self):
571
        """We get some kind of error when malformed entities are passed"""
6973.7.10 by Jelmer Vernooij
More fixes.
572
        self.assertRaises(KeyError, breezy.bzr.xml8._unescape_xml, b'foo&bar;')