6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
1 |
# Copyright (C) 2007, 2009-2012, 2016 Canonical Ltd
|
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
16 |
|
5086.4.8
by Jelmer Vernooij
Review comments from Ian. |
17 |
"""Tests for bzrlib.tag."""
|
18 |
||
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
19 |
|
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
20 |
from bzrlib import ( |
6472.2.1
by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories. |
21 |
controldir, |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
22 |
errors, |
23 |
)
|
|
24 |
from bzrlib.tag import ( |
|
25 |
BasicTags, |
|
2831.8.1
by James Westby
Fix log against smart server branches that don't support tags. (#140615) |
26 |
DisabledTags, |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
27 |
)
|
28 |
from bzrlib.tests import ( |
|
29 |
TestCase, |
|
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
30 |
TestCaseWithTransport, |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
31 |
)
|
32 |
||
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
33 |
|
34 |
class TestTagSerialization(TestCase): |
|
35 |
||
36 |
def test_tag_serialization(self): |
|
37 |
"""Test the precise representation of tag dicts."""
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
38 |
# Don't change this after we commit to this format, as it checks
|
2220.2.15
by mbp at sourcefrog
Store tag dictionary in bencode and accomodate non-ascii tags |
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.
|
|
2220.2.20
by Martin Pool
Tag methods now available through Branch.tags.add_tag, etc |
43 |
store = BasicTags(branch=None) |
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
44 |
td = dict(stable='stable-revid', boring='boring-revid') |
45 |
packed = store._serialize_tag_dict(td) |
|
2220.2.15
by mbp at sourcefrog
Store tag dictionary in bencode and accomodate non-ascii tags |
46 |
expected = r'd6:boring12:boring-revid6:stable12:stable-revide' |
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
47 |
self.assertEqualDiff(packed, expected) |
48 |
self.assertEqual(store._deserialize_tag_dict(packed), td) |
|
49 |
||
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
50 |
|
4325.2.1
by Jelmer Vernooij
Add Tags.rename_revisions(). |
51 |
class TestTagRevisionRenames(TestCaseWithTransport): |
52 |
||
53 |
def make_branch_supporting_tags(self, relpath): |
|
54 |
return self.make_branch(relpath, format='dirstate-tags') |
|
55 |
||
56 |
def test_simple(self): |
|
57 |
store = self.make_branch_supporting_tags('a').tags |
|
58 |
store.set_tag("foo", "myoldrevid") |
|
59 |
store.rename_revisions({"myoldrevid": "mynewrevid"}) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
60 |
self.assertEqual({"foo": "mynewrevid"}, store.get_tag_dict()) |
4325.2.1
by Jelmer Vernooij
Add Tags.rename_revisions(). |
61 |
|
62 |
def test_unknown_ignored(self): |
|
63 |
store = self.make_branch_supporting_tags('a').tags |
|
64 |
store.set_tag("foo", "myoldrevid") |
|
65 |
store.rename_revisions({"anotherrevid": "mynewrevid"}) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
66 |
self.assertEqual({"foo": "myoldrevid"}, store.get_tag_dict()) |
4325.2.1
by Jelmer Vernooij
Add Tags.rename_revisions(). |
67 |
|
68 |
||
2255.2.194
by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests. |
69 |
class TestTagMerging(TestCaseWithTransport): |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
70 |
|
71 |
def make_knit_branch(self, relpath): |
|
6472.2.1
by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories. |
72 |
old_bdf = controldir.format_registry.make_bzrdir('knit') |
73 |
return controldir.ControlDir.create_branch_convenience(relpath, format=old_bdf) |
|
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
74 |
|
75 |
def make_branch_supporting_tags(self, relpath): |
|
1551.13.1
by Aaron Bentley
Introduce dirstate-tags format |
76 |
return self.make_branch(relpath, format='dirstate-tags') |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
77 |
|
78 |
def test_merge_not_possible(self): |
|
79 |
# test merging between branches which do and don't support tags
|
|
80 |
old_branch = self.make_knit_branch('old') |
|
81 |
new_branch = self.make_branch_supporting_tags('new') |
|
82 |
# just to make sure this test is valid
|
|
83 |
self.assertFalse(old_branch.supports_tags(), |
|
84 |
"%s is expected to not support tags but does" % old_branch) |
|
85 |
self.assertTrue(new_branch.supports_tags(), |
|
86 |
"%s is expected to support tags but does not" % new_branch) |
|
87 |
# there are no tags in the old one, and we can merge from it into the
|
|
88 |
# new one
|
|
2220.2.31
by Martin Pool
tag cleanups |
89 |
old_branch.tags.merge_to(new_branch.tags) |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
90 |
# we couldn't merge tags from the new branch to the old one, but as
|
91 |
# there are not any yet this isn't a problem
|
|
2220.2.31
by Martin Pool
tag cleanups |
92 |
new_branch.tags.merge_to(old_branch.tags) |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
93 |
# but if there is a tag in the new one, we get a warning when trying
|
94 |
# to move it back
|
|
95 |
new_branch.tags.set_tag(u'\u2040tag', 'revid') |
|
2220.2.31
by Martin Pool
tag cleanups |
96 |
old_branch.tags.merge_to(new_branch.tags) |
2220.2.30
by Martin Pool
split out tag-merging code and add some tests |
97 |
self.assertRaises(errors.TagsNotSupported, |
2220.2.31
by Martin Pool
tag cleanups |
98 |
new_branch.tags.merge_to, old_branch.tags) |
2804.3.1
by Lukáš Lalinský
Overwrite conflicting tags by push|pull --overwrite. |
99 |
|
100 |
def test_merge_to(self): |
|
101 |
a = self.make_branch_supporting_tags('a') |
|
102 |
b = self.make_branch_supporting_tags('b') |
|
103 |
# simple merge
|
|
104 |
a.tags.set_tag('tag-1', 'x') |
|
105 |
b.tags.set_tag('tag-2', 'y') |
|
106 |
a.tags.merge_to(b.tags) |
|
107 |
self.assertEqual('x', b.tags.lookup_tag('tag-1')) |
|
108 |
self.assertEqual('y', b.tags.lookup_tag('tag-2')) |
|
109 |
self.assertRaises(errors.NoSuchTag, a.tags.lookup_tag, 'tag-2') |
|
110 |
# conflicting merge
|
|
111 |
a.tags.set_tag('tag-2', 'z') |
|
6112.4.2
by Jelmer Vernooij
Fix tag tests. |
112 |
updates, conflicts = a.tags.merge_to(b.tags) |
113 |
self.assertEqual({}, updates) |
|
5540.4.4
by Andrew Bennetts
Make the tests more relaxed about the return type of merge_to (don't assume lists) |
114 |
self.assertEqual(list(conflicts), [('tag-2', 'z', 'y')]) |
2804.3.1
by Lukáš Lalinský
Overwrite conflicting tags by push|pull --overwrite. |
115 |
self.assertEqual('y', b.tags.lookup_tag('tag-2')) |
116 |
# overwrite conflicts
|
|
6112.4.2
by Jelmer Vernooij
Fix tag tests. |
117 |
updates, conflicts = a.tags.merge_to(b.tags, overwrite=True) |
5540.4.4
by Andrew Bennetts
Make the tests more relaxed about the return type of merge_to (don't assume lists) |
118 |
self.assertEqual(list(conflicts), []) |
6156.1.2
by Jelmer Vernooij
Fix tests. |
119 |
self.assertEqual({u'tag-2': 'z'}, updates) |
2804.3.1
by Lukáš Lalinský
Overwrite conflicting tags by push|pull --overwrite. |
120 |
self.assertEqual('z', b.tags.lookup_tag('tag-2')) |
2805.5.4
by Martin Pool
merge trunk |
121 |
|
2805.5.1
by Martin Pool
Start adding tests for bug 93860 |
122 |
|
123 |
class TestTagsInCheckouts(TestCaseWithTransport): |
|
5050.53.1
by Andrew Bennetts
Tags.merge_to now updates the master branch as well, if any. |
124 |
"""Tests for how tags are synchronised between the master and child branch
|
125 |
of a checkout.
|
|
126 |
"""
|
|
2805.5.1
by Martin Pool
Start adding tests for bug 93860 |
127 |
|
2805.5.5
by Martin Pool
Add another test that tags work ok in checkouts |
128 |
def test_update_tag_into_checkout(self): |
2805.5.1
by Martin Pool
Start adding tests for bug 93860 |
129 |
# checkouts are directly connected to the tags of their master branch:
|
130 |
# adding a tag in the checkout pushes it to the master
|
|
2805.5.3
by Martin Pool
In checkouts, tags are copied into the master branch when created, changed or deleted, and are copied into the checkout when it is updated. (Martin Pool, #93856, #93860) |
131 |
# https://bugs.launchpad.net/bzr/+bug/93860
|
2805.5.2
by Martin Pool
Setting and deleting tags should also update the master branch, if any. |
132 |
master = self.make_branch('master') |
133 |
child = self.make_branch('child') |
|
134 |
child.bind(master) |
|
135 |
child.tags.set_tag('foo', 'rev-1') |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
136 |
self.assertEqual('rev-1', master.tags.lookup_tag('foo')) |
2805.5.2
by Martin Pool
Setting and deleting tags should also update the master branch, if any. |
137 |
# deleting a tag updates the master too
|
138 |
child.tags.delete_tag('foo') |
|
139 |
self.assertRaises(errors.NoSuchTag, |
|
140 |
master.tags.lookup_tag, 'foo') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
141 |
|
2805.5.5
by Martin Pool
Add another test that tags work ok in checkouts |
142 |
def test_tag_copied_by_initial_checkout(self): |
143 |
# https://bugs.launchpad.net/bzr/+bug/93860
|
|
144 |
master = self.make_branch('master') |
|
145 |
master.tags.set_tag('foo', 'rev-1') |
|
146 |
co_tree = master.create_checkout('checkout') |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
147 |
self.assertEqual('rev-1', |
2805.5.5
by Martin Pool
Add another test that tags work ok in checkouts |
148 |
co_tree.branch.tags.lookup_tag('foo')) |
2805.5.1
by Martin Pool
Start adding tests for bug 93860 |
149 |
|
150 |
def test_update_updates_tags(self): |
|
2805.5.3
by Martin Pool
In checkouts, tags are copied into the master branch when created, changed or deleted, and are copied into the checkout when it is updated. (Martin Pool, #93856, #93860) |
151 |
# https://bugs.launchpad.net/bzr/+bug/93856
|
152 |
master = self.make_branch('master') |
|
153 |
master.tags.set_tag('foo', 'rev-1') |
|
154 |
child = self.make_branch('child') |
|
155 |
child.bind(master) |
|
156 |
child.update() |
|
157 |
# after an update, the child has all the master's tags
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
158 |
self.assertEqual('rev-1', child.tags.lookup_tag('foo')) |
2805.5.3
by Martin Pool
In checkouts, tags are copied into the master branch when created, changed or deleted, and are copied into the checkout when it is updated. (Martin Pool, #93856, #93860) |
159 |
# add another tag and update again
|
160 |
master.tags.set_tag('tag2', 'target2') |
|
161 |
child.update() |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
162 |
self.assertEqual('target2', child.tags.lookup_tag('tag2')) |
2805.5.3
by Martin Pool
In checkouts, tags are copied into the master branch when created, changed or deleted, and are copied into the checkout when it is updated. (Martin Pool, #93856, #93860) |
163 |
|
5050.53.2
by Andrew Bennetts
More tests, more description of test intent, and specify exactly what happens with duplicate vs. different conflicts. |
164 |
def test_tag_deletion_from_master_to_bound(self): |
165 |
master = self.make_branch('master') |
|
166 |
master.tags.set_tag('foo', 'rev-1') |
|
167 |
child = self.make_branch('child') |
|
168 |
child.bind(master) |
|
169 |
child.update() |
|
170 |
# and deletion of tags should also propagate
|
|
171 |
master.tags.delete_tag('foo') |
|
6050.1.3
by Martin
Fix syntax typo in test_tag |
172 |
self.knownFailure("tag deletion does not propagate: " |
5050.53.2
by Andrew Bennetts
More tests, more description of test intent, and specify exactly what happens with duplicate vs. different conflicts. |
173 |
"https://bugs.launchpad.net/bzr/+bug/138802") |
174 |
self.assertRaises(errors.NoSuchTag, |
|
175 |
child.tags.lookup_tag, 'foo') |
|
176 |
||
177 |
||
2831.8.1
by James Westby
Fix log against smart server branches that don't support tags. (#140615) |
178 |
class DisabledTagsTests(TestCaseWithTransport): |
179 |
||
180 |
def setUp(self): |
|
181 |
super(DisabledTagsTests, self).setUp() |
|
182 |
branch = self.make_branch('.') |
|
183 |
self.tags = DisabledTags(branch) |
|
184 |
||
185 |
def test_set_tag(self): |
|
186 |
self.assertRaises(errors.TagsNotSupported, self.tags.set_tag) |
|
187 |
||
188 |
def test_get_reverse_tag_dict(self): |
|
189 |
self.assertEqual(self.tags.get_reverse_tag_dict(), {}) |
|
5086.4.1
by Jelmer Vernooij
New function ``determine_tag_name`` that can be used to find a |
190 |
|
191 |
||
5086.4.7
by Jelmer Vernooij
Put automatic_tag_name on Branch. |
192 |