20
20
1:1 with Branch implementations so can be tested from here.
30
from bzrlib.tests import per_branch
33
class TestBranchTags(per_branch.TestCaseWithBranch):
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):
36
super(TestBranchTags, self).setUp()
40
TestCaseWithBranch.setUp(self)
37
41
# formats that don't support tags can skip the rest of these
39
43
branch = self.make_branch('probe')
40
44
if not branch._format.supports_tags():
41
raise tests.TestSkipped(
42
"format %s doesn't support tags" % branch._format)
45
raise TestSkipped("format %s doesn't support tags" % branch._format)
44
47
def test_tags_initially_empty(self):
45
48
b = self.make_branch('b')
51
54
b.tags.set_tag('tag-name', 'target-revid-1')
52
55
b.tags.set_tag('other-name', 'target-revid-2')
53
56
# then reopen the branch and see they're still there
54
b = branch.Branch.open('b')
55
58
self.assertEqual(b.tags.get_tag_dict(),
56
59
{'tag-name': 'target-revid-1',
57
60
'other-name': 'target-revid-2',
68
71
b.tags.set_tag('tag-name', 'target-revid-1')
69
72
b.tags.set_tag('other-name', 'target-revid-2')
70
73
# then reopen the branch and check reverse map id->tags list
71
b = branch.Branch.open('b')
72
75
self.assertEqual(b.tags.get_reverse_tag_dict(),
73
76
{'target-revid-1': ['tag-name'],
74
77
'target-revid-2': ['other-name'],
144
147
b1.tags.merge_to(b2.tags)
147
class TestUnsupportedTags(per_branch.TestCaseWithBranch):
150
class TestUnsupportedTags(TestCaseWithBranch):
148
151
"""Formats that don't support tags should give reasonable errors."""
151
super(TestUnsupportedTags, self).setUp()
154
TestCaseWithBranch.setUp(self)
152
155
branch = self.make_branch('probe')
153
156
if branch._format.supports_tags():
154
raise tests.TestSkipped("Format %s declares that tags are supported"
157
raise TestSkipped("Format %s declares that tags are supported"
156
159
# it's covered by TestBranchTags
158
161
def test_tag_methods_raise(self):
171
174
b1 = self.make_branch('b1')
172
175
b2 = self.make_branch('b2')
173
176
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()))