~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_tags.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2009, 2010 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
20
20
1:1 with Branch implementations so can be tested from here.
21
21
"""
22
22
 
23
 
import os
24
 
import re
25
 
import sys
26
 
 
27
 
import bzrlib
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
33
 
 
34
 
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
35
 
 
36
 
 
37
 
class TestBranchTags(TestCaseWithBranch):
 
23
from bzrlib import (
 
24
    branch,
 
25
    bzrdir,
 
26
    errors,
 
27
    repository,
 
28
    tests,
 
29
    )
 
30
from bzrlib.tests import per_branch
 
31
 
 
32
 
 
33
class TestBranchTags(per_branch.TestCaseWithBranch):
38
34
 
39
35
    def setUp(self):
40
 
        TestCaseWithBranch.setUp(self)
 
36
        super(TestBranchTags, self).setUp()
41
37
        # formats that don't support tags can skip the rest of these
42
38
        # tests...
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)
46
43
 
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
57
 
        b = Branch.open('b')
 
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
74
 
        b = Branch.open('b')
 
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)
148
145
 
149
146
 
150
 
class TestUnsupportedTags(TestCaseWithBranch):
 
147
class TestUnsupportedTags(per_branch.TestCaseWithBranch):
151
148
    """Formats that don't support tags should give reasonable errors."""
152
149
 
153
150
    def setUp(self):
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"
158
 
                              % branch._format)
 
154
            raise tests.TestSkipped("Format %s declares that tags are supported"
 
155
                                    % branch._format)
159
156
            # it's covered by TestBranchTags
160
157
 
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)
 
174
 
 
175
 
 
176
class AutomaticTagNameTests(per_branch.TestCaseWithBranch):
 
177
 
 
178
    def setUp(self):
 
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))],
 
188
            message='foo')
 
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)
 
193
 
 
194
    def test_no_functions(self):
 
195
        rev = self.branch.last_revision()
 
196
        self.assertEquals(None, self.branch.automatic_tag_name(rev))
 
197
 
 
198
    def test_returns_tag_name(self):
 
199
        def get_tag_name(br, revid):
 
200
            return "foo"
 
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()))
 
205
    
 
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()))
 
215
 
 
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()))