~bzr-pqm/bzr/bzr.dev

1886.1.4 by John Arbash Meinel
Move the revprops test to test against each Repository format.
1
# Copyright (C) 2006 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.16.35 by Martin Pool
- stub for revision properties
16
17
"""Tests for revision properties."""
18
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
19
from bzrlib.tests.per_repository import (
1886.1.4 by John Arbash Meinel
Move the revprops test to test against each Repository format.
20
    TestCaseWithRepository,
21
    )
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
22
1886.1.4 by John Arbash Meinel
Move the revprops test to test against each Repository format.
23
class TestRevProps(TestCaseWithRepository):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
24
1185.16.35 by Martin Pool
- stub for revision properties
25
    def test_simple_revprops(self):
26
        """Simple revision properties"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
27
        wt = self.make_branch_and_tree('.')
28
        b = wt.branch
1185.35.16 by Aaron Bentley
Fixed tests
29
        b.nick = 'Nicholas'
1886.1.3 by John Arbash Meinel
Also update the revprops test.
30
        props = dict(flavor='choc-mint',
31
                     condiment='orange\n  mint\n\tcandy',
32
                     empty='',
33
                     non_ascii=u'\xb5')
3831.1.5 by John Arbash Meinel
It seems we have some direct tests that don't use strings and expect a value error as well.
34
        wt.commit(message='initial null commit',
1185.16.35 by Martin Pool
- stub for revision properties
35
                 revprops=props,
36
                 allow_pointless=True,
37
                 rev_id='test@user-1')
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
38
        rev = b.repository.get_revision('test@user-1')
1185.16.37 by Martin Pool
- properties are retrieved when revisions are loaded
39
        self.assertTrue('flavor' in rev.properties)
40
        self.assertEquals(rev.properties['flavor'], 'choc-mint')
3831.1.5 by John Arbash Meinel
It seems we have some direct tests that don't use strings and expect a value error as well.
41
        self.assertEquals([('branch-nick', 'Nicholas'),
1185.35.16 by Aaron Bentley
Fixed tests
42
                           ('condiment', 'orange\n  mint\n\tcandy'),
1886.1.3 by John Arbash Meinel
Also update the revprops test.
43
                           ('empty', ''),
44
                           ('flavor', 'choc-mint'),
45
                           ('non_ascii', u'\xb5'),
46
                          ], sorted(rev.properties.items()))
1185.16.37 by Martin Pool
- properties are retrieved when revisions are loaded
47
1185.16.39 by Martin Pool
- constraints on revprops
48
    def test_invalid_revprops(self):
49
        """Invalid revision properties"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
50
        wt = self.make_branch_and_tree('.')
51
        b = wt.branch
1185.16.39 by Martin Pool
- constraints on revprops
52
        self.assertRaises(ValueError,
3831.1.5 by John Arbash Meinel
It seems we have some direct tests that don't use strings and expect a value error as well.
53
                          wt.commit,
1185.16.39 by Martin Pool
- constraints on revprops
54
                          message='invalid',
55
                          revprops={'what a silly property': 'fine'})
56
        self.assertRaises(ValueError,
3831.1.5 by John Arbash Meinel
It seems we have some direct tests that don't use strings and expect a value error as well.
57
                          wt.commit,
1185.16.39 by Martin Pool
- constraints on revprops
58
                          message='invalid',
59
                          revprops=dict(number=13))
1913.1.1 by John Arbash Meinel
Fix bug #55783
60
61
62
class TestRevisionAttributes(TestCaseWithRepository):
63
    """Test that revision attributes are correct."""
64
65
    def test_revision_accessors(self):
3831.1.5 by John Arbash Meinel
It seems we have some direct tests that don't use strings and expect a value error as well.
66
        """Make sure the values that come out of a revision are the
1913.1.1 by John Arbash Meinel
Fix bug #55783
67
        same as the ones that go in.
68
        """
69
        tree1 = self.make_branch_and_tree("br1")
70
71
        # create a revision
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
72
        rev1 = tree1.commit(message="quux", allow_pointless=True,
73
            committer="jaq",
74
            revprops={'empty':'',
75
                      'value':'one',
76
                      'unicode':u'\xb5',
77
                      'multiline':'foo\nbar\n\n'
78
                      })
79
        self.assertEquals(tree1.branch.last_revision(), rev1)
1913.1.1 by John Arbash Meinel
Fix bug #55783
80
        rev_a = tree1.branch.repository.get_revision(
81
                            tree1.branch.last_revision())
82
83
        tree2 = self.make_branch_and_tree("br2")
84
        tree2.commit(message=rev_a.message,
85
                     timestamp=rev_a.timestamp,
86
                     timezone=rev_a.timezone,
87
                     committer=rev_a.committer,
88
                     rev_id=rev_a.revision_id,
89
                     revprops=rev_a.properties,
90
                     allow_pointless=True, # there's nothing in this commit
91
                     strict=True,
92
                     verbose=True)
93
        rev_b = tree2.branch.repository.get_revision(
94
                            tree2.branch.last_revision())
3831.1.5 by John Arbash Meinel
It seems we have some direct tests that don't use strings and expect a value error as well.
95
1913.1.1 by John Arbash Meinel
Fix bug #55783
96
        self.assertEqual(rev_a.message, rev_b.message)
97
        self.assertEqual(rev_a.timestamp, rev_b.timestamp)
98
        self.assertEqual(rev_a.timezone, rev_b.timezone)
99
        self.assertEqual(rev_a.committer, rev_b.committer)
100
        self.assertEqual(rev_a.revision_id, rev_b.revision_id)
101
        self.assertEqual(rev_a.properties, rev_b.properties)
102
1913.1.5 by John Arbash Meinel
fix test name
103
    def test_zero_timezone(self):
1913.1.1 by John Arbash Meinel
Fix bug #55783
104
        tree1 = self.make_branch_and_tree("br1")
105
106
        # create a revision
107
        tree1.commit(message="quux", timezone=0, rev_id='r1')
108
        rev_a = tree1.branch.repository.get_revision('r1')
109
        self.assertEqual(0, rev_a.timezone)