1
# Copyright (C) 2005, 2006, 2008, 2009, 2011, 2016 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
3
"""Tests for revision properties."""
19
from breezy.tests import TestNotApplicable
20
from breezy.tests.per_repository import (
21
TestCaseWithRepository,
25
class TestRevProps(TestCaseWithRepository):
5
from bzrlib.tests import TestCaseWithTransport
7
class TestRevProps(TestCaseWithTransport):
27
9
def test_simple_revprops(self):
28
10
"""Simple revision properties"""
29
11
wt = self.make_branch_and_tree('.')
31
13
b.nick = 'Nicholas'
32
if b.repository._format.supports_custom_revision_properties:
33
props = {u'flavor': 'choc-mint',
34
u'condiment': 'orange\n mint\n\tcandy',
36
u'non_ascii': u'\xb5'}
39
rev1 = wt.commit(message='initial null commit',
42
rev = b.repository.get_revision(rev1)
43
if b.repository._format.supports_custom_revision_properties:
44
self.assertTrue(u'flavor' in rev.properties)
45
self.assertEqual(rev.properties[u'flavor'], 'choc-mint')
47
u'condiment': 'orange\n mint\n\tcandy',
49
u'flavor': 'choc-mint',
50
u'non_ascii': u'\xb5',
53
expected_revprops = {}
54
if b.repository._format.supports_storing_branch_nick:
55
expected_revprops[u'branch-nick'] = 'Nicholas'
56
for name, value in expected_revprops.items():
57
self.assertEqual(rev.properties[name], value)
14
props = dict(flavor='choc-mint',
15
condiment='orange\n mint\n\tcandy')
16
wt.commit(message='initial null commit',
20
rev = b.repository.get_revision('test@user-1')
21
self.assertTrue('flavor' in rev.properties)
22
self.assertEquals(rev.properties['flavor'], 'choc-mint')
23
self.assertEquals(sorted(rev.properties.items()),
24
[('branch-nick', 'Nicholas'),
25
('condiment', 'orange\n mint\n\tcandy'),
26
('flavor', 'choc-mint')])
59
28
def test_invalid_revprops(self):
60
29
"""Invalid revision properties"""
61
30
wt = self.make_branch_and_tree('.')
63
if not b.repository._format.supports_custom_revision_properties:
64
raise TestNotApplicable(
65
'format does not support custom revision properties')
66
32
self.assertRaises(ValueError,
69
35
revprops={'what a silly property': 'fine'})
70
36
self.assertRaises(ValueError,
73
39
revprops=dict(number=13))
76
class TestRevisionAttributes(TestCaseWithRepository):
77
"""Test that revision attributes are correct."""
79
def test_revision_accessors(self):
80
"""Make sure the values that come out of a revision are the
81
same as the ones that go in.
83
tree1 = self.make_branch_and_tree("br1")
84
if tree1.branch.repository._format.supports_custom_revision_properties:
85
revprops = {u'empty': '',
88
u'multiline': 'foo\nbar\n\n'
93
rev1 = tree1.commit(message="quux", allow_pointless=True,
94
committer="jaq", revprops=revprops)
95
self.assertEqual(tree1.branch.last_revision(), rev1)
96
rev_a = tree1.branch.repository.get_revision(
97
tree1.branch.last_revision())
99
tree2 = self.make_branch_and_tree("br2")
100
tree2.commit(message=rev_a.message,
101
timestamp=rev_a.timestamp,
102
timezone=rev_a.timezone,
103
committer=rev_a.committer,
104
rev_id=(rev_a.revision_id
105
if tree2.branch.repository._format.supports_setting_revision_ids
107
revprops=rev_a.properties,
108
allow_pointless=True, # there's nothing in this commit
111
rev_b = tree2.branch.repository.get_revision(
112
tree2.branch.last_revision())
114
self.assertEqual(rev_a.message, rev_b.message)
115
self.assertEqual(rev_a.timestamp, rev_b.timestamp)
116
self.assertEqual(rev_a.timezone, rev_b.timezone)
117
self.assertEqual(rev_a.committer, rev_b.committer)
118
self.assertEqual(rev_a.revision_id, rev_b.revision_id)
119
self.assertEqual(rev_a.properties, rev_b.properties)
121
def test_zero_timezone(self):
122
tree1 = self.make_branch_and_tree("br1")
125
r1 = tree1.commit(message="quux", timezone=0)
126
rev_a = tree1.branch.repository.get_revision(r1)
127
self.assertEqual(0, rev_a.timezone)