/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testrevprops.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008, 2009, 2011, 2016 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
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
1
# (C) 2005 Canonical
16
2
 
17
3
"""Tests for revision properties."""
18
4
 
19
 
from breezy.tests import TestNotApplicable
20
 
from breezy.tests.per_repository import (
21
 
    TestCaseWithRepository,
22
 
    )
23
 
 
24
 
 
25
 
class TestRevProps(TestCaseWithRepository):
26
 
 
 
5
from bzrlib.branch import Branch
 
6
from bzrlib.selftest import TestCaseInTempDir
 
7
 
 
8
class TestRevProps(TestCaseInTempDir):
27
9
    def test_simple_revprops(self):
28
10
        """Simple revision properties"""
29
 
        wt = self.make_branch_and_tree('.')
30
 
        b = wt.branch
31
 
        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',
35
 
                     u'empty': '',
36
 
                     u'non_ascii': u'\xb5'}
37
 
        else:
38
 
            props = {}
39
 
        rev1 = wt.commit(message='initial null commit',
40
 
                         revprops=props,
41
 
                         allow_pointless=True)
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')
46
 
            expected_revprops = {
47
 
                u'condiment': 'orange\n  mint\n\tcandy',
48
 
                u'empty': '',
49
 
                u'flavor': 'choc-mint',
50
 
                u'non_ascii': u'\xb5',
51
 
                }
52
 
        else:
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)
 
11
        b = Branch.initialize('.')
 
12
        props = dict(flavor='choc-mint', 
 
13
                     condiment='orange\n  mint\n\tcandy')
 
14
        b.commit(message='initial null commit', 
 
15
                 revprops=props,
 
16
                 allow_pointless=True,
 
17
                 rev_id='test@user-1')
 
18
        rev = b.get_revision('test@user-1')
 
19
        self.assertTrue('flavor' in rev.properties)
 
20
        self.assertEquals(rev.properties['flavor'], 'choc-mint')
 
21
        self.assertEquals(sorted(rev.properties.items()),
 
22
                          [('condiment', 'orange\n  mint\n\tcandy'),
 
23
                           ('flavor', 'choc-mint')])
58
24
 
59
25
    def test_invalid_revprops(self):
60
26
        """Invalid revision properties"""
61
 
        wt = self.make_branch_and_tree('.')
62
 
        b = wt.branch
63
 
        if not b.repository._format.supports_custom_revision_properties:
64
 
            raise TestNotApplicable(
65
 
                'format does not support custom revision properties')
 
27
        b = Branch.initialize('.')
66
28
        self.assertRaises(ValueError,
67
 
                          wt.commit,
 
29
                          b.commit, 
68
30
                          message='invalid',
69
31
                          revprops={'what a silly property': 'fine'})
70
32
        self.assertRaises(ValueError,
71
 
                          wt.commit,
 
33
                          b.commit, 
72
34
                          message='invalid',
73
35
                          revprops=dict(number=13))
74
 
 
75
 
 
76
 
class TestRevisionAttributes(TestCaseWithRepository):
77
 
    """Test that revision attributes are correct."""
78
 
 
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.
82
 
        """
83
 
        tree1 = self.make_branch_and_tree("br1")
84
 
        if tree1.branch.repository._format.supports_custom_revision_properties:
85
 
            revprops = {u'empty': '',
86
 
                        u'value': 'one',
87
 
                        u'unicode': u'\xb5',
88
 
                        u'multiline': 'foo\nbar\n\n'
89
 
                        }
90
 
        else:
91
 
            revprops = {}
92
 
        # create a revision
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())
98
 
 
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
106
 
                             else None),
107
 
                     revprops=rev_a.properties,
108
 
                     allow_pointless=True,  # there's nothing in this commit
109
 
                     strict=True,
110
 
                     verbose=True)
111
 
        rev_b = tree2.branch.repository.get_revision(
112
 
            tree2.branch.last_revision())
113
 
 
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)
120
 
 
121
 
    def test_zero_timezone(self):
122
 
        tree1 = self.make_branch_and_tree("br1")
123
 
 
124
 
        # create a revision
125
 
        r1 = tree1.commit(message="quux", timezone=0)
126
 
        rev_a = tree1.branch.repository.get_revision(r1)
127
 
        self.assertEqual(0, rev_a.timezone)