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