~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_tag.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
from bzrlib import (
 
19
    branch,
 
20
    bzrdir,
 
21
    errors,
 
22
    tag,
 
23
    )
 
24
from bzrlib.tag import (
 
25
    BasicTags,
 
26
    _merge_tags_if_possible,
 
27
    )
 
28
from bzrlib.tests import (
 
29
    TestCase,
 
30
    TestCaseWithTransport,
 
31
    )
 
32
 
 
33
 
 
34
class TestTagSerialization(TestCase):
 
35
 
 
36
    def test_tag_serialization(self):
 
37
        """Test the precise representation of tag dicts."""
 
38
        # Don't change this after we commit to this format, as it checks 
 
39
        # that the format is stable and compatible across releases.
 
40
        #
 
41
        # This release stores them in bencode as a dictionary from name to
 
42
        # target.
 
43
        store = BasicTags(branch=None)
 
44
        td = dict(stable='stable-revid', boring='boring-revid')
 
45
        packed = store._serialize_tag_dict(td)
 
46
        expected = r'd6:boring12:boring-revid6:stable12:stable-revide'
 
47
        self.assertEqualDiff(packed, expected)
 
48
        self.assertEqual(store._deserialize_tag_dict(packed), td)
 
49
 
 
50
 
 
51
class TestTagMerging(TestCaseWithTransport):
 
52
 
 
53
    def make_knit_branch(self, relpath):
 
54
        old_bdf = bzrdir.format_registry.make_bzrdir('knit')
 
55
        return bzrdir.BzrDir.create_branch_convenience(relpath, format=old_bdf)
 
56
 
 
57
    def make_branch_supporting_tags(self, relpath):
 
58
        return self.make_branch(relpath, format='dirstate-tags')
 
59
 
 
60
    def test_merge_not_possible(self):
 
61
        # test merging between branches which do and don't support tags
 
62
        old_branch = self.make_knit_branch('old')
 
63
        new_branch = self.make_branch_supporting_tags('new')
 
64
        # just to make sure this test is valid
 
65
        self.assertFalse(old_branch.supports_tags(),
 
66
            "%s is expected to not support tags but does" % old_branch)
 
67
        self.assertTrue(new_branch.supports_tags(),
 
68
            "%s is expected to support tags but does not" % new_branch)
 
69
        # there are no tags in the old one, and we can merge from it into the
 
70
        # new one
 
71
        old_branch.tags.merge_to(new_branch.tags)
 
72
        # we couldn't merge tags from the new branch to the old one, but as
 
73
        # there are not any yet this isn't a problem
 
74
        new_branch.tags.merge_to(old_branch.tags)
 
75
        # but if there is a tag in the new one, we get a warning when trying
 
76
        # to move it back
 
77
        new_branch.tags.set_tag(u'\u2040tag', 'revid')
 
78
        old_branch.tags.merge_to(new_branch.tags)
 
79
        self.assertRaises(errors.TagsNotSupported,
 
80
            new_branch.tags.merge_to, old_branch.tags)