1
# Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
3
"""Tests for revision properties."""
19
from bzrlib.tests.repository_implementations.test_repository import (
20
TestCaseWithRepository,
23
class TestRevProps(TestCaseWithRepository):
5
from bzrlib.branch import Branch
6
from bzrlib.selftest import TestCaseInTempDir
8
class TestRevProps(TestCaseInTempDir):
25
9
def test_simple_revprops(self):
26
10
"""Simple revision properties"""
27
wt = self.make_branch_and_tree('.')
11
b = Branch.initialize('.')
29
12
b.nick = 'Nicholas'
30
props = dict(flavor='choc-mint',
31
condiment='orange\n mint\n\tcandy',
34
wt.commit(message='initial null commit',
13
props = dict(flavor='choc-mint',
14
condiment='orange\n mint\n\tcandy')
15
b.working_tree().commit(message='initial null commit',
36
17
allow_pointless=True,
37
18
rev_id='test@user-1')
38
rev = b.repository.get_revision('test@user-1')
19
rev = b.get_revision('test@user-1')
39
20
self.assertTrue('flavor' in rev.properties)
40
21
self.assertEquals(rev.properties['flavor'], 'choc-mint')
41
self.assertEquals([('branch-nick', 'Nicholas'),
22
self.assertEquals(sorted(rev.properties.items()),
23
[('branch-nick', 'Nicholas'),
42
24
('condiment', 'orange\n mint\n\tcandy'),
44
('flavor', 'choc-mint'),
45
('non_ascii', u'\xb5'),
46
], sorted(rev.properties.items()))
25
('flavor', 'choc-mint')])
48
27
def test_invalid_revprops(self):
49
28
"""Invalid revision properties"""
50
wt = self.make_branch_and_tree('.')
29
b = Branch.initialize('.')
52
30
self.assertRaises(ValueError,
31
b.working_tree().commit,
55
33
revprops={'what a silly property': 'fine'})
56
34
self.assertRaises(ValueError,
35
b.working_tree().commit,
59
37
revprops=dict(number=13))
62
class TestRevisionAttributes(TestCaseWithRepository):
63
"""Test that revision attributes are correct."""
65
def test_revision_accessors(self):
66
"""Make sure the values that come out of a revision are the
67
same as the ones that go in.
69
tree1 = self.make_branch_and_tree("br1")
72
tree1.commit(message="quux", allow_pointless=True, committer="jaq",
76
'multiline':'foo\nbar\n\n'
78
assert len(tree1.branch.revision_history()) > 0
79
rev_a = tree1.branch.repository.get_revision(
80
tree1.branch.last_revision())
82
tree2 = self.make_branch_and_tree("br2")
83
tree2.commit(message=rev_a.message,
84
timestamp=rev_a.timestamp,
85
timezone=rev_a.timezone,
86
committer=rev_a.committer,
87
rev_id=rev_a.revision_id,
88
revprops=rev_a.properties,
89
allow_pointless=True, # there's nothing in this commit
92
rev_b = tree2.branch.repository.get_revision(
93
tree2.branch.last_revision())
95
self.assertEqual(rev_a.message, rev_b.message)
96
self.assertEqual(rev_a.timestamp, rev_b.timestamp)
97
self.assertEqual(rev_a.timezone, rev_b.timezone)
98
self.assertEqual(rev_a.committer, rev_b.committer)
99
self.assertEqual(rev_a.revision_id, rev_b.revision_id)
100
self.assertEqual(rev_a.properties, rev_b.properties)
102
def test_zero_timezone(self):
103
tree1 = self.make_branch_and_tree("br1")
106
tree1.commit(message="quux", timezone=0, rev_id='r1')
107
rev_a = tree1.branch.repository.get_revision('r1')
108
self.assertEqual(0, rev_a.timezone)