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