/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(
7143.15.2 by Jelmer Vernooij
Run autopep8.
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())
7096.3.3 by Jelmer Vernooij
Fix two more tests.
144
        if tree.has_versioned_directories() or not tree.has_filename('b'):
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
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 = (
7143.15.2 by Jelmer Vernooij
Run autopep8.
150
            ['', 'a']
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
151
            + (['b'] if tree.has_versioned_directories() else [])
7143.15.2 by Jelmer Vernooij
Run autopep8.
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())
7096.3.2 by Jelmer Vernooij
Fix some git tests.
172
        if tree.has_versioned_directories() or not tree.has_filename('1top-dir/1dir-in-1topdir'):
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
173
            self.assertEqual([], list(tree.unknowns()))
174
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
175
            self.assertEqual(['1top-dir/1dir-in-1topdir'],
176
                             list(tree.unknowns()))
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
177
        # __iter__ has no strongly defined order
2255.2.17 by Robert Collins
tweaks - finishes off all the test_test_trees tests for dirstate.
178
        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.
179
        if tree.has_versioned_directories():
180
            self.assertEqual(
181
                {tree.path2id(p) for p in [
182
                    '', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
183
                    '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
184
                set(tree.all_file_ids()))
185
            # note that the order of the paths and fileids is deliberately
186
            # mismatched to ensure that the result order is path based.
187
            self.assertEqual(
188
                [('', 'directory'),
189
                 ('0file', 'file'),
190
                 ('1top-dir', 'directory'),
191
                 (u'2utf\u1234file', 'file'),
192
                 ('symlink', 'symlink'),
193
                 ('1top-dir/0file-in-1topdir', 'file'),
194
                 ('1top-dir/1dir-in-1topdir', 'directory')],
195
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
196
        else:
197
            self.assertEqual(
198
                {tree.path2id(p) for p in [
7143.15.2 by Jelmer Vernooij
Run autopep8.
199
                    '', '0file', '1top-dir',
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
200
                    '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
201
                set(tree.all_file_ids()))
202
            # note that the order of the paths and fileids is deliberately
203
            # mismatched to ensure that the result order is path based.
204
            self.assertEqual(
205
                [('', 'directory'),
206
                 ('0file', 'file'),
207
                 ('1top-dir', 'directory'),
208
                 (u'2utf\u1234file', 'file'),
209
                 ('symlink', 'symlink'),
210
                 ('1top-dir/0file-in-1topdir', 'file')],
211
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
2255.2.106 by John Arbash Meinel
[merge] bzr.dev 2298 (broken)
212
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
213
    def test_tree_with_subdirs_and_all_content_types_wo_symlinks(self):
214
        # currently this test tree requires unicode. It might be good
215
        # to have it simply stop having the single unicode file in it
216
        # when dealing with a non-unicode filesystem.
7143.15.2 by Jelmer Vernooij
Run autopep8.
217
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(
218
            False)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
219
        tree.lock_read()
220
        self.addCleanup(tree.unlock)
221
        self.assertEqual([], tree.get_parent_ids())
222
        self.assertEqual([], tree.conflicts())
7096.3.2 by Jelmer Vernooij
Fix some git tests.
223
        if tree.has_versioned_directories() or not tree.has_filename('1top-dir/1dir-in-1topdir'):
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
224
            self.assertEqual([], list(tree.unknowns()))
225
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
226
            self.assertEqual(['1top-dir/1dir-in-1topdir'],
227
                             list(tree.unknowns()))
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
228
        # __iter__ has no strongly defined order
229
        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.
230
        if tree.has_versioned_directories():
231
            self.assertEqual(
232
                {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
233
                 '1top-dir/1dir-in-1topdir', u'2utf\u1234file'},
234
                set(tree.all_versioned_paths()))
235
            # note that the order of the paths and fileids is deliberately
236
            # mismatched to ensure that the result order is path based.
237
            self.assertEqual(
238
                [('', 'directory'),
239
                 ('0file', 'file'),
240
                 ('1top-dir', 'directory'),
241
                 (u'2utf\u1234file', 'file'),
242
                 ('1top-dir/0file-in-1topdir', 'file'),
243
                 ('1top-dir/1dir-in-1topdir', 'directory')],
244
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
245
        else:
246
            self.assertEqual(
247
                {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
248
                 u'2utf\u1234file'},
249
                set(tree.all_versioned_paths()))
250
            # note that the order of the paths and fileids is deliberately
251
            # mismatched to ensure that the result order is path based.
252
            self.assertEqual(
253
                [('', 'directory'),
254
                 ('0file', 'file'),
255
                 ('1top-dir', 'directory'),
256
                 (u'2utf\u1234file', 'file'),
257
                 ('1top-dir/0file-in-1topdir', 'file')],
258
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
259
260
    def _create_tree_with_utf8(self, tree):
261
        self.requireFeature(features.UnicodeFilenameFeature)
262
263
        # We avoid combining characters in file names here, normalization
264
        # checks (as performed by some file systems (OSX) are outside the scope
265
        # of these tests).  We use the euro sign \N{Euro Sign} or \u20ac in
266
        # unicode strings or '\xe2\x82\ac' (its utf-8 encoding) in raw strings.
267
        paths = [u'',
268
                 u'fo\N{Euro Sign}o',
269
                 u'ba\N{Euro Sign}r/',
270
                 u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
7143.15.2 by Jelmer Vernooij
Run autopep8.
271
                 ]
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
272
        # bzr itself does not create unicode file ids, but we want them for
273
        # testing.
7045.4.11 by Jelmer Vernooij
Some more tests fixed.
274
        file_ids = [b'TREE_ROOT',
275
                    b'fo\xe2\x82\xaco-id',
276
                    b'ba\xe2\x82\xacr-id',
277
                    b'ba\xe2\x82\xacz-id',
7143.15.2 by Jelmer Vernooij
Run autopep8.
278
                    ]
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
279
        self.build_tree(paths[1:])
280
        if tree.get_root_id() is None:
281
            # Some trees do not have a root yet.
282
            tree.add(paths, file_ids)
283
        else:
284
            # Some trees will already have a root
285
            if tree.supports_setting_file_ids():
286
                tree.set_root_id(file_ids[0])
287
                tree.add(paths[1:], file_ids[1:])
288
            else:
289
                tree.add(paths[1:])
290
        if tree.branch.repository._format.supports_setting_revision_ids:
291
            try:
292
                tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
293
            except errors.NonAsciiRevisionId:
294
                raise TestSkipped('non-ascii revision ids not supported')
295
        else:
296
            tree.commit(u'in\xedtial')
297
298
        return tree
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
299
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
300
    def test_tree_with_utf8(self):
301
        tree = self.make_branch_and_tree('.')
6861.1.2 by Jelmer Vernooij
Fix test.
302
        if not tree.supports_setting_file_ids():
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
303
            raise TestNotApplicable(
304
                '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.
305
        self._create_tree_with_utf8(tree)
306
307
        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
308
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
309
        revision_id = u'r\xe9v-1'.encode('utf8')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
310
        root_id = b'TREE_ROOT'
3638.3.12 by Vincent Ladeuil
Fix test missed in the previous commit (--starting-with doesn't
311
        bar_id = u'ba\N{Euro Sign}r-id'.encode('utf8')
312
        foo_id = u'fo\N{Euro Sign}o-id'.encode('utf8')
313
        baz_id = u'ba\N{Euro Sign}z-id'.encode('utf8')
314
        path_and_ids = [(u'', root_id, None, None),
315
                        (u'ba\N{Euro Sign}r', bar_id, root_id, revision_id),
316
                        (u'fo\N{Euro Sign}o', foo_id, root_id, revision_id),
317
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
318
                         baz_id, bar_id, revision_id),
7143.15.2 by Jelmer Vernooij
Run autopep8.
319
                        ]
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
320
        with tree.lock_read():
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
321
            path_entries = list(tree.iter_entries_by_dir())
322
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
323
        for expected, (path, ie) in zip(path_and_ids, path_entries):
7143.15.2 by Jelmer Vernooij
Run autopep8.
324
            self.assertEqual(expected[0], path)  # Paths should match
6973.6.2 by Jelmer Vernooij
Fix more tests.
325
            self.assertIsInstance(path, text_type)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
326
            self.assertEqual(expected[1], ie.file_id)
7045.4.34 by Jelmer Vernooij
Fix some more tests.
327
            self.assertIsInstance(ie.file_id, bytes)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
328
            self.assertEqual(expected[2], ie.parent_id)
329
            if expected[2] is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
330
                self.assertIsInstance(ie.parent_id, bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
331
            # 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
332
            if ie.revision is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
333
                self.assertIsInstance(ie.revision, bytes)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
334
                if expected[0] != '':
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
335
                    # Some trees will preserve the revision id of the tree root,
336
                    # but not all will
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
337
                    self.assertEqual(revision_id, ie.revision)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
338
        self.assertEqual(len(path_and_ids), len(path_entries))
339
        get_revision_id = getattr(tree, 'get_revision_id', None)
340
        if get_revision_id is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
341
            self.assertIsInstance(get_revision_id(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
342
        last_revision = getattr(tree, 'last_revision', None)
343
        if last_revision is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
344
            self.assertIsInstance(last_revision(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
345
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
346
    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.
347
        wt = self.make_branch_and_tree('.')
348
349
        self._create_tree_with_utf8(wt)
350
351
        tree2 = wt.controldir.sprout('tree2').open_workingtree()
352
        self.build_tree([u'tree2/ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
353
        if wt.supports_setting_file_ids():
354
            tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'],
355
                      [u'qu\N{Euro Sign}x-id'.encode('utf-8')])
356
        else:
357
            tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
358
        if wt.branch.repository._format.supports_setting_revision_ids:
359
            tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
360
        else:
361
            tree2.commit(u'to m\xe9rge')
362
7143.15.2 by Jelmer Vernooij
Run autopep8.
363
        self.assertTrue(tree2.is_versioned(
364
            u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
365
        wt.merge_from_branch(tree2.branch)
366
        self.assertTrue(wt.is_versioned(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
367
368
        if wt.branch.repository._format.supports_setting_revision_ids:
369
            wt.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
370
        else:
371
            wt.commit(u'm\xe9rge')
372
        tree = self.workingtree_to_test_tree(wt)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
373
374
        revision_id_1 = u'r\xe9v-1'.encode('utf8')
375
        revision_id_2 = u'r\xe9v-2'.encode('utf8')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
376
        root_id = b'TREE_ROOT'
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
377
        bar_id = u'ba\N{Euro Sign}r-id'.encode('utf8')
378
        foo_id = u'fo\N{Euro Sign}o-id'.encode('utf8')
379
        baz_id = u'ba\N{Euro Sign}z-id'.encode('utf8')
380
        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
381
        path_and_ids = [(u'', root_id, None, None),
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
382
                        (u'ba\N{Euro Sign}r', bar_id, root_id, revision_id_1),
383
                        (u'fo\N{Euro Sign}o', foo_id, root_id, revision_id_1),
384
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
385
                         baz_id, bar_id, revision_id_1),
386
                        (u'ba\N{Euro Sign}r/qu\N{Euro Sign}x',
387
                         qux_id, bar_id, revision_id_2),
7143.15.2 by Jelmer Vernooij
Run autopep8.
388
                        ]
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
389
        with tree.lock_read():
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
390
            path_entries = list(tree.iter_entries_by_dir())
391
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
392
        for (epath, efid, eparent, erev), (path, ie) in zip(path_and_ids,
393
                                                            path_entries):
7143.15.2 by Jelmer Vernooij
Run autopep8.
394
            self.assertEqual(epath, path)  # Paths should match
6973.6.2 by Jelmer Vernooij
Fix more tests.
395
            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.
396
            self.assertIsInstance(ie.file_id, bytes)
397
            if wt.supports_setting_file_ids():
398
                self.assertEqual(efid, ie.file_id)
399
                self.assertEqual(eparent, ie.parent_id)
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
400
            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.
401
                self.assertIsInstance(ie.parent_id, bytes)
402
        self.assertEqual(len(path_and_ids), len(path_entries),
403
                         "%r vs %r" % (
404
                             [p for (p, f, pf, r) in path_and_ids],
405
                             [p for (p, e) in path_entries]))
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
406
        get_revision_id = getattr(tree, 'get_revision_id', None)
407
        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.
408
            self.assertIsInstance(get_revision_id(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
409
        last_revision = getattr(tree, 'last_revision', None)
410
        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.
411
            self.assertIsInstance(last_revision(), bytes)