/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

Merge in the BranchBuilder updates, which brings in a newer bzr.dev

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
423
424
        self.assertFalse(repo.is_shared())
424
425
 
425
426
 
 
427
    def test_determine_stacking_policy(self):
 
428
        parent_bzrdir = self.make_bzrdir('.')
 
429
        child_bzrdir = self.make_bzrdir('child')
 
430
        parent_bzrdir.get_config().set_default_stack_on('http://example.org')
 
431
        repo_policy = child_bzrdir.determine_repository_policy()
 
432
        self.assertEqual('http://example.org', repo_policy._stack_on)
 
433
 
 
434
    def test_determine_stacking_policy_relative(self):
 
435
        parent_bzrdir = self.make_bzrdir('.')
 
436
        child_bzrdir = self.make_bzrdir('child')
 
437
        parent_bzrdir.get_config().set_default_stack_on('child2')
 
438
        repo_policy = child_bzrdir.determine_repository_policy()
 
439
        self.assertEqual('child2', repo_policy._stack_on)
 
440
        self.assertEqual(parent_bzrdir.root_transport.base,
 
441
                         repo_policy._stack_on_pwd)
 
442
 
 
443
    def prepare_default_stacking(self):
 
444
        parent_bzrdir = self.make_bzrdir('.')
 
445
        child_branch = self.make_branch('child', format='development1')
 
446
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
 
447
        new_child_transport = parent_bzrdir.transport.clone('child2')
 
448
        return child_branch, new_child_transport
 
449
 
 
450
    def test_clone_on_transport_obeys_stacking_policy(self):
 
451
        child_branch, new_child_transport = self.prepare_default_stacking()
 
452
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
 
453
        self.assertEqual(child_branch.base,
 
454
                         new_child.open_branch().get_stacked_on_url())
 
455
 
 
456
    def test_sprout_obeys_stacking_policy(self):
 
457
        child_branch, new_child_transport = self.prepare_default_stacking()
 
458
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
 
459
        self.assertEqual(child_branch.base,
 
460
                         new_child.open_branch().get_stacked_on_url())
 
461
 
 
462
    def test_add_fallback_repo_handles_absolute_urls(self):
 
463
        stack_on = self.make_branch('stack_on', format='development1')
 
464
        repo = self.make_repository('repo', format='development1')
 
465
        policy = bzrdir.UseExistingRepository(repo, stack_on.base)
 
466
        policy._add_fallback(repo)
 
467
 
 
468
    def test_add_fallback_repo_handles_relative_urls(self):
 
469
        stack_on = self.make_branch('stack_on', format='development1')
 
470
        repo = self.make_repository('repo', format='development1')
 
471
        policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
 
472
        policy._add_fallback(repo)
 
473
 
 
474
    def test_configure_relative_branch_stacking_url(self):
 
475
        stack_on = self.make_branch('stack_on', format='development1')
 
476
        stacked = self.make_branch('stack_on/stacked', format='development1')
 
477
        policy = bzrdir.UseExistingRepository(stacked.repository,
 
478
            '.', stack_on.base)
 
479
        policy.configure_branch(stacked)
 
480
        self.assertEqual('..', stacked.get_stacked_on_url())
 
481
 
 
482
    def test_relative_branch_stacking_to_absolute(self):
 
483
        stack_on = self.make_branch('stack_on', format='development1')
 
484
        stacked = self.make_branch('stack_on/stacked', format='development1')
 
485
        policy = bzrdir.UseExistingRepository(stacked.repository,
 
486
            '.', self.get_readonly_url('stack_on'))
 
487
        policy.configure_branch(stacked)
 
488
        self.assertEqual(self.get_readonly_url('stack_on'),
 
489
                         stacked.get_stacked_on_url())
 
490
 
 
491
 
426
492
class ChrootedTests(TestCaseWithTransport):
427
493
    """A support class that provides readonly urls outside the local namespace.
428
494
 
436
502
        if not self.vfs_transport_factory == MemoryServer:
437
503
            self.transport_readonly_server = HttpServer
438
504
 
 
505
    def local_branch_path(self, branch):
 
506
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
 
507
 
439
508
    def test_open_containing(self):
440
509
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
441
510
                          self.get_readonly_url(''))
447
516
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
448
517
        self.assertEqual('g/p/q', relpath)
449
518
 
 
519
    def test_open_containing_tree_branch_or_repository_empty(self):
 
520
        self.assertRaises(errors.NotBranchError,
 
521
            bzrdir.BzrDir.open_containing_tree_branch_or_repository,
 
522
            self.get_readonly_url(''))
 
523
 
 
524
    def test_open_containing_tree_branch_or_repository_all(self):
 
525
        self.make_branch_and_tree('topdir')
 
526
        tree, branch, repo, relpath = \
 
527
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
528
                'topdir/foo')
 
529
        self.assertEqual(os.path.realpath('topdir'),
 
530
                         os.path.realpath(tree.basedir))
 
531
        self.assertEqual(os.path.realpath('topdir'),
 
532
                         self.local_branch_path(branch))
 
533
        self.assertEqual(
 
534
            os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
 
535
            repo.bzrdir.transport.local_abspath('repository'))
 
536
        self.assertEqual(relpath, 'foo')
 
537
 
 
538
    def test_open_containing_tree_branch_or_repository_no_tree(self):
 
539
        self.make_branch('branch')
 
540
        tree, branch, repo, relpath = \
 
541
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
542
                'branch/foo')
 
543
        self.assertEqual(tree, None)
 
544
        self.assertEqual(os.path.realpath('branch'),
 
545
                         self.local_branch_path(branch))
 
546
        self.assertEqual(
 
547
            os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
 
548
            repo.bzrdir.transport.local_abspath('repository'))
 
549
        self.assertEqual(relpath, 'foo')
 
550
 
 
551
    def test_open_containing_tree_branch_or_repository_repo(self):
 
552
        self.make_repository('repo')
 
553
        tree, branch, repo, relpath = \
 
554
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
555
                'repo')
 
556
        self.assertEqual(tree, None)
 
557
        self.assertEqual(branch, None)
 
558
        self.assertEqual(
 
559
            os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
 
560
            repo.bzrdir.transport.local_abspath('repository'))
 
561
        self.assertEqual(relpath, '')
 
562
 
 
563
    def test_open_containing_tree_branch_or_repository_shared_repo(self):
 
564
        self.make_repository('shared', shared=True)
 
565
        bzrdir.BzrDir.create_branch_convenience('shared/branch',
 
566
                                                force_new_tree=False)
 
567
        tree, branch, repo, relpath = \
 
568
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
569
                'shared/branch')
 
570
        self.assertEqual(tree, None)
 
571
        self.assertEqual(os.path.realpath('shared/branch'),
 
572
                         self.local_branch_path(branch))
 
573
        self.assertEqual(
 
574
            os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
 
575
            repo.bzrdir.transport.local_abspath('repository'))
 
576
        self.assertEqual(relpath, '')
 
577
 
 
578
    def test_open_containing_tree_branch_or_repository_branch_subdir(self):
 
579
        self.make_branch_and_tree('foo')
 
580
        self.build_tree(['foo/bar/'])
 
581
        tree, branch, repo, relpath = \
 
582
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
583
                'foo/bar')
 
584
        self.assertEqual(os.path.realpath('foo'),
 
585
                         os.path.realpath(tree.basedir))
 
586
        self.assertEqual(os.path.realpath('foo'),
 
587
                         self.local_branch_path(branch))
 
588
        self.assertEqual(
 
589
            os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
 
590
            repo.bzrdir.transport.local_abspath('repository'))
 
591
        self.assertEqual(relpath, 'bar')
 
592
 
 
593
    def test_open_containing_tree_branch_or_repository_repo_subdir(self):
 
594
        self.make_repository('bar')
 
595
        self.build_tree(['bar/baz/'])
 
596
        tree, branch, repo, relpath = \
 
597
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
598
                'bar/baz')
 
599
        self.assertEqual(tree, None)
 
600
        self.assertEqual(branch, None)
 
601
        self.assertEqual(
 
602
            os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
 
603
            repo.bzrdir.transport.local_abspath('repository'))
 
604
        self.assertEqual(relpath, 'baz')
 
605
 
450
606
    def test_open_containing_from_transport(self):
451
607
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
452
608
                          get_transport(self.get_readonly_url('')))
461
617
        self.assertEqual('g/p/q', relpath)
462
618
 
463
619
    def test_open_containing_tree_or_branch(self):
464
 
        def local_branch_path(branch):
465
 
             return os.path.realpath(
466
 
                urlutils.local_path_from_url(branch.base))
467
 
 
468
620
        self.make_branch_and_tree('topdir')
469
621
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
470
622
            'topdir/foo')
471
623
        self.assertEqual(os.path.realpath('topdir'),
472
624
                         os.path.realpath(tree.basedir))
473
625
        self.assertEqual(os.path.realpath('topdir'),
474
 
                         local_branch_path(branch))
 
626
                         self.local_branch_path(branch))
475
627
        self.assertIs(tree.bzrdir, branch.bzrdir)
476
628
        self.assertEqual('foo', relpath)
477
629
        # opening from non-local should not return the tree
485
637
            'topdir/foo')
486
638
        self.assertIs(tree, None)
487
639
        self.assertEqual(os.path.realpath('topdir/foo'),
488
 
                         local_branch_path(branch))
 
640
                         self.local_branch_path(branch))
489
641
        self.assertEqual('', relpath)
490
642
 
491
643
    def test_open_tree_or_branch(self):
492
 
        def local_branch_path(branch):
493
 
             return os.path.realpath(
494
 
                urlutils.local_path_from_url(branch.base))
495
 
 
496
644
        self.make_branch_and_tree('topdir')
497
645
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
498
646
        self.assertEqual(os.path.realpath('topdir'),
499
647
                         os.path.realpath(tree.basedir))
500
648
        self.assertEqual(os.path.realpath('topdir'),
501
 
                         local_branch_path(branch))
 
649
                         self.local_branch_path(branch))
502
650
        self.assertIs(tree.bzrdir, branch.bzrdir)
503
651
        # opening from non-local should not return the tree
504
652
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
509
657
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
510
658
        self.assertIs(tree, None)
511
659
        self.assertEqual(os.path.realpath('topdir/foo'),
512
 
                         local_branch_path(branch))
 
660
                         self.local_branch_path(branch))
513
661
 
514
662
    def test_open_from_transport(self):
515
663
        # transport pointing at bzrdir should give a bzrdir with root transport