/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.7.83 by John Arbash Meinel
Update some obvious copyright headers to include 2007.
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.6.1 by Robert Collins
Start tree implementation tests.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1852.6.1 by Robert Collins
Start tree implementation tests.
16
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
17
"""Tests for the test trees used by the per_tree tests."""
1852.6.1 by Robert Collins
Start tree implementation tests.
18
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
19
from breezy import errors
6973.6.2 by Jelmer Vernooij
Fix more tests.
20
from breezy.sixish import text_type
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy.tests import per_tree
22
from breezy.tests import (
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
23
    TestNotApplicable,
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
24
    TestSkipped,
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
25
    features,
26
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
27
28
29
class TestTreeShapes(per_tree.TestCaseWithTree):
1852.6.1 by Robert Collins
Start tree implementation tests.
30
31
    def test_empty_tree_no_parents(self):
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
32
        tree = self.make_branch_and_tree('.')
33
        tree = self.get_tree_no_parents_no_content(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
34
        tree.lock_read()
35
        self.addCleanup(tree.unlock)
1852.6.1 by Robert Collins
Start tree implementation tests.
36
        self.assertEqual([], tree.get_parent_ids())
37
        self.assertEqual([], tree.conflicts())
38
        self.assertEqual([], list(tree.unknowns()))
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
39
        self.assertEqual([''], list(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
40
        self.assertEqual(
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
41
            [('', tree.path2id(''))],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
42
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
43
44
    def test_abc_tree_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
45
        tree = self.make_branch_and_tree('.')
46
        tree = self.get_tree_no_parents_abc_content(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
47
        tree.lock_read()
48
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
49
        self.assertEqual([], tree.get_parent_ids())
50
        self.assertEqual([], tree.conflicts())
51
        self.assertEqual([], list(tree.unknowns()))
52
        # __iter__ has no strongly defined order
53
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
54
            {'', 'a', 'b', 'b/c'},
55
            set(tree.all_versioned_paths()))
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
56
        self.assertTrue(tree.is_versioned('a'))
57
        self.assertTrue(tree.is_versioned('b'))
58
        self.assertTrue(tree.is_versioned('b/c'))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
59
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
60
            [(p, tree.path2id(p)) for p in ['', 'a', 'b', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
61
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
62
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
63
        self.assertFalse(tree.is_executable('b/c'))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
64
65
    def test_abc_tree_content_2_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
66
        tree = self.make_branch_and_tree('.')
67
        tree = self.get_tree_no_parents_abc_content_2(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
68
        tree.lock_read()
69
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
70
        self.assertEqual([], tree.get_parent_ids())
71
        self.assertEqual([], tree.conflicts())
72
        self.assertEqual([], list(tree.unknowns()))
73
        # __iter__ has no strongly defined order
74
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
75
            {'', 'a', 'b', 'b/c'},
76
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
77
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
78
            [(p, tree.path2id(p)) for p in ['', 'a', 'b', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
79
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
80
        self.assertEqualDiff(b'foobar\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
81
        self.assertFalse(tree.is_executable('b//c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
82
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
83
    def test_abc_tree_content_3_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
84
        tree = self.make_branch_and_tree('.')
85
        tree = self.get_tree_no_parents_abc_content_3(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
86
        tree.lock_read()
87
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
88
        self.assertEqual([], tree.get_parent_ids())
89
        self.assertEqual([], tree.conflicts())
90
        self.assertEqual([], list(tree.unknowns()))
91
        # __iter__ has no strongly defined order
92
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
93
            {'', 'a', 'b', 'b/c'},
94
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
95
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
96
            [(p, tree.path2id(p)) for p in ['', 'a', 'b', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
97
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
98
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
99
        self.assertTrue(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
100
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
101
    def test_abc_tree_content_4_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
102
        tree = self.make_branch_and_tree('.')
103
        tree = self.get_tree_no_parents_abc_content_4(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
104
        tree.lock_read()
105
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
106
        self.assertEqual([], tree.get_parent_ids())
107
        self.assertEqual([], tree.conflicts())
108
        self.assertEqual([], list(tree.unknowns()))
109
        # __iter__ has no strongly defined order
110
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
111
            {'', 'b', 'd', 'b/c'},
112
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
113
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
114
            [(p, tree.path2id(p)) for p in ['', 'b', 'd', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
115
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
116
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('d'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
117
        self.assertFalse(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
118
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
119
    def test_abc_tree_content_5_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
120
        tree = self.make_branch_and_tree('.')
121
        tree = self.get_tree_no_parents_abc_content_5(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
122
        tree.lock_read()
123
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
124
        self.assertEqual([], tree.get_parent_ids())
125
        self.assertEqual([], tree.conflicts())
126
        self.assertEqual([], list(tree.unknowns()))
127
        # __iter__ has no strongly defined order
128
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
129
            {'', 'd', 'b', 'b/c'},
130
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
131
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
132
            [(p, tree.path2id(p)) for p in ['', 'b', 'd',  'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
133
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
134
        self.assertEqualDiff(b'bar\n', tree.get_file_text('d'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
135
        self.assertFalse(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
136
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
137
    def test_abc_tree_content_6_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
138
        tree = self.make_branch_and_tree('.')
139
        tree = self.get_tree_no_parents_abc_content_6(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
140
        tree.lock_read()
141
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
142
        self.assertEqual([], tree.get_parent_ids())
143
        self.assertEqual([], tree.conflicts())
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
144
        if tree.has_versioned_directories():
145
            self.assertEqual([], list(tree.unknowns()))
146
        else:
147
            self.assertEqual(['b'], list(tree.unknowns()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
148
        # __iter__ has no strongly defined order
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
149
        expected_paths = (
150
                ['', 'a'] +
151
                (['b'] if tree.has_versioned_directories() else []) +
152
                ['e'])
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
153
        self.assertEqual(
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
154
            set(expected_paths),
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
155
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
156
        self.assertEqual(
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
157
            [(p, tree.path2id(p)) for p in expected_paths],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
158
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
159
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
160
        self.assertTrue(tree.is_executable('e'))
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
161
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
162
    def test_tree_with_subdirs_and_all_content_types(self):
163
        # currently this test tree requires unicode. It might be good
164
        # to have it simply stop having the single unicode file in it
165
        # when dealing with a non-unicode filesystem.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
166
        self.requireFeature(features.SymlinkFeature)
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
167
        tree = self.get_tree_with_subdirs_and_all_content_types()
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
168
        tree.lock_read()
169
        self.addCleanup(tree.unlock)
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
170
        self.assertEqual([], tree.get_parent_ids())
171
        self.assertEqual([], tree.conflicts())
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
172
        if tree.has_versioned_directories():
173
            self.assertEqual([], list(tree.unknowns()))
174
        else:
175
            self.assertEqual(['1top-dir/1dir-in-1topdir'], list(tree.unknowns()))
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
176
        # __iter__ has no strongly defined order
2255.2.17 by Robert Collins
tweaks - finishes off all the test_test_trees tests for dirstate.
177
        tree_root = tree.path2id('')
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
178
        if tree.has_versioned_directories():
179
            self.assertEqual(
180
                {tree.path2id(p) for p in [
181
                    '', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
182
                    '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
183
                set(tree.all_file_ids()))
184
            # note that the order of the paths and fileids is deliberately
185
            # mismatched to ensure that the result order is path based.
186
            self.assertEqual(
187
                [('', 'directory'),
188
                 ('0file', 'file'),
189
                 ('1top-dir', 'directory'),
190
                 (u'2utf\u1234file', 'file'),
191
                 ('symlink', 'symlink'),
192
                 ('1top-dir/0file-in-1topdir', 'file'),
193
                 ('1top-dir/1dir-in-1topdir', 'directory')],
194
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
195
        else:
196
            self.assertEqual(
197
                {tree.path2id(p) for p in [
198
                    '', '0file', '1top-dir', 
199
                    '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
200
                set(tree.all_file_ids()))
201
            # note that the order of the paths and fileids is deliberately
202
            # mismatched to ensure that the result order is path based.
203
            self.assertEqual(
204
                [('', 'directory'),
205
                 ('0file', 'file'),
206
                 ('1top-dir', 'directory'),
207
                 (u'2utf\u1234file', 'file'),
208
                 ('symlink', 'symlink'),
209
                 ('1top-dir/0file-in-1topdir', 'file')],
210
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
2255.2.106 by John Arbash Meinel
[merge] bzr.dev 2298 (broken)
211
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
212
    def test_tree_with_subdirs_and_all_content_types_wo_symlinks(self):
213
        # currently this test tree requires unicode. It might be good
214
        # to have it simply stop having the single unicode file in it
215
        # when dealing with a non-unicode filesystem.
216
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(False)
217
        tree.lock_read()
218
        self.addCleanup(tree.unlock)
219
        self.assertEqual([], tree.get_parent_ids())
220
        self.assertEqual([], tree.conflicts())
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
221
        if tree.has_versioned_directories():
222
            self.assertEqual([], list(tree.unknowns()))
223
        else:
224
            self.assertEqual(['1top-dir/1dir-in-1topdir'], list(tree.unknowns()))
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
225
        # __iter__ has no strongly defined order
226
        tree_root = tree.path2id('')
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
227
        if tree.has_versioned_directories():
228
            self.assertEqual(
229
                {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
230
                 '1top-dir/1dir-in-1topdir', u'2utf\u1234file'},
231
                set(tree.all_versioned_paths()))
232
            # note that the order of the paths and fileids is deliberately
233
            # mismatched to ensure that the result order is path based.
234
            self.assertEqual(
235
                [('', 'directory'),
236
                 ('0file', 'file'),
237
                 ('1top-dir', 'directory'),
238
                 (u'2utf\u1234file', 'file'),
239
                 ('1top-dir/0file-in-1topdir', 'file'),
240
                 ('1top-dir/1dir-in-1topdir', 'directory')],
241
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
242
        else:
243
            self.assertEqual(
244
                {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
245
                 u'2utf\u1234file'},
246
                set(tree.all_versioned_paths()))
247
            # note that the order of the paths and fileids is deliberately
248
            # mismatched to ensure that the result order is path based.
249
            self.assertEqual(
250
                [('', 'directory'),
251
                 ('0file', 'file'),
252
                 ('1top-dir', 'directory'),
253
                 (u'2utf\u1234file', 'file'),
254
                 ('1top-dir/0file-in-1topdir', 'file')],
255
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
256
257
    def _create_tree_with_utf8(self, tree):
258
        self.requireFeature(features.UnicodeFilenameFeature)
259
260
        # We avoid combining characters in file names here, normalization
261
        # checks (as performed by some file systems (OSX) are outside the scope
262
        # of these tests).  We use the euro sign \N{Euro Sign} or \u20ac in
263
        # unicode strings or '\xe2\x82\ac' (its utf-8 encoding) in raw strings.
264
        paths = [u'',
265
                 u'fo\N{Euro Sign}o',
266
                 u'ba\N{Euro Sign}r/',
267
                 u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
268
                ]
269
        # bzr itself does not create unicode file ids, but we want them for
270
        # testing.
271
        file_ids = ['TREE_ROOT',
272
                    'fo\xe2\x82\xaco-id',
273
                    'ba\xe2\x82\xacr-id',
274
                    'ba\xe2\x82\xacz-id',
275
                   ]
276
        self.build_tree(paths[1:])
277
        if tree.get_root_id() is None:
278
            # Some trees do not have a root yet.
279
            tree.add(paths, file_ids)
280
        else:
281
            # Some trees will already have a root
282
            if tree.supports_setting_file_ids():
283
                tree.set_root_id(file_ids[0])
284
                tree.add(paths[1:], file_ids[1:])
285
            else:
286
                tree.add(paths[1:])
287
        if tree.branch.repository._format.supports_setting_revision_ids:
288
            try:
289
                tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
290
            except errors.NonAsciiRevisionId:
291
                raise TestSkipped('non-ascii revision ids not supported')
292
        else:
293
            tree.commit(u'in\xedtial')
294
295
        return tree
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
296
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
297
    def test_tree_with_utf8(self):
298
        tree = self.make_branch_and_tree('.')
6861.1.2 by Jelmer Vernooij
Fix test.
299
        if not tree.supports_setting_file_ids():
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
300
            raise TestNotApplicable(
301
                'format does not support custom file ids')
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
302
        self._create_tree_with_utf8(tree)
303
304
        tree = self.workingtree_to_test_tree(tree)
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
305
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
306
        revision_id = u'r\xe9v-1'.encode('utf8')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
307
        root_id = b'TREE_ROOT'
3638.3.12 by Vincent Ladeuil
Fix test missed in the previous commit (--starting-with doesn't
308
        bar_id = u'ba\N{Euro Sign}r-id'.encode('utf8')
309
        foo_id = u'fo\N{Euro Sign}o-id'.encode('utf8')
310
        baz_id = u'ba\N{Euro Sign}z-id'.encode('utf8')
311
        path_and_ids = [(u'', root_id, None, None),
312
                        (u'ba\N{Euro Sign}r', bar_id, root_id, revision_id),
313
                        (u'fo\N{Euro Sign}o', foo_id, root_id, revision_id),
314
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
315
                         baz_id, bar_id, revision_id),
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
316
                       ]
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
317
        with tree.lock_read():
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
318
            path_entries = list(tree.iter_entries_by_dir())
319
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
320
        for expected, (path, ie) in zip(path_and_ids, path_entries):
321
            self.assertEqual(expected[0], path) # Paths should match
6973.6.2 by Jelmer Vernooij
Fix more tests.
322
            self.assertIsInstance(path, text_type)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
323
            self.assertEqual(expected[1], ie.file_id)
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
324
            self.assertIsInstance(ie.file_id, str)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
325
            self.assertEqual(expected[2], ie.parent_id)
326
            if expected[2] is not None:
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
327
                self.assertIsInstance(ie.parent_id, str)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
328
            # WorkingTree's return None for the last modified revision
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
329
            if ie.revision is not None:
330
                self.assertIsInstance(ie.revision, str)
331
                if expected[0] != '':
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
332
                    # Some trees will preserve the revision id of the tree root,
333
                    # but not all will
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
334
                    self.assertEqual(revision_id, ie.revision)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
335
        self.assertEqual(len(path_and_ids), len(path_entries))
336
        get_revision_id = getattr(tree, 'get_revision_id', None)
337
        if get_revision_id is not None:
338
            self.assertIsInstance(get_revision_id(), str)
339
        last_revision = getattr(tree, 'last_revision', None)
340
        if last_revision is not None:
341
            self.assertIsInstance(last_revision(), str)
342
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
343
    def test_tree_with_merged_utf8(self):
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
344
        wt = self.make_branch_and_tree('.')
345
346
        self._create_tree_with_utf8(wt)
347
348
        tree2 = wt.controldir.sprout('tree2').open_workingtree()
349
        self.build_tree([u'tree2/ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
350
        if wt.supports_setting_file_ids():
351
            tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'],
352
                      [u'qu\N{Euro Sign}x-id'.encode('utf-8')])
353
        else:
354
            tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
355
        if wt.branch.repository._format.supports_setting_revision_ids:
356
            tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
357
        else:
358
            tree2.commit(u'to m\xe9rge')
359
360
        self.assertTrue(tree2.is_versioned(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
361
        wt.merge_from_branch(tree2.branch)
362
        self.assertTrue(wt.is_versioned(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
363
364
        if wt.branch.repository._format.supports_setting_revision_ids:
365
            wt.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
366
        else:
367
            wt.commit(u'm\xe9rge')
368
        tree = self.workingtree_to_test_tree(wt)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
369
370
        revision_id_1 = u'r\xe9v-1'.encode('utf8')
371
        revision_id_2 = u'r\xe9v-2'.encode('utf8')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
372
        root_id = b'TREE_ROOT'
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
373
        bar_id = u'ba\N{Euro Sign}r-id'.encode('utf8')
374
        foo_id = u'fo\N{Euro Sign}o-id'.encode('utf8')
375
        baz_id = u'ba\N{Euro Sign}z-id'.encode('utf8')
376
        qux_id = u'qu\N{Euro Sign}x-id'.encode('utf8')
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
377
        path_and_ids = [(u'', root_id, None, None),
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
378
                        (u'ba\N{Euro Sign}r', bar_id, root_id, revision_id_1),
379
                        (u'fo\N{Euro Sign}o', foo_id, root_id, revision_id_1),
380
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
381
                         baz_id, bar_id, revision_id_1),
382
                        (u'ba\N{Euro Sign}r/qu\N{Euro Sign}x',
383
                         qux_id, bar_id, revision_id_2),
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
384
                       ]
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
385
        with tree.lock_read():
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
386
            path_entries = list(tree.iter_entries_by_dir())
387
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
388
        for (epath, efid, eparent, erev), (path, ie) in zip(path_and_ids,
389
                                                            path_entries):
390
            self.assertEqual(epath, path) # Paths should match
6973.6.2 by Jelmer Vernooij
Fix more tests.
391
            self.assertIsInstance(path, text_type)
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
392
            self.assertIsInstance(ie.file_id, bytes)
393
            if wt.supports_setting_file_ids():
394
                self.assertEqual(efid, ie.file_id)
395
                self.assertEqual(eparent, ie.parent_id)
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
396
            if eparent is not None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
397
                self.assertIsInstance(ie.parent_id, bytes)
398
        self.assertEqual(len(path_and_ids), len(path_entries),
399
                         "%r vs %r" % (
400
                             [p for (p, f, pf, r) in path_and_ids],
401
                             [p for (p, e) in path_entries]))
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
402
        get_revision_id = getattr(tree, 'get_revision_id', None)
403
        if get_revision_id is not None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
404
            self.assertIsInstance(get_revision_id(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
405
        last_revision = getattr(tree, 'last_revision', None)
406
        if last_revision is not None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
407
            self.assertIsInstance(last_revision(), bytes)