~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011, 2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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.assertEqual("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.assertEqual(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.assertEqual(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.assertEqual(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)
 
137
 
 
138
    def test_branch_name_with_slash(self):
 
139
        repo = self.make_repository('branch-1')
 
140
        try:
 
141
            target_branch = repo.bzrdir.create_branch(name='foo/bar')
 
142
        except errors.InvalidBranchName:
 
143
            raise tests.TestNotApplicable(
 
144
                "format does not support branches with / in their name")
 
145
        self.assertEqual(['foo/bar'], repo.bzrdir.get_branches().keys())
 
146
        self.assertEqual(
 
147
            target_branch.base, repo.bzrdir.open_branch(name='foo/bar').base)
 
148
 
 
149
    def test_branch_reference(self):
 
150
        referenced = self.make_branch('referenced')
 
151
        repo = self.make_repository('repo')
 
152
        try:
 
153
            repo.bzrdir.set_branch_reference(referenced, name='foo')
 
154
        except errors.IncompatibleFormat:
 
155
            raise tests.TestNotApplicable(
 
156
                'Control dir does not support creating branch references.')
 
157
        self.assertEqual(referenced.base,
 
158
            repo.bzrdir.get_branch_reference('foo'))