20
20
1:1 with Branch implementations so can be tested from here.
28
from bzrlib import bzrdir, errors, repository
29
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
30
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
31
from bzrlib.trace import mutter
32
from bzrlib.workingtree import WorkingTree
34
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
37
class TestBranchTags(TestCaseWithBranch):
30
from bzrlib.tests import per_branch
33
class TestBranchTags(per_branch.TestCaseWithBranch):
40
TestCaseWithBranch.setUp(self)
36
super(TestBranchTags, self).setUp()
41
37
# formats that don't support tags can skip the rest of these
43
39
branch = self.make_branch('probe')
44
40
if not branch._format.supports_tags():
45
raise TestSkipped("format %s doesn't support tags" % branch._format)
41
raise tests.TestSkipped(
42
"format %s doesn't support tags" % branch._format)
47
44
def test_tags_initially_empty(self):
48
45
b = self.make_branch('b')
54
51
b.tags.set_tag('tag-name', 'target-revid-1')
55
52
b.tags.set_tag('other-name', 'target-revid-2')
56
53
# then reopen the branch and see they're still there
54
b = branch.Branch.open('b')
58
55
self.assertEqual(b.tags.get_tag_dict(),
59
56
{'tag-name': 'target-revid-1',
60
57
'other-name': 'target-revid-2',
71
68
b.tags.set_tag('tag-name', 'target-revid-1')
72
69
b.tags.set_tag('other-name', 'target-revid-2')
73
70
# then reopen the branch and check reverse map id->tags list
71
b = branch.Branch.open('b')
75
72
self.assertEqual(b.tags.get_reverse_tag_dict(),
76
73
{'target-revid-1': ['tag-name'],
77
74
'target-revid-2': ['other-name'],
147
144
b1.tags.merge_to(b2.tags)
150
class TestUnsupportedTags(TestCaseWithBranch):
147
class TestUnsupportedTags(per_branch.TestCaseWithBranch):
151
148
"""Formats that don't support tags should give reasonable errors."""
154
TestCaseWithBranch.setUp(self)
151
super(TestUnsupportedTags, self).setUp()
155
152
branch = self.make_branch('probe')
156
153
if branch._format.supports_tags():
157
raise TestSkipped("Format %s declares that tags are supported"
154
raise tests.TestSkipped("Format %s declares that tags are supported"
159
156
# it's covered by TestBranchTags
161
158
def test_tag_methods_raise(self):
174
171
b1 = self.make_branch('b1')
175
172
b2 = self.make_branch('b2')
176
173
b1.tags.merge_to(b2.tags)
176
class AutomaticTagNameTests(per_branch.TestCaseWithBranch):
179
super(AutomaticTagNameTests, self).setUp()
180
if isinstance(self.branch_format, branch.BranchReferenceFormat):
181
# This test could in principle apply to BranchReferenceFormat, but
182
# make_branch_builder doesn't support it.
183
raise tests.TestSkipped(
184
"BranchBuilder can't make reference branches.")
185
self.builder = self.make_branch_builder('.')
186
self.builder.build_snapshot('foo', None,
187
[('add', ('', None, 'directory', None))],
189
self.branch = self.builder.get_branch()
190
if not self.branch._format.supports_tags():
191
raise tests.TestSkipped(
192
"format %s doesn't support tags" % self.branch._format)
194
def test_no_functions(self):
195
rev = self.branch.last_revision()
196
self.assertEquals(None, self.branch.automatic_tag_name(rev))
198
def test_returns_tag_name(self):
199
def get_tag_name(br, revid):
201
branch.Branch.hooks.install_named_hook('automatic_tag_name',
202
get_tag_name, 'get tag name foo')
203
self.assertEquals("foo", self.branch.automatic_tag_name(
204
self.branch.last_revision()))
206
def test_uses_first_return(self):
207
get_tag_name_1 = lambda br, revid: "foo1"
208
get_tag_name_2 = lambda br, revid: "foo2"
209
branch.Branch.hooks.install_named_hook('automatic_tag_name',
210
get_tag_name_1, 'tagname1')
211
branch.Branch.hooks.install_named_hook('automatic_tag_name',
212
get_tag_name_2, 'tagname2')
213
self.assertEquals("foo1", self.branch.automatic_tag_name(
214
self.branch.last_revision()))
216
def test_ignores_none(self):
217
get_tag_name_1 = lambda br, revid: None
218
get_tag_name_2 = lambda br, revid: "foo2"
219
branch.Branch.hooks.install_named_hook('automatic_tag_name',
220
get_tag_name_1, 'tagname1')
221
branch.Branch.hooks.install_named_hook('automatic_tag_name',
222
get_tag_name_2, 'tagname2')
223
self.assertEquals("foo2", self.branch.automatic_tag_name(
224
self.branch.last_revision()))