~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2007 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
 
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):
 
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):
34
38
 
35
39
    def setUp(self):
36
 
        super(TestBranchTags, self).setUp()
 
40
        TestCaseWithBranch.setUp(self)
37
41
        # formats that don't support tags can skip the rest of these
38
42
        # tests...
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)
43
46
 
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')
 
57
        b = 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')
 
74
        b = 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)
145
148
 
146
149
 
147
 
class TestUnsupportedTags(per_branch.TestCaseWithBranch):
 
150
class TestUnsupportedTags(TestCaseWithBranch):
148
151
    """Formats that don't support tags should give reasonable errors."""
149
152
 
150
153
    def setUp(self):
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"
155
 
                                    % branch._format)
 
157
            raise TestSkipped("Format %s declares that tags are supported"
 
158
                              % branch._format)
156
159
            # it's covered by TestBranchTags
157
160
 
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)
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()))