~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_controldir_colo/test_supported.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for bzr directories that support colocated branches."""
18
18
 
19
 
import bzrlib.branch
 
19
from bzrlib.branch import Branch
20
20
from bzrlib import (
21
21
    errors,
22
22
    tests,
23
 
    transport,
 
23
    urlutils,
24
24
    )
25
25
from bzrlib.tests import (
26
26
    per_controldir,
27
27
    )
 
28
from bzrlib.tests.features import (
 
29
    UnicodeFilenameFeature,
 
30
    )
28
31
 
29
32
 
30
33
class TestColocatedBranchSupport(per_controldir.TestCaseWithControlDir):
53
56
        except errors.UninitializableFormat:
54
57
            raise tests.TestNotApplicable(
55
58
                'Control dir does not support creating new branches.')
56
 
        made_repo = made_control.create_repository()
 
59
        made_control.create_repository()
57
60
        made_branch = made_control.create_branch("colo")
58
 
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
59
 
        self.assertEqual(made_control, made_branch.bzrdir)
 
61
        self.assertIsInstance(made_branch, Branch)
 
62
        self.assertEquals("colo", made_branch.name)
 
63
        self.assertEqual(made_control, made_branch.bzrdir)
 
64
 
 
65
    def test_open_by_url(self):
 
66
        # a bzrdir can construct a branch and repository for itself.
 
67
        if not self.bzrdir_format.is_supported():
 
68
            # unsupported formats are not loopback testable
 
69
            # because the default open will not open them and
 
70
            # they may not be initializable.
 
71
            raise tests.TestNotApplicable('Control dir format not supported')
 
72
        t = self.get_transport()
 
73
        try:
 
74
            made_control = self.bzrdir_format.initialize(t.base)
 
75
        except errors.UninitializableFormat:
 
76
            raise tests.TestNotApplicable(
 
77
                'Control dir does not support creating new branches.')
 
78
        made_control.create_repository()
 
79
        made_branch = made_control.create_branch(name="colo")
 
80
        other_branch = made_control.create_branch(name="othercolo")
 
81
        self.assertIsInstance(made_branch, Branch)
 
82
        self.assertEqual(made_control, made_branch.bzrdir)
 
83
        self.assertNotEqual(made_branch.user_url, other_branch.user_url)
 
84
        self.assertNotEqual(made_branch.control_url, other_branch.control_url)
 
85
        re_made_branch = Branch.open(made_branch.user_url)
 
86
        self.assertEquals(re_made_branch.name, "colo")
 
87
        self.assertEqual(made_branch.control_url, re_made_branch.control_url)
 
88
        self.assertEqual(made_branch.user_url, re_made_branch.user_url)
 
89
 
 
90
    def test_sprout_into_colocated(self):
 
91
        # a bzrdir can construct a branch and repository for itself.
 
92
        if not self.bzrdir_format.is_supported():
 
93
            # unsupported formats are not loopback testable
 
94
            # because the default open will not open them and
 
95
            # they may not be initializable.
 
96
            raise tests.TestNotApplicable('Control dir format not supported')
 
97
        from_tree = self.make_branch_and_tree('from')
 
98
        revid = from_tree.commit("rev1")
 
99
        try:
 
100
            other_branch = self.make_branch("to")
 
101
        except errors.UninitializableFormat:
 
102
            raise tests.TestNotApplicable(
 
103
                'Control dir does not support creating new branches.')
 
104
        to_dir = from_tree.bzrdir.sprout(
 
105
            urlutils.join_segment_parameters(
 
106
                other_branch.bzrdir.user_url, {"branch": "target"}))
 
107
        to_branch = to_dir.open_branch(name="target")
 
108
        self.assertEquals(revid, to_branch.last_revision())
 
109
 
 
110
    def test_unicode(self):
 
111
        self.requireFeature(UnicodeFilenameFeature)
 
112
        if not self.bzrdir_format.is_supported():
 
113
            # unsupported formats are not loopback testable
 
114
            # because the default open will not open them and
 
115
            # they may not be initializable.
 
116
            raise tests.TestNotApplicable('Control dir format not supported')
 
117
        t = self.get_transport()
 
118
        try:
 
119
            made_control = self.bzrdir_format.initialize(t.base)
 
120
        except errors.UninitializableFormat:
 
121
            raise tests.TestNotApplicable(
 
122
                'Control dir does not support creating new branches.')
 
123
        made_control.create_repository()
 
124
        made_branch = made_control.create_branch(name=u"col\xe9")
 
125
        self.assertTrue(
 
126
            u"col\xe9" in [b.name for b in made_control.list_branches()])
 
127
        made_branch = Branch.open(made_branch.user_url)
 
128
        self.assertEquals(u"col\xe9", made_branch.name)
 
129
        made_control.destroy_branch(u"col\xe9")
 
130
 
 
131
    def test_get_branches(self):
 
132
        repo = self.make_repository('branch-1')
 
133
        target_branch = repo.bzrdir.create_branch(name='foo')
 
134
        self.assertEqual(['foo'], repo.bzrdir.get_branches().keys())
 
135
        self.assertEqual(target_branch.base,
 
136
                         repo.bzrdir.get_branches()['foo'].base)