/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
6855.3.1 by Jelmer Vernooij
Several more fixes.
173
_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,
174
                                   revision_id="erik@b&#229;gfors-02">
175
<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
176
      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,
177
      revision="erik@b&#229;gfors-01"/>
178
<directory name="s&#181;bdir"
179
           file_id="s&#181;bdir-01"
2294.1.9 by John Arbash Meinel
Minor performance improvement, use None as signal rather than ROOT_ID
180
           parent_id="TRE&#233;_ROOT"
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
181
           revision="erik@b&#229;gfors-01"/>
182
<file executable="yes" file_id="b&#229;r-02"
183
      name="b&#229;r" parent_id="s&#181;bdir-01"
184
      revision="erik@b&#229;gfors-02"/>
185
</inventory>
186
"""
187
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
188
# Before revision_id was always stored as an attribute
6855.3.1 by Jelmer Vernooij
Several more fixes.
189
_inventory_v5a = b"""<inventory format="5">
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
190
</inventory>
191
"""
192
193
# Before revision_id was always stored as an attribute
6855.3.1 by Jelmer Vernooij
Several more fixes.
194
_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
195
</inventory>
196
"""
197
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
198
1181 by Martin Pool
- add test for deserialization from a canned XML inventory
199
class TestSerializer(TestCase):
200
    """Test XML serialization"""
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
201
1183 by Martin Pool
- implement version 5 xml storage, and tests
202
    def test_unpack_revision_5(self):
203
        """Test unpacking a canned revision v5"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
204
        inp = BytesIO(_revision_v5)
6670.4.1 by Jelmer Vernooij
Update imports.
205
        rev = breezy.bzr.xml5.serializer_v5.read_revision(inp)
1183 by Martin Pool
- implement version 5 xml storage, and tests
206
        eq = self.assertEqual
207
        eq(rev.committer,
208
           "Martin Pool <mbp@sourcefrog.net>")
1313 by Martin Pool
- rename to Revision.parent_ids to avoid confusion with old usage
209
        eq(len(rev.parent_ids), 1)
1183 by Martin Pool
- implement version 5 xml storage, and tests
210
        eq(rev.timezone, 36000)
1313 by Martin Pool
- rename to Revision.parent_ids to avoid confusion with old usage
211
        eq(rev.parent_ids[0],
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
212
           b"mbp@sourcefrog.net-20050905063503-43948f59fa127d92")
1183 by Martin Pool
- implement version 5 xml storage, and tests
213
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
214
    def test_unpack_revision_5_utc(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
215
        inp = BytesIO(_revision_v5_utc)
6670.4.1 by Jelmer Vernooij
Update imports.
216
        rev = breezy.bzr.xml5.serializer_v5.read_revision(inp)
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
217
        eq = self.assertEqual
218
        eq(rev.committer,
219
           "Martin Pool <mbp@sourcefrog.net>")
220
        eq(len(rev.parent_ids), 1)
221
        eq(rev.timezone, 0)
222
        eq(rev.parent_ids[0],
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
223
           b"mbp@sourcefrog.net-20050905063503-43948f59fa127d92")
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
224
1183 by Martin Pool
- implement version 5 xml storage, and tests
225
    def test_unpack_inventory_5(self):
226
        """Unpack canned new-style inventory"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
227
        inp = BytesIO(_committed_inv_v5)
6670.4.1 by Jelmer Vernooij
Update imports.
228
        inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
1183 by Martin Pool
- implement version 5 xml storage, and tests
229
        eq = self.assertEqual
230
        eq(len(inv), 4)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
231
        ie = inv.get_entry(b'bar-20050824000535-6bc48cfad47ed134')
1183 by Martin Pool
- implement version 5 xml storage, and tests
232
        eq(ie.kind, 'file')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
233
        eq(ie.revision, b'mbp@foo-00')
1183 by Martin Pool
- implement version 5 xml storage, and tests
234
        eq(ie.name, 'bar')
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
235
        eq(inv.get_entry(ie.parent_id).kind, 'directory')
1184 by Martin Pool
- fix v5 packing of inventory entries
236
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
237
    def test_unpack_basis_inventory_5(self):
238
        """Unpack canned new-style inventory"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
239
        inp = BytesIO(_basis_inv_v5)
6670.4.1 by Jelmer Vernooij
Update imports.
240
        inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
241
        eq = self.assertEqual
242
        eq(len(inv), 4)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
243
        eq(inv.revision_id,
244
           b'mbp@sourcefrog.net-20050905063503-43948f59fa127d92')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
245
        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.
246
        eq(ie.kind, 'file')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
247
        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.
248
        eq(ie.name, 'bar')
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
249
        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.
250
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
251
    def test_unpack_inventory_5a(self):
6670.4.1 by Jelmer Vernooij
Update imports.
252
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string(
7143.15.2 by Jelmer Vernooij
Run autopep8.
253
            _inventory_v5a, revision_id=b'test-rev-id')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
254
        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
255
4849.4.2 by John Arbash Meinel
Change from being a per-serializer attribute to being a per-repo attribute.
256
    def test_unpack_inventory_5a_cache_and_copy(self):
257
        # Passing an entry_cache should get populated with the objects
258
        # But the returned objects should be copies if return_from_cache is
259
        # False
260
        entry_cache = fifo_cache.FIFOCache()
6670.4.1 by Jelmer Vernooij
Update imports.
261
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string(
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
262
            _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.
263
            entry_cache=entry_cache, return_from_cache=False)
264
        for entry in inv.iter_just_entries():
265
            key = (entry.file_id, entry.revision)
266
            if entry.file_id is inv.root.file_id:
267
                # The root id is inferred for xml v5
268
                self.assertFalse(key in entry_cache)
269
            else:
270
                self.assertIsNot(entry, entry_cache[key])
271
272
    def test_unpack_inventory_5a_cache_no_copy(self):
273
        # Passing an entry_cache should get populated with the objects
274
        # The returned objects should be exact if return_from_cache is
275
        # True
276
        entry_cache = fifo_cache.FIFOCache()
6670.4.1 by Jelmer Vernooij
Update imports.
277
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string(
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
278
            _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=True)
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.assertIs(entry, entry_cache[key])
287
2917.2.1 by John Arbash Meinel
Fix bug #152360. The xml5 serializer should be using
288
    def test_unpack_inventory_5b(self):
6670.4.1 by Jelmer Vernooij
Update imports.
289
        inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string(
7143.15.2 by Jelmer Vernooij
Run autopep8.
290
            _inventory_v5b, revision_id=b'test-rev-id')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
291
        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
292
1184 by Martin Pool
- fix v5 packing of inventory entries
293
    def test_repack_inventory_5(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
294
        inp = BytesIO(_committed_inv_v5)
6670.4.1 by Jelmer Vernooij
Update imports.
295
        inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
296
        outp = BytesIO()
6670.4.1 by Jelmer Vernooij
Update imports.
297
        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
298
        self.assertEqualDiff(_expected_inv_v5, outp.getvalue())
7143.15.2 by Jelmer Vernooij
Run autopep8.
299
        inv2 = breezy.bzr.xml5.serializer_v5.read_inventory(
300
            BytesIO(outp.getvalue()))
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
301
        self.assertEqual(inv, inv2)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
302
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
303
    def assertRoundTrips(self, xml_string):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
304
        inp = BytesIO(xml_string)
6670.4.1 by Jelmer Vernooij
Update imports.
305
        inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
306
        outp = BytesIO()
6670.4.1 by Jelmer Vernooij
Update imports.
307
        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
308
        self.assertEqualDiff(xml_string, outp.getvalue())
6670.4.1 by Jelmer Vernooij
Update imports.
309
        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.
310
        outp.seek(0)
311
        self.assertEqual(outp.readlines(), lines)
7143.15.2 by Jelmer Vernooij
Run autopep8.
312
        inv2 = breezy.bzr.xml5.serializer_v5.read_inventory(
313
            BytesIO(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)
315
316
    def tests_serialize_inventory_v5_with_root(self):
317
        self.assertRoundTrips(_expected_inv_v5_root)
1185 by Martin Pool
- add xml round-trip test for revisions
318
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
319
    def check_repack_revision(self, txt):
320
        """Check that repacking a revision yields the same information"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
321
        inp = BytesIO(txt)
6670.4.1 by Jelmer Vernooij
Update imports.
322
        rev = breezy.bzr.xml5.serializer_v5.read_revision(inp)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
323
        outp = BytesIO()
6670.4.1 by Jelmer Vernooij
Update imports.
324
        breezy.bzr.xml5.serializer_v5.write_revision(rev, outp)
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
325
        outfile_contents = outp.getvalue()
7143.15.2 by Jelmer Vernooij
Run autopep8.
326
        rev2 = breezy.bzr.xml5.serializer_v5.read_revision(
327
            BytesIO(outfile_contents))
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
328
        self.assertEqual(rev, rev2)
329
1185 by Martin Pool
- add xml round-trip test for revisions
330
    def test_repack_revision_5(self):
1185.16.123 by Martin Pool
Fix syntax of serializer_v5.pack_revision_to_string
331
        """Round-trip revision to XML v5"""
1913.1.2 by John Arbash Meinel
Add direct tests to xml serializer
332
        self.check_repack_revision(_revision_v5)
333
334
    def test_repack_revision_5_utc(self):
335
        self.check_repack_revision(_revision_v5_utc)
1185 by Martin Pool
- add xml round-trip test for revisions
336
1185.16.123 by Martin Pool
Fix syntax of serializer_v5.pack_revision_to_string
337
    def test_pack_revision_5(self):
338
        """Pack revision to XML v5"""
339
        # fixed 20051025, revisions should have final newline
7143.15.2 by Jelmer Vernooij
Run autopep8.
340
        rev = breezy.bzr.xml5.serializer_v5.read_revision_from_string(
341
            _revision_v5)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
342
        outp = BytesIO()
6670.4.1 by Jelmer Vernooij
Update imports.
343
        breezy.bzr.xml5.serializer_v5.write_revision(rev, outp)
1185.16.123 by Martin Pool
Fix syntax of serializer_v5.pack_revision_to_string
344
        outfile_contents = outp.getvalue()
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
345
        self.assertEqual(outfile_contents[-1:], b'\n')
7143.15.2 by Jelmer Vernooij
Run autopep8.
346
        self.assertEqualDiff(
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
347
            outfile_contents,
348
            breezy.bzr.xml5.serializer_v5.write_revision_to_string(rev))
1934.1.3 by John Arbash Meinel
[merge] robert's custom XML serializer, and cleanup for benchmarks and iter_entries() differences
349
        self.assertEqualDiff(outfile_contents, _expected_rev_v5)
1886.1.1 by John Arbash Meinel
Fix bug #47782,
350
351
    def test_empty_property_value(self):
352
        """Create an empty property value check that it serializes correctly"""
6670.4.1 by Jelmer Vernooij
Update imports.
353
        s_v5 = breezy.bzr.xml5.serializer_v5
1886.1.1 by John Arbash Meinel
Fix bug #47782,
354
        rev = s_v5.read_revision_from_string(_revision_v5)
7143.15.2 by Jelmer Vernooij
Run autopep8.
355
        props = {'empty': '', 'one': 'one'}
1886.1.1 by John Arbash Meinel
Fix bug #47782,
356
        rev.properties = props
357
        txt = s_v5.write_revision_to_string(rev)
358
        new_rev = s_v5.read_revision_from_string(txt)
359
        self.assertEqual(props, new_rev.properties)
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
360
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
361
    def get_sample_inventory(self):
6855.4.1 by Jelmer Vernooij
Yet more bees.
362
        inv = Inventory(b'tree-root-321', revision_id=b'rev_outer')
363
        inv.add(inventory.InventoryFile(b'file-id', 'file', b'tree-root-321'))
364
        inv.add(inventory.InventoryDirectory(b'dir-id', 'dir',
365
                                             b'tree-root-321'))
366
        inv.add(inventory.InventoryLink(b'link-id', 'link', b'tree-root-321'))
6855.4.10 by Jelmer Vernooij
merge trunk
367
        inv.get_entry(b'tree-root-321').revision = b'rev_outer'
368
        inv.get_entry(b'dir-id').revision = b'rev_outer'
369
        inv.get_entry(b'file-id').revision = b'rev_outer'
6973.7.8 by Jelmer Vernooij
Fix more tests.
370
        inv.get_entry(b'file-id').text_sha1 = b'A'
6855.4.10 by Jelmer Vernooij
merge trunk
371
        inv.get_entry(b'file-id').text_size = 1
372
        inv.get_entry(b'link-id').revision = b'rev_outer'
373
        inv.get_entry(b'link-id').symlink_target = 'a'
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
374
        return inv
375
376
    def test_roundtrip_inventory_v7(self):
377
        inv = self.get_sample_inventory()
6855.4.1 by Jelmer Vernooij
Yet more bees.
378
        inv.add(inventory.TreeReference(b'nested-id', 'nested', b'tree-root-321',
379
                                        b'rev_outer', b'rev_inner'))
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
380
        txt = xml7.serializer_v7.write_inventory_to_string(inv)
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
381
        lines = xml7.serializer_v7.write_inventory_to_lines(inv)
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
382
        self.assertEqual(breezy.osutils.split_lines(txt), lines)
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
383
        self.assertEqualDiff(_expected_inv_v7, txt)
384
        inv2 = xml7.serializer_v7.read_inventory_from_string(txt)
385
        self.assertEqual(5, len(inv2))
386
        for path, ie in inv.iter_entries():
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
387
            self.assertEqual(ie, inv2.get_entry(ie.file_id))
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
388
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
389
    def test_roundtrip_inventory_v6(self):
390
        inv = self.get_sample_inventory()
391
        txt = xml6.serializer_v6.write_inventory_to_string(inv)
392
        lines = xml6.serializer_v6.write_inventory_to_lines(inv)
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
393
        self.assertEqual(breezy.osutils.split_lines(txt), lines)
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
394
        self.assertEqualDiff(_expected_inv_v6, txt)
395
        inv2 = xml6.serializer_v6.read_inventory_from_string(txt)
396
        self.assertEqual(4, len(inv2))
397
        for path, ie in inv.iter_entries():
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
398
            self.assertEqual(ie, inv2.get_entry(ie.file_id))
4476.3.27 by Andrew Bennetts
Trivial improvement to test coverage in test_xml.
399
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
400
    def test_wrong_format_v7(self):
401
        """Can't accidentally open a file with wrong serializer"""
6670.4.1 by Jelmer Vernooij
Update imports.
402
        s_v6 = breezy.bzr.xml6.serializer_v6
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
403
        s_v7 = xml7.serializer_v7
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
404
        self.assertRaises(errors.UnexpectedInventoryFormat,
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
405
                          s_v7.read_inventory_from_string, _expected_inv_v5)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
406
        self.assertRaises(errors.UnexpectedInventoryFormat,
2100.3.2 by Aaron Bentley
Add tests for format 7, enforce number
407
                          s_v6.read_inventory_from_string, _expected_inv_v7)
408
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
409
    def test_tree_reference(self):
6670.4.1 by Jelmer Vernooij
Update imports.
410
        s_v5 = breezy.bzr.xml5.serializer_v5
411
        s_v6 = breezy.bzr.xml6.serializer_v6
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
412
        s_v7 = xml7.serializer_v7
6855.4.1 by Jelmer Vernooij
Yet more bees.
413
        inv = Inventory(b'tree-root-321', revision_id=b'rev-outer')
414
        inv.root.revision = b'root-rev'
415
        inv.add(inventory.TreeReference(b'nested-id', 'nested', b'tree-root-321',
416
                                        b'rev-outer', b'rev-inner'))
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
417
        self.assertRaises(errors.UnsupportedInventoryKind,
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
418
                          s_v5.write_inventory_to_string, inv)
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
419
        self.assertRaises(errors.UnsupportedInventoryKind,
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
420
                          s_v6.write_inventory_to_string, inv)
421
        txt = s_v7.write_inventory_to_string(inv)
2817.2.1 by Robert Collins
* Inventory serialisation no longer double-sha's the content.
422
        lines = s_v7.write_inventory_to_lines(inv)
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
423
        self.assertEqual(breezy.osutils.split_lines(txt), lines)
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
424
        inv2 = s_v7.read_inventory_from_string(txt)
7143.15.2 by Jelmer Vernooij
Run autopep8.
425
        self.assertEqual(b'tree-root-321',
426
                         inv2.get_entry(b'nested-id').parent_id)
6855.4.10 by Jelmer Vernooij
merge trunk
427
        self.assertEqual(b'rev-outer', inv2.get_entry(b'nested-id').revision)
7143.15.2 by Jelmer Vernooij
Run autopep8.
428
        self.assertEqual(
429
            b'rev-inner', inv2.get_entry(b'nested-id').reference_revision)
2255.6.1 by Aaron Bentley
Merge from by-reference-trees
430
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
431
    def test_roundtrip_inventory_v8(self):
432
        inv = self.get_sample_inventory()
433
        txt = xml8.serializer_v8.write_inventory_to_string(inv)
434
        inv2 = xml8.serializer_v8.read_inventory_from_string(txt)
435
        self.assertEqual(4, len(inv2))
436
        for path, ie in inv.iter_entries():
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
437
            self.assertEqual(ie, inv2.get_entry(ie.file_id))
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
438
439
    def test_inventory_text_v8(self):
440
        inv = self.get_sample_inventory()
441
        txt = xml8.serializer_v8.write_inventory_to_string(inv)
442
        lines = xml8.serializer_v8.write_inventory_to_lines(inv)
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
443
        self.assertEqual(breezy.osutils.split_lines(txt), lines)
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
444
        self.assertEqualDiff(_expected_inv_v8, txt)
445
3311.3.3 by Aaron Bentley
Handle format 5 revision
446
    def test_revision_text_v6(self):
447
        """Pack revision to XML v6"""
6670.4.1 by Jelmer Vernooij
Update imports.
448
        rev = breezy.bzr.xml6.serializer_v6.read_revision_from_string(
3311.3.3 by Aaron Bentley
Handle format 5 revision
449
            _expected_rev_v5)
7143.15.2 by Jelmer Vernooij
Run autopep8.
450
        serialized = breezy.bzr.xml6.serializer_v6.write_revision_to_string(
451
            rev)
3311.3.3 by Aaron Bentley
Handle format 5 revision
452
        self.assertEqualDiff(serialized, _expected_rev_v5)
453
454
    def test_revision_text_v7(self):
455
        """Pack revision to XML v7"""
6670.4.1 by Jelmer Vernooij
Update imports.
456
        rev = breezy.bzr.xml7.serializer_v7.read_revision_from_string(
3311.3.3 by Aaron Bentley
Handle format 5 revision
457
            _expected_rev_v5)
7143.15.2 by Jelmer Vernooij
Run autopep8.
458
        serialized = breezy.bzr.xml7.serializer_v7.write_revision_to_string(
459
            rev)
3311.3.3 by Aaron Bentley
Handle format 5 revision
460
        self.assertEqualDiff(serialized, _expected_rev_v5)
461
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
462
    def test_revision_text_v8(self):
463
        """Pack revision to XML v8"""
6670.4.1 by Jelmer Vernooij
Update imports.
464
        rev = breezy.bzr.xml8.serializer_v8.read_revision_from_string(
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
465
            _expected_rev_v8)
7143.15.2 by Jelmer Vernooij
Run autopep8.
466
        serialized = breezy.bzr.xml8.serializer_v8.write_revision_to_string(
467
            rev)
3311.3.2 by Aaron Bentley
Implement version numbers for format 8
468
        self.assertEqualDiff(serialized, _expected_rev_v8)
469
2249.5.4 by John Arbash Meinel
When reading XML, always return utf-8 revision ids.
470
    def test_revision_ids_are_utf8(self):
471
        """Parsed revision_ids should all be utf-8 strings, not unicode."""
6670.4.1 by Jelmer Vernooij
Update imports.
472
        s_v5 = breezy.bzr.xml5.serializer_v5
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
473
        rev = s_v5.read_revision_from_string(_revision_utf8_v5)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
474
        self.assertEqual(b'erik@b\xc3\xa5gfors-02', rev.revision_id)
475
        self.assertIsInstance(rev.revision_id, bytes)
476
        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.
477
        for parent_id in rev.parent_ids:
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
478
            self.assertIsInstance(parent_id, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
479
        self.assertEqual(u'Include \xb5nicode characters\n', rev.message)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
480
        self.assertIsInstance(rev.message, text_type)
2249.5.4 by John Arbash Meinel
When reading XML, always return utf-8 revision ids.
481
482
        # ie.revision should either be None or a utf-8 revision id
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
483
        inv = s_v5.read_inventory_from_string(_inventory_utf8_v5)
484
        rev_id_1 = u'erik@b\xe5gfors-01'.encode('utf8')
485
        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
486
        fid_root = u'TRE\xe9_ROOT'.encode('utf8')
487
        fid_bar1 = u'b\xe5r-01'.encode('utf8')
488
        fid_sub = u's\xb5bdir-01'.encode('utf8')
489
        fid_bar2 = u'b\xe5r-02'.encode('utf8')
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
490
        expected = [(u'', fid_root, None, rev_id_2),
2294.1.6 by John Arbash Meinel
Include parent_id checks in the xml serializer tests.
491
                    (u'b\xe5r', fid_bar1, fid_root, rev_id_1),
492
                    (u's\xb5bdir', fid_sub, fid_root, rev_id_1),
493
                    (u's\xb5bdir/b\xe5r', fid_bar2, fid_sub, rev_id_2),
7143.15.2 by Jelmer Vernooij
Run autopep8.
494
                    ]
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
495
        self.assertEqual(rev_id_2, inv.revision_id)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
496
        self.assertIsInstance(inv.revision_id, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
497
498
        actual = list(inv.iter_entries_by_dir())
2294.1.6 by John Arbash Meinel
Include parent_id checks in the xml serializer tests.
499
        for ((exp_path, exp_file_id, exp_parent_id, exp_rev_id),
500
             (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,
501
            self.assertEqual(exp_path, act_path)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
502
            self.assertIsInstance(act_path, text_type)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
503
            self.assertEqual(exp_file_id, act_ie.file_id)
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
504
            self.assertIsInstance(act_ie.file_id, bytes)
2294.1.6 by John Arbash Meinel
Include parent_id checks in the xml serializer tests.
505
            self.assertEqual(exp_parent_id, act_ie.parent_id)
506
            if exp_parent_id is not None:
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
507
                self.assertIsInstance(act_ie.parent_id, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
508
            self.assertEqual(exp_rev_id, act_ie.revision)
509
            if exp_rev_id is not None:
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
510
                self.assertIsInstance(act_ie.revision, bytes)
2294.1.5 by John Arbash Meinel
Fix Inventory.iter_entries_by_dir to return Unicode paths,
511
512
        self.assertEqual(len(expected), len(actual))
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
513
514
515
class TestEncodeAndEscape(TestCase):
516
    """Whitebox testing of the _encode_and_escape function."""
517
518
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
519
        super(TestEncodeAndEscape, self).setUp()
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
520
        # Keep the cache clear before and after the test
6670.4.1 by Jelmer Vernooij
Update imports.
521
        breezy.bzr.xml_serializer._clear_cache()
522
        self.addCleanup(breezy.bzr.xml_serializer._clear_cache)
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
523
524
    def test_simple_ascii(self):
525
        # _encode_and_escape always appends a final ", because these parameters
526
        # are being used in xml attributes, and by returning it now, we have to
527
        # do fewer string operations later.
6670.4.1 by Jelmer Vernooij
Update imports.
528
        val = breezy.bzr.xml_serializer.encode_and_escape('foo bar')
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
529
        self.assertEqual(b'foo bar"', val)
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
530
        # The second time should be cached
6670.4.1 by Jelmer Vernooij
Update imports.
531
        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
532
        self.assertIs(val2, val)
533
534
    def test_ascii_with_xml(self):
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
535
        self.assertEqual(b'&amp;&apos;&quot;&lt;&gt;"',
6670.4.1 by Jelmer Vernooij
Update imports.
536
                         breezy.bzr.xml_serializer.encode_and_escape('&\'"<>'))
2249.5.10 by John Arbash Meinel
Make sure xml5 can handle unicode or utf8 strings
537
538
    def test_utf8_with_xml(self):
539
        # u'\xb5\xe5&\u062c'
6973.4.2 by Jelmer Vernooij
Port breezy.bzr.xml* to python3.
540
        utf8_str = b'\xc2\xb5\xc3\xa5&\xd8\xac'
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
541
        self.assertEqual(b'&#181;&#229;&amp;&#1580;"',
6670.4.1 by Jelmer Vernooij
Update imports.
542
                         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
543
544
    def test_unicode(self):
545
        uni_str = u'\xb5\xe5&\u062c'
6973.4.1 by Jelmer Vernooij
Fix a bunch of tests.
546
        self.assertEqual(b'&#181;&#229;&amp;&#1580;"',
6670.4.1 by Jelmer Vernooij
Update imports.
547
                         breezy.bzr.xml_serializer.encode_and_escape(uni_str))
5671.2.4 by Jelmer Vernooij
Fix unescape_xml test.
548
549
550
class TestMisc(TestCase):
551
552
    def test_unescape_xml(self):
553
        """We get some kind of error when malformed entities are passed"""
6973.7.10 by Jelmer Vernooij
More fixes.
554
        self.assertRaises(KeyError, breezy.bzr.xml8._unescape_xml, b'foo&bar;')