1
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2007, 2009-2012, 2016 Canonical Ltd
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
90
90
b.tags.set_tag, "ghost", "idontexist")
92
92
b.tags.set_tag("ghost", "idontexist")
93
self.assertEquals("idontexist", b.tags.lookup_tag("ghost"))
93
self.assertEqual("idontexist", b.tags.lookup_tag("ghost"))
95
95
def test_no_such_tag(self):
96
96
b = self.make_branch('b')
98
98
b.tags.lookup_tag('bosko')
99
99
except errors.NoSuchTag, e:
100
self.assertEquals(e.tag_name, 'bosko')
101
self.assertEquals(str(e), 'No such tag: bosko')
100
self.assertEqual(e.tag_name, 'bosko')
101
self.assertEqual(str(e), 'No such tag: bosko')
103
103
self.fail("didn't get expected exception")
110
110
b1.tags.set_tag('tagname', 'revid')
111
111
b1.tags.merge_to(b2.tags)
112
self.assertEquals(b2.tags.lookup_tag('tagname'), 'revid')
112
self.assertEqual(b2.tags.lookup_tag('tagname'), 'revid')
113
113
# if a tag is in the destination and not in the source, it is not
114
114
# removed when we merge them
115
115
b2.tags.set_tag('in-destination', 'revid')
116
116
updates, conflicts = b1.tags.merge_to(b2.tags)
117
self.assertEquals(list(conflicts), [])
118
self.assertEquals(updates, {})
119
self.assertEquals(b2.tags.lookup_tag('in-destination'), 'revid')
117
self.assertEqual(list(conflicts), [])
118
self.assertEqual(updates, {})
119
self.assertEqual(b2.tags.lookup_tag('in-destination'), 'revid')
120
120
# if there's a conflicting tag, it's reported -- the command line
121
121
# interface will say "these tags couldn't be copied"
122
122
b1.tags.set_tag('conflicts', 'revid-1')
123
123
b2.tags.set_tag('conflicts', 'revid-2')
124
124
updates, conflicts = b1.tags.merge_to(b2.tags)
125
self.assertEquals(list(conflicts),
125
self.assertEqual(list(conflicts),
126
126
[('conflicts', 'revid-1', 'revid-2')])
127
127
# and it keeps the same value
128
self.assertEquals(updates, {})
129
self.assertEquals(b2.tags.lookup_tag('conflicts'), 'revid-2')
128
self.assertEqual(updates, {})
129
self.assertEqual(b2.tags.lookup_tag('conflicts'), 'revid-2')
131
131
def test_unicode_tag(self):
132
132
tag_name = u'\u3070'
135
135
revid = ('revid' + tag_name).encode('utf-8')
136
136
b1 = self.make_branch_with_revisions('b', [revid])
137
137
b1.tags.set_tag(tag_name, revid)
138
self.assertEquals(b1.tags.lookup_tag(tag_name), revid)
138
self.assertEqual(b1.tags.lookup_tag(tag_name), revid)
140
140
def test_delete_tag(self):
141
141
tag_name = u'\N{GREEK SMALL LETTER ALPHA}'
148
148
self.assertRaises(errors.NoSuchTag,
149
149
b.tags.lookup_tag, tag_name)
150
150
# and it's not in the dictionary
151
self.assertEquals(b.tags.get_tag_dict(), {})
151
self.assertEqual(b.tags.get_tag_dict(), {})
152
152
# and you can't remove it a second time
153
153
self.assertRaises(errors.NoSuchTag,
154
154
b.tags.delete_tag, tag_name)
290
290
child.bind(master)
292
292
other.tags.merge_to(child.tags)
293
self.assertEquals('rev-1', child.tags.lookup_tag('foo'))
294
self.assertEquals('rev-1', master.tags.lookup_tag('foo'))
293
self.assertEqual('rev-1', child.tags.lookup_tag('foo'))
294
self.assertEqual('rev-1', master.tags.lookup_tag('foo'))
296
296
def test_ignore_master_disables_tag_propagation(self):
297
297
"""merge_to(child, ignore_master=True) does not merge tags to the
304
304
child.bind(master)
306
306
other.tags.merge_to(child.tags, ignore_master=True)
307
self.assertEquals('rev-1', child.tags.lookup_tag('foo'))
307
self.assertEqual('rev-1', child.tags.lookup_tag('foo'))
308
308
self.assertRaises(errors.NoSuchTag, master.tags.lookup_tag, 'foo')
310
310
def test_merge_to_overwrite_conflict_in_master(self):
320
320
master.tags.set_tag('foo', 'rev-2')
321
321
tag_updates, tag_conflicts = other.tags.merge_to(child.tags, overwrite=True)
322
self.assertEquals('rev-1', child.tags.lookup_tag('foo'))
323
self.assertEquals('rev-1', master.tags.lookup_tag('foo'))
324
self.assertEquals({"foo": "rev-1"}, tag_updates)
322
self.assertEqual('rev-1', child.tags.lookup_tag('foo'))
323
self.assertEqual('rev-1', master.tags.lookup_tag('foo'))
324
self.assertEqual({"foo": "rev-1"}, tag_updates)
325
325
self.assertLength(0, tag_conflicts)
327
327
def test_merge_to_overwrite_conflict_in_child_and_master(self):
338
338
tag_updates, tag_conflicts = other.tags.merge_to(
339
339
child.tags, overwrite=True)
340
self.assertEquals('rev-1', child.tags.lookup_tag('foo'))
341
self.assertEquals('rev-1', master.tags.lookup_tag('foo'))
342
self.assertEquals({u'foo': 'rev-1'}, tag_updates)
340
self.assertEqual('rev-1', child.tags.lookup_tag('foo'))
341
self.assertEqual('rev-1', master.tags.lookup_tag('foo'))
342
self.assertEqual({u'foo': 'rev-1'}, tag_updates)
343
343
self.assertLength(0, tag_conflicts)
345
345
def test_merge_to_conflict_in_child_only(self):
356
356
master.tags.delete_tag('foo')
357
357
tag_updates, tag_conflicts = other.tags.merge_to(child.tags)
358
358
# Conflict in child, so it is unchanged.
359
self.assertEquals('rev-2', child.tags.lookup_tag('foo'))
359
self.assertEqual('rev-2', child.tags.lookup_tag('foo'))
360
360
# No conflict in the master, so the 'foo' tag equals other's value here.
361
self.assertEquals('rev-1', master.tags.lookup_tag('foo'))
361
self.assertEqual('rev-1', master.tags.lookup_tag('foo'))
362
362
# The conflict is reported.
363
self.assertEquals([(u'foo', 'rev-1', 'rev-2')], list(tag_conflicts))
364
self.assertEquals({u'foo': 'rev-1'}, tag_updates)
363
self.assertEqual([(u'foo', 'rev-1', 'rev-2')], list(tag_conflicts))
364
self.assertEqual({u'foo': 'rev-1'}, tag_updates)
366
366
def test_merge_to_conflict_in_master_only(self):
367
367
"""When new_tags.merge_to(child.tags) conflicts with the master but not
376
376
master.tags.set_tag('foo', 'rev-2')
377
377
tag_updates, tag_conflicts = other.tags.merge_to(child.tags)
378
378
# No conflict in the child, so the 'foo' tag equals other's value here.
379
self.assertEquals('rev-1', child.tags.lookup_tag('foo'))
379
self.assertEqual('rev-1', child.tags.lookup_tag('foo'))
380
380
# Conflict in master, so it is unchanged.
381
self.assertEquals('rev-2', master.tags.lookup_tag('foo'))
381
self.assertEqual('rev-2', master.tags.lookup_tag('foo'))
382
382
# The conflict is reported.
383
self.assertEquals({u'foo': 'rev-1'}, tag_updates)
384
self.assertEquals([(u'foo', 'rev-1', 'rev-2')], list(tag_conflicts))
383
self.assertEqual({u'foo': 'rev-1'}, tag_updates)
384
self.assertEqual([(u'foo', 'rev-1', 'rev-2')], list(tag_conflicts))
386
386
def test_merge_to_same_conflict_in_master_and_child(self):
387
387
"""When new_tags.merge_to(child.tags) conflicts the same way with the
397
397
tag_updates, tag_conflicts = other.tags.merge_to(child.tags)
398
398
# Both master and child conflict, so both stay as rev-2
399
self.assertEquals('rev-2', child.tags.lookup_tag('foo'))
400
self.assertEquals('rev-2', master.tags.lookup_tag('foo'))
399
self.assertEqual('rev-2', child.tags.lookup_tag('foo'))
400
self.assertEqual('rev-2', master.tags.lookup_tag('foo'))
401
401
# The conflict is reported exactly once, even though it occurs in both
402
402
# master and child.
403
self.assertEquals({}, tag_updates)
404
self.assertEquals([(u'foo', 'rev-1', 'rev-2')], list(tag_conflicts))
403
self.assertEqual({}, tag_updates)
404
self.assertEqual([(u'foo', 'rev-1', 'rev-2')], list(tag_conflicts))
406
406
def test_merge_to_different_conflict_in_master_and_child(self):
407
407
"""When new_tags.merge_to(child.tags) conflicts differently in the
419
419
child.tags._set_tag_dict({'foo': 'rev-3'})
420
420
tag_updates, tag_conflicts = other.tags.merge_to(child.tags)
421
421
# Both master and child conflict, so both stay as they were.
422
self.assertEquals('rev-3', child.tags.lookup_tag('foo'))
423
self.assertEquals('rev-2', master.tags.lookup_tag('foo'))
422
self.assertEqual('rev-3', child.tags.lookup_tag('foo'))
423
self.assertEqual('rev-2', master.tags.lookup_tag('foo'))
424
424
# Both conflicts are reported.
425
self.assertEquals({}, tag_updates)
425
self.assertEqual({}, tag_updates)
427
427
[(u'foo', 'rev-1', 'rev-2'), (u'foo', 'rev-1', 'rev-3')],
428
428
sorted(tag_conflicts))
478
478
def test_no_functions(self):
479
479
rev = self.branch.last_revision()
480
self.assertEquals(None, self.branch.automatic_tag_name(rev))
480
self.assertEqual(None, self.branch.automatic_tag_name(rev))
482
482
def test_returns_tag_name(self):
483
483
def get_tag_name(br, revid):
485
485
branch.Branch.hooks.install_named_hook('automatic_tag_name',
486
486
get_tag_name, 'get tag name foo')
487
self.assertEquals("foo", self.branch.automatic_tag_name(
487
self.assertEqual("foo", self.branch.automatic_tag_name(
488
488
self.branch.last_revision()))
490
490
def test_uses_first_return(self):
494
494
get_tag_name_1, 'tagname1')
495
495
branch.Branch.hooks.install_named_hook('automatic_tag_name',
496
496
get_tag_name_2, 'tagname2')
497
self.assertEquals("foo1", self.branch.automatic_tag_name(
497
self.assertEqual("foo1", self.branch.automatic_tag_name(
498
498
self.branch.last_revision()))
500
500
def test_ignores_none(self):
504
504
get_tag_name_1, 'tagname1')
505
505
branch.Branch.hooks.install_named_hook('automatic_tag_name',
506
506
get_tag_name_2, 'tagname2')
507
self.assertEquals("foo2", self.branch.automatic_tag_name(
507
self.assertEqual("foo2", self.branch.automatic_tag_name(
508
508
self.branch.last_revision()))