/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 bzrlib/tests/test_bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-08 14:55:19 UTC
  • mfrom: (3530 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3532.
  • Revision ID: john@arbash-meinel.com-20080708145519-paqg4kjwbpgs2xmq
Merge bzr.dev 3530

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
For interface contract tests, see tests/bzr_dir_implementations.
20
20
"""
21
21
 
 
22
import os
22
23
import os.path
23
24
from StringIO import StringIO
24
25
import subprocess
39
40
                           UnknownFormatError,
40
41
                           UnsupportedFormatError,
41
42
                           )
42
 
from bzrlib.symbol_versioning import (
43
 
    zero_ninetyone,
44
 
    )
45
43
from bzrlib.tests import (
46
44
    TestCase,
47
45
    TestCaseWithTransport,
66
64
        old_format = bzrdir.BzrDirFormat.get_default_format()
67
65
        # default is BzrDirFormat6
68
66
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
69
 
        self.applyDeprecated(symbol_versioning.zero_fourteen, 
70
 
                             bzrdir.BzrDirFormat.set_default_format, 
71
 
                             SampleBzrDirFormat())
 
67
        bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
72
68
        # creating a bzr dir should now create an instrumented dir.
73
69
        try:
74
70
            result = bzrdir.BzrDir.create('memory:///')
75
71
            self.failUnless(isinstance(result, SampleBzrDir))
76
72
        finally:
77
 
            self.applyDeprecated(symbol_versioning.zero_fourteen,
78
 
                bzrdir.BzrDirFormat.set_default_format, old_format)
 
73
            bzrdir.BzrDirFormat._set_default_format(old_format)
79
74
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
80
75
 
81
76
 
281
276
        # now open_downlevel should fail too.
282
277
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
283
278
 
284
 
    def test_create_repository_deprecated(self):
285
 
        # new interface is to make the bzrdir, then a repository within that.
286
 
        format = SampleBzrDirFormat()
287
 
        repo = self.applyDeprecated(zero_ninetyone,
288
 
                bzrdir.BzrDir.create_repository,
289
 
                self.get_url(), format=format)
290
 
        self.assertEqual('A repository', repo)
291
 
 
292
 
    def test_create_repository_shared(self):
293
 
        # new interface is to make the bzrdir, then a repository within that.
294
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
295
 
        repo = self.applyDeprecated(zero_ninetyone,
296
 
                bzrdir.BzrDir.create_repository,
297
 
                '.', shared=True)
298
 
        self.assertTrue(repo.is_shared())
299
 
 
300
 
    def test_create_repository_nonshared(self):
301
 
        # new interface is to make the bzrdir, then a repository within that.
302
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
303
 
        repo = self.applyDeprecated(zero_ninetyone,
304
 
                bzrdir.BzrDir.create_repository,
305
 
                '.')
306
 
        self.assertFalse(repo.is_shared())
307
 
 
308
 
    def test_create_repository_under_shared(self):
309
 
        # an explicit create_repository always does so.
310
 
        # we trust the format is right from the 'create_repository test'
311
 
        # new interface is to make the bzrdir, then a repository within that.
312
 
        format = bzrdir.format_registry.make_bzrdir('knit')
313
 
        self.make_repository('.', shared=True, format=format)
314
 
        repo = self.applyDeprecated(zero_ninetyone,
315
 
                bzrdir.BzrDir.create_repository,
316
 
                self.get_url('child'),
317
 
                format=format)
318
 
        self.assertTrue(isinstance(repo, repository.Repository))
319
 
        self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
320
 
 
321
279
    def test_create_branch_and_repo_uses_default(self):
322
280
        format = SampleBzrDirFormat()
323
281
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
454
412
        branch.bzrdir.open_workingtree()
455
413
 
456
414
 
 
415
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
 
416
 
 
417
    def test_acquire_repository_standalone(self):
 
418
        """The default acquisition policy should create a standalone branch."""
 
419
        my_bzrdir = self.make_bzrdir('.')
 
420
        repo_policy = my_bzrdir.determine_repository_policy()
 
421
        repo = repo_policy.acquire_repository()
 
422
        self.assertEqual(repo.bzrdir.root_transport.base,
 
423
                         my_bzrdir.root_transport.base)
 
424
        self.assertFalse(repo.is_shared())
 
425
 
 
426
 
457
427
class ChrootedTests(TestCaseWithTransport):
458
428
    """A support class that provides readonly urls outside the local namespace.
459
429
 
467
437
        if not self.vfs_transport_factory == MemoryServer:
468
438
            self.transport_readonly_server = HttpServer
469
439
 
 
440
    def local_branch_path(self, branch):
 
441
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
 
442
 
470
443
    def test_open_containing(self):
471
444
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
472
445
                          self.get_readonly_url(''))
478
451
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
479
452
        self.assertEqual('g/p/q', relpath)
480
453
 
 
454
    def test_open_containing_tree_branch_or_repository_empty(self):
 
455
        self.assertRaises(errors.NotBranchError,
 
456
            bzrdir.BzrDir.open_containing_tree_branch_or_repository,
 
457
            self.get_readonly_url(''))
 
458
 
 
459
    def test_open_containing_tree_branch_or_repository_all(self):
 
460
        self.make_branch_and_tree('topdir')
 
461
        tree, branch, repo, relpath = \
 
462
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
463
                'topdir/foo')
 
464
        self.assertEqual(os.path.realpath('topdir'),
 
465
                         os.path.realpath(tree.basedir))
 
466
        self.assertEqual(os.path.realpath('topdir'),
 
467
                         self.local_branch_path(branch))
 
468
        self.assertEqual(
 
469
            os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
 
470
            repo.bzrdir.transport.local_abspath('repository'))
 
471
        self.assertEqual(relpath, 'foo')
 
472
 
 
473
    def test_open_containing_tree_branch_or_repository_no_tree(self):
 
474
        self.make_branch('branch')
 
475
        tree, branch, repo, relpath = \
 
476
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
477
                'branch/foo')
 
478
        self.assertEqual(tree, None)
 
479
        self.assertEqual(os.path.realpath('branch'),
 
480
                         self.local_branch_path(branch))
 
481
        self.assertEqual(
 
482
            os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
 
483
            repo.bzrdir.transport.local_abspath('repository'))
 
484
        self.assertEqual(relpath, 'foo')
 
485
 
 
486
    def test_open_containing_tree_branch_or_repository_repo(self):
 
487
        self.make_repository('repo')
 
488
        tree, branch, repo, relpath = \
 
489
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
490
                'repo')
 
491
        self.assertEqual(tree, None)
 
492
        self.assertEqual(branch, None)
 
493
        self.assertEqual(
 
494
            os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
 
495
            repo.bzrdir.transport.local_abspath('repository'))
 
496
        self.assertEqual(relpath, '')
 
497
 
 
498
    def test_open_containing_tree_branch_or_repository_shared_repo(self):
 
499
        self.make_repository('shared', shared=True)
 
500
        bzrdir.BzrDir.create_branch_convenience('shared/branch',
 
501
                                                force_new_tree=False)
 
502
        tree, branch, repo, relpath = \
 
503
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
504
                'shared/branch')
 
505
        self.assertEqual(tree, None)
 
506
        self.assertEqual(os.path.realpath('shared/branch'),
 
507
                         self.local_branch_path(branch))
 
508
        self.assertEqual(
 
509
            os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
 
510
            repo.bzrdir.transport.local_abspath('repository'))
 
511
        self.assertEqual(relpath, '')
 
512
 
 
513
    def test_open_containing_tree_branch_or_repository_branch_subdir(self):
 
514
        self.make_branch_and_tree('foo')
 
515
        self.build_tree(['foo/bar/'])
 
516
        tree, branch, repo, relpath = \
 
517
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
518
                'foo/bar')
 
519
        self.assertEqual(os.path.realpath('foo'),
 
520
                         os.path.realpath(tree.basedir))
 
521
        self.assertEqual(os.path.realpath('foo'),
 
522
                         self.local_branch_path(branch))
 
523
        self.assertEqual(
 
524
            os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
 
525
            repo.bzrdir.transport.local_abspath('repository'))
 
526
        self.assertEqual(relpath, 'bar')
 
527
 
 
528
    def test_open_containing_tree_branch_or_repository_repo_subdir(self):
 
529
        self.make_repository('bar')
 
530
        self.build_tree(['bar/baz/'])
 
531
        tree, branch, repo, relpath = \
 
532
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
533
                'bar/baz')
 
534
        self.assertEqual(tree, None)
 
535
        self.assertEqual(branch, None)
 
536
        self.assertEqual(
 
537
            os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
 
538
            repo.bzrdir.transport.local_abspath('repository'))
 
539
        self.assertEqual(relpath, 'baz')
 
540
 
481
541
    def test_open_containing_from_transport(self):
482
542
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
483
543
                          get_transport(self.get_readonly_url('')))
492
552
        self.assertEqual('g/p/q', relpath)
493
553
 
494
554
    def test_open_containing_tree_or_branch(self):
495
 
        def local_branch_path(branch):
496
 
             return os.path.realpath(
497
 
                urlutils.local_path_from_url(branch.base))
498
 
 
499
555
        self.make_branch_and_tree('topdir')
500
556
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
501
557
            'topdir/foo')
502
558
        self.assertEqual(os.path.realpath('topdir'),
503
559
                         os.path.realpath(tree.basedir))
504
560
        self.assertEqual(os.path.realpath('topdir'),
505
 
                         local_branch_path(branch))
 
561
                         self.local_branch_path(branch))
506
562
        self.assertIs(tree.bzrdir, branch.bzrdir)
507
563
        self.assertEqual('foo', relpath)
508
564
        # opening from non-local should not return the tree
516
572
            'topdir/foo')
517
573
        self.assertIs(tree, None)
518
574
        self.assertEqual(os.path.realpath('topdir/foo'),
519
 
                         local_branch_path(branch))
 
575
                         self.local_branch_path(branch))
520
576
        self.assertEqual('', relpath)
521
577
 
522
578
    def test_open_tree_or_branch(self):
523
 
        def local_branch_path(branch):
524
 
             return os.path.realpath(
525
 
                urlutils.local_path_from_url(branch.base))
526
 
 
527
579
        self.make_branch_and_tree('topdir')
528
580
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
529
581
        self.assertEqual(os.path.realpath('topdir'),
530
582
                         os.path.realpath(tree.basedir))
531
583
        self.assertEqual(os.path.realpath('topdir'),
532
 
                         local_branch_path(branch))
 
584
                         self.local_branch_path(branch))
533
585
        self.assertIs(tree.bzrdir, branch.bzrdir)
534
586
        # opening from non-local should not return the tree
535
587
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
540
592
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
541
593
        self.assertIs(tree, None)
542
594
        self.assertEqual(os.path.realpath('topdir/foo'),
543
 
                         local_branch_path(branch))
 
595
                         self.local_branch_path(branch))
544
596
 
545
597
    def test_open_from_transport(self):
546
598
        # transport pointing at bzrdir should give a bzrdir with root transport