~bzr-pqm/bzr/bzr.dev

5387.2.7 by John Arbash Meinel
Merge bzr.dev 5444 to resolve some small text conflicts.
1
# Copyright (C) 2010 Canonical Ltd
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for bzrdir implementations - tests a bzrdir format."""
18
19
import errno
20
from stat import S_ISDIR
21
22
import bzrlib.branch
23
from bzrlib import (
24
    errors,
5699.4.7 by Jelmer Vernooij
Fix imports.
25
    repository,
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
26
    revision as _mod_revision,
5363.2.30 by Jelmer Vernooij
actually run per_bzrdir tests.
27
    transport,
5699.4.7 by Jelmer Vernooij
Fix imports.
28
    workingtree,
5363.2.30 by Jelmer Vernooij
actually run per_bzrdir tests.
29
    )
30
from bzrlib.tests import (
31
    TestSkipped,
32
    )
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
33
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
5363.2.30 by Jelmer Vernooij
actually run per_bzrdir tests.
34
from bzrlib.transport.local import (
35
    LocalTransport,
36
    )
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
37
38
5699.4.7 by Jelmer Vernooij
Fix imports.
39
class AnonymousTestBranchFormat(bzrlib.branch.BranchFormat):
40
    """An anonymous branch format (does not have a format string)"""
41
42
    def get_format_string(self):
43
        raise NotImplementedError(self.get_format_string)
44
45
46
class IdentifiableTestBranchFormat(bzrlib.branch.BranchFormat):
47
    """An identifable branch format (has a format string)"""
48
49
    def get_format_string(self):
50
        return "I have an identity"
51
52
53
class AnonymousTestRepositoryFormat(repository.RepositoryFormat):
54
    """An anonymous branch format (does not have a format string)"""
55
56
    def get_format_string(self):
57
        raise NotImplementedError(self.get_format_string)
58
59
60
class IdentifiableTestRepositoryFormat(repository.RepositoryFormat):
61
    """An identifable branch format (has a format string)"""
62
63
    def get_format_string(self):
64
        return "I have an identity"
65
66
67
class AnonymousTestWorkingTreeFormat(workingtree.WorkingTreeFormat):
68
    """An anonymous branch format (does not have a format string)"""
69
70
    def get_format_string(self):
71
        raise NotImplementedError(self.get_format_string)
72
73
74
class IdentifiableTestWorkingTreeFormat(workingtree.WorkingTreeFormat):
75
    """An identifable branch format (has a format string)"""
76
77
    def get_format_string(self):
78
        return "I have an identity"
79
80
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
81
class TestBzrDir(TestCaseWithBzrDir):
82
83
    # Many of these tests test for disk equality rather than checking
84
    # for semantic equivalence. This works well for some tests but
85
    # is not good at handling changes in representation or the addition
86
    # or removal of control data. It would be nice to for instance:
87
    # sprout a new branch, check that the nickname has been reset by hand
88
    # and then set the nickname to match the source branch, at which point
89
    # a semantic equivalence should pass
90
91
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
92
        """Assert that the content of source and target are identical.
93
94
        paths in ignore list will be completely ignored.
95
96
        We ignore paths that represent data which is allowed to change during
97
        a clone or sprout: for instance, inventory.knit contains gzip fragements
98
        which have timestamps in them, and as we have read the inventory from
99
        the source knit, the already-read data is recompressed rather than
100
        reading it again, which leads to changed timestamps. This is ok though,
101
        because the inventory.kndx file is not ignored, and the integrity of
102
        knit joins is tested by test_knit and test_versionedfile.
103
104
        :seealso: Additionally, assertRepositoryHasSameItems provides value
105
            rather than representation checking of repositories for
106
            equivalence.
107
        """
108
        files = []
109
        directories = ['.']
110
        while directories:
111
            dir = directories.pop()
112
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
113
                path = dir + '/' + path
114
                if path in ignore_list:
115
                    continue
116
                try:
117
                    stat = source.stat(path)
118
                except errors.NoSuchFile:
119
                    self.fail('%s not in source' % path)
120
                if S_ISDIR(stat.st_mode):
121
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
122
                    directories.append(path)
123
                else:
124
                    self.assertEqualDiff(source.get(path).read(),
125
                                         target.get(path).read(),
126
                                         "text for file %r differs:\n" % path)
127
128
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
129
        """require left_repo and right_repo to contain the same data."""
130
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
131
        # local repositories to remote ones...  but this is an as-yet unsolved
132
        # aspect of format management and the Remote protocols...
133
        # self.assertEqual(left_repo._format.__class__,
134
        #     right_repo._format.__class__)
135
        left_repo.lock_read()
136
        try:
137
            right_repo.lock_read()
138
            try:
139
                # revs
140
                all_revs = left_repo.all_revision_ids()
141
                self.assertEqual(left_repo.all_revision_ids(),
142
                    right_repo.all_revision_ids())
143
                for rev_id in left_repo.all_revision_ids():
144
                    self.assertEqual(left_repo.get_revision(rev_id),
145
                        right_repo.get_revision(rev_id))
146
                # Assert the revision trees (and thus the inventories) are equal
147
                sort_key = lambda rev_tree: rev_tree.get_revision_id()
148
                rev_trees_a = sorted(
149
                    left_repo.revision_trees(all_revs), key=sort_key)
150
                rev_trees_b = sorted(
151
                    right_repo.revision_trees(all_revs), key=sort_key)
152
                for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
153
                    self.assertEqual([], list(tree_a.iter_changes(tree_b)))
154
                # texts
155
                text_index = left_repo._generate_text_key_index()
156
                self.assertEqual(text_index,
157
                    right_repo._generate_text_key_index())
158
                desired_files = []
159
                for file_id, revision_id in text_index.iterkeys():
160
                    desired_files.append(
161
                        (file_id, revision_id, (file_id, revision_id)))
162
                left_texts = list(left_repo.iter_files_bytes(desired_files))
163
                right_texts = list(right_repo.iter_files_bytes(desired_files))
164
                left_texts.sort()
165
                right_texts.sort()
166
                self.assertEqual(left_texts, right_texts)
167
                # signatures
168
                for rev_id in all_revs:
169
                    try:
170
                        left_text = left_repo.get_signature_text(rev_id)
171
                    except errors.NoSuchRevision:
172
                        continue
173
                    right_text = right_repo.get_signature_text(rev_id)
174
                    self.assertEqual(left_text, right_text)
175
            finally:
176
                right_repo.unlock()
177
        finally:
178
            left_repo.unlock()
179
5363.2.30 by Jelmer Vernooij
actually run per_bzrdir tests.
180
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
181
                     force_new_repo=False, accelerator_tree=None,
182
                     create_tree_if_local=True):
183
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
184
185
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
186
        TestSkipped.  Returns the newly sprouted bzrdir.
187
        """
188
        to_transport = transport.get_transport(to_url)
189
        if not isinstance(to_transport, LocalTransport):
190
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
191
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
192
                                    force_new_repo=force_new_repo,
193
                                    possible_transports=[to_transport],
194
                                    accelerator_tree=accelerator_tree,
195
                                    create_tree_if_local=create_tree_if_local)
196
        return target
197
198
    def skipIfNoWorkingTree(self, a_bzrdir):
199
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
200
201
        If the bzrdir does have a workingtree, this is a no-op.
202
        """
203
        try:
204
            a_bzrdir.open_workingtree()
205
        except (errors.NotLocalUrl, errors.NoWorkingTree):
206
            raise TestSkipped("bzrdir on transport %r has no working tree"
207
                              % a_bzrdir.transport)
208
209
    def createWorkingTreeOrSkip(self, a_bzrdir):
210
        """Create a working tree on a_bzrdir, or raise TestSkipped.
211
212
        A simple wrapper for create_workingtree that translates NotLocalUrl into
213
        TestSkipped.  Returns the newly created working tree.
214
        """
215
        try:
5042.1.3 by Martin Pool
Update a test for BzrDir.create_workingtree so that it covers bug 524627
216
            # This passes in many named options to make sure they're
217
            # understood by subclasses: see
218
            # <https://bugs.launchpad.net/bzr/+bug/524627>.
219
            return a_bzrdir.create_workingtree(
220
                revision_id=None,
221
                from_branch=None,
222
                accelerator_tree=None,
223
                hardlink=False)
5363.2.30 by Jelmer Vernooij
actually run per_bzrdir tests.
224
        except errors.NotLocalUrl:
225
            raise TestSkipped("cannot make working tree with transport %r"
226
                              % a_bzrdir.transport)
227
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
228
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
229
        tree = self.make_branch_and_tree('commit_tree')
230
        self.build_tree(['commit_tree/foo'])
231
        tree.add('foo')
232
        tree.commit('revision 1', rev_id='1')
233
        dir = self.make_bzrdir('source')
234
        repo = dir.create_repository()
235
        repo.fetch(tree.branch.repository)
236
        self.assertTrue(repo.has_revision('1'))
237
        try:
238
            self.make_repository('target', shared=True)
239
        except errors.IncompatibleFormat:
240
            return
241
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
242
        self.assertNotEqual(dir.transport.base, target.transport.base)
243
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
244
                                    ['./.bzr/repository',
245
                                     ])
246
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
247
248
    def test_clone_bzrdir_branch_and_repo(self):
249
        tree = self.make_branch_and_tree('commit_tree')
250
        self.build_tree(['commit_tree/foo'])
251
        tree.add('foo')
252
        tree.commit('revision 1')
253
        source = self.make_branch('source')
254
        tree.branch.repository.copy_content_into(source.repository)
255
        tree.branch.copy_content_into(source)
256
        dir = source.bzrdir
257
        target = dir.clone(self.get_url('target'))
258
        self.assertNotEqual(dir.transport.base, target.transport.base)
259
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
260
                                    [
261
                                     './.bzr/basis-inventory-cache',
262
                                     './.bzr/checkout/stat-cache',
263
                                     './.bzr/merge-hashes',
264
                                     './.bzr/repository',
265
                                     './.bzr/stat-cache',
266
                                    ])
267
        self.assertRepositoryHasSameItems(
268
            tree.branch.repository, target.open_repository())
269
270
    def test_clone_on_transport(self):
271
        a_dir = self.make_bzrdir('source')
272
        target_transport = a_dir.root_transport.clone('..').clone('target')
273
        target = a_dir.clone_on_transport(target_transport)
274
        self.assertNotEqual(a_dir.transport.base, target.transport.base)
275
        self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
276
                                    ['./.bzr/merge-hashes'])
277
278
    def test_clone_bzrdir_empty(self):
279
        dir = self.make_bzrdir('source')
280
        target = dir.clone(self.get_url('target'))
281
        self.assertNotEqual(dir.transport.base, target.transport.base)
282
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
283
                                    ['./.bzr/merge-hashes'])
284
285
    def test_clone_bzrdir_empty_force_new_ignored(self):
286
        # the force_new_repo parameter should have no effect on an empty
287
        # bzrdir's clone logic
288
        dir = self.make_bzrdir('source')
289
        target = dir.clone(self.get_url('target'), force_new_repo=True)
290
        self.assertNotEqual(dir.transport.base, target.transport.base)
291
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
292
                                    ['./.bzr/merge-hashes'])
293
294
    def test_clone_bzrdir_repository(self):
295
        tree = self.make_branch_and_tree('commit_tree')
296
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
297
        tree.add('foo')
298
        tree.commit('revision 1', rev_id='1')
299
        dir = self.make_bzrdir('source')
300
        repo = dir.create_repository()
301
        repo.fetch(tree.branch.repository)
302
        self.assertTrue(repo.has_revision('1'))
303
        target = dir.clone(self.get_url('target'))
304
        self.assertNotEqual(dir.transport.base, target.transport.base)
305
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
306
                                    [
307
                                     './.bzr/merge-hashes',
308
                                     './.bzr/repository',
309
                                     ])
310
        self.assertRepositoryHasSameItems(tree.branch.repository,
311
            target.open_repository())
312
313
    def test_clone_bzrdir_tree_branch_repo(self):
314
        tree = self.make_branch_and_tree('source')
315
        self.build_tree(['source/foo'])
316
        tree.add('foo')
317
        tree.commit('revision 1')
318
        dir = tree.bzrdir
319
        target = dir.clone(self.get_url('target'))
320
        self.skipIfNoWorkingTree(target)
321
        self.assertNotEqual(dir.transport.base, target.transport.base)
322
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
323
                                    ['./.bzr/stat-cache',
324
                                     './.bzr/checkout/dirstate',
325
                                     './.bzr/checkout/stat-cache',
326
                                     './.bzr/checkout/merge-hashes',
327
                                     './.bzr/merge-hashes',
328
                                     './.bzr/repository',
329
                                     ])
330
        self.assertRepositoryHasSameItems(tree.branch.repository,
331
            target.open_repository())
332
        target.open_workingtree().revert()
333
334
    def test_revert_inventory(self):
335
        tree = self.make_branch_and_tree('source')
336
        self.build_tree(['source/foo'])
337
        tree.add('foo')
338
        tree.commit('revision 1')
339
        dir = tree.bzrdir
340
        target = dir.clone(self.get_url('target'))
341
        self.skipIfNoWorkingTree(target)
342
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
343
                                    ['./.bzr/stat-cache',
344
                                     './.bzr/checkout/dirstate',
345
                                     './.bzr/checkout/stat-cache',
346
                                     './.bzr/checkout/merge-hashes',
347
                                     './.bzr/merge-hashes',
348
                                     './.bzr/repository',
349
                                     ])
350
        self.assertRepositoryHasSameItems(tree.branch.repository,
351
            target.open_repository())
352
353
        target.open_workingtree().revert()
354
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
355
                                    ['./.bzr/stat-cache',
356
                                     './.bzr/checkout/dirstate',
357
                                     './.bzr/checkout/stat-cache',
358
                                     './.bzr/checkout/merge-hashes',
359
                                     './.bzr/merge-hashes',
360
                                     './.bzr/repository',
361
                                     ])
362
        self.assertRepositoryHasSameItems(tree.branch.repository,
363
            target.open_repository())
364
365
    def test_clone_bzrdir_tree_branch_reference(self):
366
        # a tree with a branch reference (aka a checkout)
367
        # should stay a checkout on clone.
368
        referenced_branch = self.make_branch('referencced')
369
        dir = self.make_bzrdir('source')
370
        try:
371
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
372
                target_branch=referenced_branch)
373
        except errors.IncompatibleFormat:
374
            # this is ok too, not all formats have to support references.
375
            return
376
        self.createWorkingTreeOrSkip(dir)
377
        target = dir.clone(self.get_url('target'))
378
        self.skipIfNoWorkingTree(target)
379
        self.assertNotEqual(dir.transport.base, target.transport.base)
380
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
381
                                    ['./.bzr/stat-cache',
382
                                     './.bzr/checkout/stat-cache',
383
                                     './.bzr/checkout/merge-hashes',
384
                                     './.bzr/merge-hashes',
385
                                     './.bzr/repository/inventory.knit',
386
                                     ])
387
388
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
389
        # by default cloning into a shared repo uses the shared repo.
390
        tree = self.make_branch_and_tree('commit_tree')
391
        self.build_tree(['commit_tree/foo'])
392
        tree.add('foo')
393
        tree.commit('revision 1')
394
        source = self.make_branch('source')
395
        tree.branch.repository.copy_content_into(source.repository)
396
        tree.branch.copy_content_into(source)
397
        try:
398
            self.make_repository('target', shared=True)
399
        except errors.IncompatibleFormat:
400
            return
401
        dir = source.bzrdir
402
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
403
        self.assertNotEqual(dir.transport.base, target.transport.base)
404
        repo = target.open_repository()
405
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
406
                                    ['./.bzr/repository',
407
                                     ])
408
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
409
410
    def test_clone_bzrdir_branch_reference(self):
411
        # cloning should preserve the reference status of the branch in a bzrdir
412
        referenced_branch = self.make_branch('referencced')
413
        dir = self.make_bzrdir('source')
414
        try:
415
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
416
                target_branch=referenced_branch)
417
        except errors.IncompatibleFormat:
418
            # this is ok too, not all formats have to support references.
419
            return
420
        target = dir.clone(self.get_url('target'))
421
        self.assertNotEqual(dir.transport.base, target.transport.base)
422
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
423
424
    def test_sprout_bzrdir_repository(self):
425
        tree = self.make_branch_and_tree('commit_tree')
426
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
427
        tree.add('foo')
428
        tree.commit('revision 1', rev_id='1')
429
        dir = self.make_bzrdir('source')
430
        repo = dir.create_repository()
431
        repo.fetch(tree.branch.repository)
432
        self.assertTrue(repo.has_revision('1'))
433
        try:
434
            self.assertTrue(
435
                _mod_revision.is_null(_mod_revision.ensure_null(
436
                dir.open_branch().last_revision())))
437
        except errors.NotBranchError:
438
            pass
439
        target = dir.sprout(self.get_url('target'))
440
        self.assertNotEqual(dir.transport.base, target.transport.base)
441
        # testing inventory isn't reasonable for repositories
442
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
443
                                    [
444
                                     './.bzr/branch',
445
                                     './.bzr/checkout',
446
                                     './.bzr/inventory',
447
                                     './.bzr/parent',
448
                                     './.bzr/repository/inventory.knit',
449
                                     ])
450
        try:
451
            local_inventory = dir.transport.local_abspath('inventory')
452
        except errors.NotLocalUrl:
453
            return
454
        try:
455
            # If we happen to have a tree, we'll guarantee everything
456
            # except for the tree root is the same.
457
            inventory_f = file(local_inventory, 'rb')
458
            self.addCleanup(inventory_f.close)
459
            self.assertContainsRe(inventory_f.read(),
460
                                  '<inventory format="5">\n</inventory>\n')
461
        except IOError, e:
462
            if e.errno != errno.ENOENT:
463
                raise
464
465
    def test_sprout_bzrdir_branch_and_repo(self):
466
        tree = self.make_branch_and_tree('commit_tree')
467
        self.build_tree(['commit_tree/foo'])
468
        tree.add('foo')
469
        tree.commit('revision 1')
470
        source = self.make_branch('source')
471
        tree.branch.repository.copy_content_into(source.repository)
472
        tree.bzrdir.open_branch().copy_content_into(source)
473
        dir = source.bzrdir
474
        target = dir.sprout(self.get_url('target'))
475
        self.assertNotEqual(dir.transport.base, target.transport.base)
476
        target_repo = target.open_repository()
477
        self.assertRepositoryHasSameItems(source.repository, target_repo)
478
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
479
                                    [
480
                                     './.bzr/basis-inventory-cache',
481
                                     './.bzr/branch/branch.conf',
482
                                     './.bzr/branch/parent',
483
                                     './.bzr/checkout',
484
                                     './.bzr/checkout/inventory',
485
                                     './.bzr/checkout/stat-cache',
486
                                     './.bzr/inventory',
487
                                     './.bzr/parent',
488
                                     './.bzr/repository',
489
                                     './.bzr/stat-cache',
490
                                     './foo',
491
                                     ])
492
493
    def test_sprout_bzrdir_tree_branch_repo(self):
494
        tree = self.make_branch_and_tree('source')
495
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
496
        tree.add('foo')
497
        tree.commit('revision 1')
498
        dir = tree.bzrdir
499
        target = self.sproutOrSkip(dir, self.get_url('target'))
500
        self.assertNotEqual(dir.transport.base, target.transport.base)
501
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
502
                                    [
503
                                     './.bzr/branch/branch.conf',
504
                                     './.bzr/branch/parent',
505
                                     './.bzr/checkout/dirstate',
506
                                     './.bzr/checkout/stat-cache',
507
                                     './.bzr/checkout/inventory',
508
                                     './.bzr/inventory',
509
                                     './.bzr/parent',
510
                                     './.bzr/repository',
511
                                     './.bzr/stat-cache',
512
                                     ])
513
        self.assertRepositoryHasSameItems(
514
            tree.branch.repository, target.open_repository())
515
516
517
    def test_retire_bzrdir(self):
518
        bd = self.make_bzrdir('.')
519
        transport = bd.root_transport
520
        # must not overwrite existing directories
521
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
522
            transport=transport)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
523
        self.assertTrue(transport.has('.bzr'))
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
524
        bd.retire_bzrdir()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
525
        self.assertFalse(transport.has('.bzr'))
526
        self.assertTrue(transport.has('.bzr.retired.1'))
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
527
528
    def test_retire_bzrdir_limited(self):
529
        bd = self.make_bzrdir('.')
530
        transport = bd.root_transport
531
        # must not overwrite existing directories
532
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
533
            transport=transport)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
534
        self.assertTrue(transport.has('.bzr'))
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
535
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
536
            bd.retire_bzrdir, limit=0)
5699.4.1 by Jelmer Vernooij
Move get_branch_transport, .get_workingtree_transport and .get_repository_transport
537
538
    def test_get_branch_transport(self):
539
        dir = self.make_bzrdir('.')
540
        # without a format, get_branch_transport gives use a transport
541
        # which -may- point to an existing dir.
542
        self.assertTrue(isinstance(dir.get_branch_transport(None),
543
                                   transport.Transport))
544
        # with a given format, either the bzr dir supports identifiable
545
        # branches, or it supports anonymous branch formats, but not both.
546
        anonymous_format = AnonymousTestBranchFormat()
547
        identifiable_format = IdentifiableTestBranchFormat()
548
        try:
549
            found_transport = dir.get_branch_transport(anonymous_format)
550
            self.assertRaises(errors.IncompatibleFormat,
551
                              dir.get_branch_transport,
552
                              identifiable_format)
553
        except errors.IncompatibleFormat:
554
            found_transport = dir.get_branch_transport(identifiable_format)
555
        self.assertTrue(isinstance(found_transport, transport.Transport))
556
        # and the dir which has been initialized for us must exist.
557
        found_transport.list_dir('.')
558
559
    def test_get_repository_transport(self):
560
        dir = self.make_bzrdir('.')
561
        # without a format, get_repository_transport gives use a transport
562
        # which -may- point to an existing dir.
563
        self.assertTrue(isinstance(dir.get_repository_transport(None),
564
                                   transport.Transport))
565
        # with a given format, either the bzr dir supports identifiable
566
        # repositories, or it supports anonymous repository formats, but not both.
567
        anonymous_format = AnonymousTestRepositoryFormat()
568
        identifiable_format = IdentifiableTestRepositoryFormat()
569
        try:
570
            found_transport = dir.get_repository_transport(anonymous_format)
571
            self.assertRaises(errors.IncompatibleFormat,
572
                              dir.get_repository_transport,
573
                              identifiable_format)
574
        except errors.IncompatibleFormat:
575
            found_transport = dir.get_repository_transport(identifiable_format)
576
        self.assertTrue(isinstance(found_transport, transport.Transport))
577
        # and the dir which has been initialized for us must exist.
578
        found_transport.list_dir('.')
579
580
    def test_get_workingtree_transport(self):
581
        dir = self.make_bzrdir('.')
582
        # without a format, get_workingtree_transport gives use a transport
583
        # which -may- point to an existing dir.
584
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
585
                                   transport.Transport))
586
        # with a given format, either the bzr dir supports identifiable
587
        # trees, or it supports anonymous tree formats, but not both.
588
        anonymous_format = AnonymousTestWorkingTreeFormat()
589
        identifiable_format = IdentifiableTestWorkingTreeFormat()
590
        try:
591
            found_transport = dir.get_workingtree_transport(anonymous_format)
592
            self.assertRaises(errors.IncompatibleFormat,
593
                              dir.get_workingtree_transport,
594
                              identifiable_format)
595
        except errors.IncompatibleFormat:
596
            found_transport = dir.get_workingtree_transport(identifiable_format)
597
        self.assertTrue(isinstance(found_transport, transport.Transport))
598
        # and the dir which has been initialized for us must exist.
599
        found_transport.list_dir('.')