~jelmer/bzr-svn/svn-1.5

« back to all changes in this revision

Viewing changes to tests/test_properties.py

  • Committer: Jelmer Vernooij
  • Date: 2008-07-07 11:29:11 UTC
  • mfrom: (1196.1.245 0.4)
  • Revision ID: jelmer@samba.org-20080707112911-fca6wpxr457n690x
MergeĀ 0.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
 
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 3 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, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
"""Subversion core library tests."""
 
17
 
 
18
from bzrlib.tests import TestCase
 
19
from bzrlib.plugins.svn import core, properties
 
20
 
 
21
class TestProperties(TestCase):
 
22
    def setUp(self):
 
23
        super(TestProperties, self).setUp()
 
24
 
 
25
    def test_time_from_cstring(self):
 
26
        self.assertEquals(1225704780716938L, properties.time_from_cstring("2008-11-03T09:33:00.716938Z"))
 
27
 
 
28
    def test_time_to_cstring(self):
 
29
        self.assertEquals("2008-11-03T09:33:00.716938Z", properties.time_to_cstring(1225704780716938L))
 
30
 
 
31
 
 
32
class TestExternalsParser(TestCase):
 
33
    def test_parse_root_relative_externals(self):
 
34
        self.assertRaises(NotImplementedError, properties.parse_externals_description, 
 
35
                    "http://example.com", "third-party/skins              ^/foo")
 
36
 
 
37
    def test_parse_scheme_relative_externals(self):
 
38
        self.assertRaises(NotImplementedError, properties.parse_externals_description, 
 
39
                    "http://example.com", "third-party/skins              //foo")
 
40
 
 
41
    def test_parse_externals(self):
 
42
        self.assertEqual({
 
43
            'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
 
44
            'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
 
45
            'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
 
46
            properties.parse_externals_description("http://example.com",
 
47
"""third-party/sounds             http://sounds.red-bean.com/repos
 
48
third-party/skins              http://skins.red-bean.com/repositories/skinproj
 
49
third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
 
50
 
 
51
    def test_parse_comment(self):
 
52
        self.assertEqual({
 
53
            'third-party/sounds': (None, "http://sounds.red-bean.com/repos")
 
54
                },
 
55
            properties.parse_externals_description("http://example.com/",
 
56
"""
 
57
 
 
58
third-party/sounds             http://sounds.red-bean.com/repos
 
59
#third-party/skins              http://skins.red-bean.com/repositories/skinproj
 
60
#third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
 
61
 
 
62
    def test_parse_relative(self):
 
63
        self.assertEqual({
 
64
            'third-party/sounds': (None, "http://example.com/branches/other"),
 
65
                },
 
66
            properties.parse_externals_description("http://example.com/trunk",
 
67
"third-party/sounds             ../branches/other"))
 
68
 
 
69
    def test_parse_repos_root_relative(self):
 
70
        self.assertEqual({
 
71
            'third-party/sounds': (None, "http://example.com/bar/bla/branches/other"),
 
72
                },
 
73
            properties.parse_externals_description("http://example.com/trunk",
 
74
"third-party/sounds             /bar/bla/branches/other"))
 
75
 
 
76
    def test_parse_invalid_missing_url(self):
 
77
        """No URL specified."""
 
78
        self.assertRaises(properties.InvalidExternalsDescription, 
 
79
            lambda: properties.parse_externals_description("http://example.com/", "bla"))
 
80
            
 
81
    def test_parse_invalid_too_much_data(self):
 
82
        """No URL specified."""
 
83
        self.assertRaises(properties.InvalidExternalsDescription, 
 
84
            lambda: properties.parse_externals_description(None, "bla -R40 http://bla/"))
 
85
 
 
86
 
 
87
class MergeInfoPropertyParserTests(TestCase):
 
88
    def test_simple_range(self):
 
89
        self.assertEquals({"/trunk": [(1,2,True)]}, properties.parse_mergeinfo_property("/trunk:1-2\n"))
 
90
 
 
91
    def test_simple_range_uninheritable(self):
 
92
        self.assertEquals({"/trunk": [(1,2,False)]}, properties.parse_mergeinfo_property("/trunk:1-2*\n"))
 
93
 
 
94
    def test_simple_individual(self):
 
95
        self.assertEquals({"/trunk": [(1,1,True)]}, properties.parse_mergeinfo_property("/trunk:1\n"))
 
96
 
 
97
    def test_empty(self):
 
98
        self.assertEquals({}, properties.parse_mergeinfo_property(""))
 
99
       
 
100
 
 
101
class MergeInfoPropertyCreatorTests(TestCase):
 
102
    def test_simple_range(self):
 
103
        self.assertEquals("/trunk:1-2\n", properties.generate_mergeinfo_property({"/trunk": [(1,2,True)]}))
 
104
 
 
105
    def test_simple_individual(self):
 
106
        self.assertEquals("/trunk:1\n", properties.generate_mergeinfo_property({"/trunk": [(1,1,True)]}))
 
107
 
 
108
    def test_empty(self):
 
109
        self.assertEquals("", properties.generate_mergeinfo_property({}))
 
110
 
 
111
 
 
112
class RevnumRangeTests(TestCase):
 
113
    def test_add_revnum_empty(self):
 
114
        self.assertEquals([(1,1,True)], properties.range_add_revnum([], 1))
 
115
 
 
116
    def test_add_revnum_before(self):
 
117
        self.assertEquals([(2,2,True), (8,8,True)], properties.range_add_revnum([(2,2,True)], 8))
 
118
 
 
119
    def test_add_revnum_included(self):
 
120
        self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,3,True)], 2))
 
121
        
 
122
    def test_add_revnum_after(self):
 
123
        self.assertEquals([(1,3,True),(5,5,True)], properties.range_add_revnum([(1,3,True)], 5))
 
124
 
 
125
    def test_add_revnum_extend_before(self):
 
126
        self.assertEquals([(1,3,True)], properties.range_add_revnum([(2,3,True)], 1))
 
127
 
 
128
    def test_add_revnum_extend_after(self):
 
129
        self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,2,True)], 3))
 
130
 
 
131
    def test_revnum_includes_empty(self):
 
132
        self.assertFalse(properties.range_includes_revnum([], 2))
 
133
 
 
134
    def test_revnum_includes_oor(self):
 
135
        self.assertFalse(properties.range_includes_revnum([(1,3,True), (4,5, True)], 10))
 
136
 
 
137
    def test_revnum_includes_in(self):
 
138
        self.assertTrue(properties.range_includes_revnum([(1,3,True), (4,5, True)], 2))
 
139
 
 
140
 
 
141
class MergeInfoIncludeTests(TestCase):
 
142
    def test_includes_individual(self):
 
143
        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,1,True)]}, "/trunk", 1))
 
144
 
 
145
    def test_includes_range(self):
 
146
        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 3))
 
147
 
 
148
    def test_includes_invalid_path(self):
 
149
        self.assertFalse(properties.mergeinfo_includes_revision({"/somepath": [(1,5,True)]}, "/trunk", 3))
 
150
 
 
151
    def test_includes_invalid_revnum(self):
 
152
        self.assertFalse(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 30))