/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_tree/test_test_trees.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-25 00:39:16 UTC
  • mfrom: (6926 work)
  • mto: This revision was merged to the branch mainline in revision 6928.
  • Revision ID: jelmer@jelmer.uk-20180325003916-mqa5uj4uq55hrjq9
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the test trees used by the per_tree tests."""
18
18
 
 
19
from breezy import errors
19
20
from breezy.tests import per_tree
20
21
from breezy.tests import (
 
22
    TestNotApplicable,
 
23
    TestSkipped,
21
24
    features,
22
25
    )
23
26
 
137
140
        self.addCleanup(tree.unlock)
138
141
        self.assertEqual([], tree.get_parent_ids())
139
142
        self.assertEqual([], tree.conflicts())
140
 
        self.assertEqual([], list(tree.unknowns()))
 
143
        if tree.has_versioned_directories():
 
144
            self.assertEqual([], list(tree.unknowns()))
 
145
        else:
 
146
            self.assertEqual(['b'], list(tree.unknowns()))
141
147
        # __iter__ has no strongly defined order
142
148
        expected_paths = (
143
149
                ['', 'a'] +
162
168
        self.addCleanup(tree.unlock)
163
169
        self.assertEqual([], tree.get_parent_ids())
164
170
        self.assertEqual([], tree.conflicts())
165
 
        self.assertEqual([], list(tree.unknowns()))
 
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()))
166
175
        # __iter__ has no strongly defined order
167
176
        tree_root = tree.path2id('')
168
 
        self.assertEqual(
169
 
            {tree.path2id(p) for p in [
170
 
                '', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
171
 
                '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
172
 
            set(tree.all_file_ids()))
173
 
        # note that the order of the paths and fileids is deliberately
174
 
        # mismatched to ensure that the result order is path based.
175
 
        self.assertEqual(
176
 
            [('', 'directory'),
177
 
             ('0file', 'file'),
178
 
             ('1top-dir', 'directory'),
179
 
             (u'2utf\u1234file', 'file'),
180
 
             ('symlink', 'symlink'),
181
 
             ('1top-dir/0file-in-1topdir', 'file'),
182
 
             ('1top-dir/1dir-in-1topdir', 'directory')],
183
 
            [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
 
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()])
184
210
 
185
211
    def test_tree_with_subdirs_and_all_content_types_wo_symlinks(self):
186
212
        # currently this test tree requires unicode. It might be good
191
217
        self.addCleanup(tree.unlock)
192
218
        self.assertEqual([], tree.get_parent_ids())
193
219
        self.assertEqual([], tree.conflicts())
194
 
        self.assertEqual([], list(tree.unknowns()))
 
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()))
195
224
        # __iter__ has no strongly defined order
196
225
        tree_root = tree.path2id('')
197
 
        self.assertEqual(
198
 
            {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
199
 
             '1top-dir/1dir-in-1topdir', u'2utf\u1234file'},
200
 
            set(tree.all_versioned_paths()))
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
 
             ('1top-dir/0file-in-1topdir', 'file'),
209
 
             ('1top-dir/1dir-in-1topdir', 'directory')],
210
 
            [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
 
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
211
295
 
212
296
    def test_tree_with_utf8(self):
213
297
        tree = self.make_branch_and_tree('.')
214
 
        tree = self.get_tree_with_utf8(tree)
 
298
        if not tree.supports_setting_file_ids():
 
299
            raise TestNotApplicable(
 
300
                'format does not support custom file ids')
 
301
        self._create_tree_with_utf8(tree)
 
302
 
 
303
        tree = self.workingtree_to_test_tree(tree)
215
304
 
216
305
        revision_id = u'r\xe9v-1'.encode('utf8')
217
306
        root_id = 'TREE_ROOT'
224
313
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
225
314
                         baz_id, bar_id, revision_id),
226
315
                       ]
227
 
        tree.lock_read()
228
 
        try:
 
316
        with tree.lock_read():
229
317
            path_entries = list(tree.iter_entries_by_dir())
230
 
        finally:
231
 
            tree.unlock()
232
318
 
233
319
        for expected, (path, ie) in zip(path_and_ids, path_entries):
234
320
            self.assertEqual(expected[0], path) # Paths should match
254
340
            self.assertIsInstance(last_revision(), str)
255
341
 
256
342
    def test_tree_with_merged_utf8(self):
257
 
        tree = self.make_branch_and_tree('.')
258
 
        tree = self.get_tree_with_merged_utf8(tree)
 
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)
259
368
 
260
369
        revision_id_1 = u'r\xe9v-1'.encode('utf8')
261
370
        revision_id_2 = u'r\xe9v-2'.encode('utf8')
272
381
                        (u'ba\N{Euro Sign}r/qu\N{Euro Sign}x',
273
382
                         qux_id, bar_id, revision_id_2),
274
383
                       ]
275
 
        tree.lock_read()
276
 
        try:
 
384
        with tree.lock_read():
277
385
            path_entries = list(tree.iter_entries_by_dir())
278
 
        finally:
279
 
            tree.unlock()
280
386
 
281
387
        for (epath, efid, eparent, erev), (path, ie) in zip(path_and_ids,
282
388
                                                            path_entries):
283
389
            self.assertEqual(epath, path) # Paths should match
284
390
            self.assertIsInstance(path, unicode)
285
 
            self.assertEqual(efid, ie.file_id)
286
 
            self.assertIsInstance(ie.file_id, str)
287
 
            self.assertEqual(eparent, ie.parent_id)
 
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)
288
395
            if eparent is not None:
289
 
                self.assertIsInstance(ie.parent_id, str)
290
 
            # WorkingTree's return None for the last modified revision
291
 
            if ie.revision is not None:
292
 
                self.assertIsInstance(ie.revision, str)
293
 
                if epath == '':
294
 
                    # Some trees will preserve the revision id of the tree root,
295
 
                    # but not all will
296
 
                    continue
297
 
                self.assertEqual(erev, ie.revision)
298
 
        self.assertEqual(len(path_and_ids), len(path_entries))
 
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]))
299
401
        get_revision_id = getattr(tree, 'get_revision_id', None)
300
402
        if get_revision_id is not None:
301
 
            self.assertIsInstance(get_revision_id(), str)
 
403
            self.assertIsInstance(get_revision_id(), bytes)
302
404
        last_revision = getattr(tree, 'last_revision', None)
303
405
        if last_revision is not None:
304
 
            self.assertIsInstance(last_revision(), str)
 
406
            self.assertIsInstance(last_revision(), bytes)