~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_bzrdir/test_bzrdir.py

(jelmer) Several more fixes to allow running bzr.dev against bzr-svn (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import bzrlib.branch
23
23
from bzrlib import (
 
24
    bzrdir,
24
25
    errors,
25
26
    repository,
26
27
    revision as _mod_revision,
27
28
    transport,
28
29
    workingtree,
29
30
    )
 
31
from bzrlib.remote import RemoteBzrDirFormat
30
32
from bzrlib.tests import (
 
33
    TestNotApplicable,
31
34
    TestSkipped,
32
35
    )
33
36
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
597
600
        self.assertTrue(isinstance(found_transport, transport.Transport))
598
601
        # and the dir which has been initialized for us must exist.
599
602
        found_transport.list_dir('.')
 
603
 
 
604
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
 
605
        """Execute initialize_on_transport_ex and check it succeeded correctly.
 
606
 
 
607
        This involves checking that the disk objects were created, open with
 
608
        the same format returned, and had the expected disk format.
 
609
 
 
610
        :param t: The transport to initialize on.
 
611
        :param **kwargs: Additional arguments to pass to
 
612
            initialize_on_transport_ex.
 
613
        :return: the resulting repo, control dir tuple.
 
614
        """
 
615
        if not self.bzrdir_format.is_initializable():
 
616
            raise TestNotApplicable("control dir format is not "
 
617
                "initializable")
 
618
        repo, control, require_stacking, repo_policy = \
 
619
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
 
620
        if repo is not None:
 
621
            # Repositories are open write-locked
 
622
            self.assertTrue(repo.is_write_locked())
 
623
            self.addCleanup(repo.unlock)
 
624
        self.assertIsInstance(control, bzrdir.BzrDir)
 
625
        opened = bzrdir.BzrDir.open(t.base)
 
626
        expected_format = self.bzrdir_format
 
627
        if need_meta and expected_format.fixed_components:
 
628
            # Pre-metadir formats change when we are making something that
 
629
            # needs a metaformat, because clone is used for push.
 
630
            expected_format = bzrdir.BzrDirMetaFormat1()
 
631
        if not isinstance(expected_format, RemoteBzrDirFormat):
 
632
            self.assertEqual(control._format.network_name(),
 
633
                expected_format.network_name())
 
634
            self.assertEqual(control._format.network_name(),
 
635
                opened._format.network_name())
 
636
        self.assertEqual(control.__class__, opened.__class__)
 
637
        return repo, control
 
638
 
 
639
    def test_format_initialize_on_transport_ex_default_stack_on(self):
 
640
        # When initialize_on_transport_ex uses a stacked-on branch because of
 
641
        # a stacking policy on the target, the location of the fallback
 
642
        # repository is the same as the external location of the stacked-on
 
643
        # branch.
 
644
        balloon = self.make_bzrdir('balloon')
 
645
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
 
646
            stack_on = self.make_branch('stack-on', format='1.9')
 
647
        else:
 
648
            stack_on = self.make_branch('stack-on')
 
649
        if not stack_on.repository._format.supports_nesting_repositories:
 
650
            raise TestNotApplicable("requires nesting repositories")
 
651
        config = self.make_bzrdir('.').get_config()
 
652
        try:
 
653
            config.set_default_stack_on('stack-on')
 
654
        except errors.BzrError:
 
655
            raise TestNotApplicable('Only relevant for stackable formats.')
 
656
        # Initialize a bzrdir subject to the policy.
 
657
        t = self.get_transport('stacked')
 
658
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
659
        repo_name = repo_fmt.repository_format.network_name()
 
660
        repo, control = self.assertInitializeEx(
 
661
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
 
662
        # self.addCleanup(repo.unlock)
 
663
        # There's one fallback repo, with a public location.
 
664
        self.assertLength(1, repo._fallback_repositories)
 
665
        fallback_repo = repo._fallback_repositories[0]
 
666
        self.assertEqual(
 
667
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
 
668
        # The bzrdir creates a branch in stacking-capable format.
 
669
        new_branch = control.create_branch()
 
670
        self.assertTrue(new_branch._format.supports_stacking())
 
671
 
 
672