1
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
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.
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, see <http://www.gnu.org/licenses/>.
16
"""Subversion core library tests."""
18
from bzrlib.tests import TestCase
19
from bzrlib.plugins.svn import core, properties
21
class TestProperties(TestCase):
23
super(TestProperties, self).setUp()
25
def test_time_from_cstring(self):
26
self.assertEquals(1225704780716938L, properties.time_from_cstring("2008-11-03T09:33:00.716938Z"))
28
def test_time_to_cstring(self):
29
self.assertEquals("2008-11-03T09:33:00.716938Z", properties.time_to_cstring(1225704780716938L))
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")
37
def test_parse_scheme_relative_externals(self):
38
self.assertRaises(NotImplementedError, properties.parse_externals_description,
39
"http://example.com", "third-party/skins //foo")
41
def test_parse_externals(self):
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"""))
51
def test_parse_comment(self):
53
'third-party/sounds': (None, "http://sounds.red-bean.com/repos")
55
properties.parse_externals_description("http://example.com/",
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"""))
62
def test_parse_relative(self):
64
'third-party/sounds': (None, "http://example.com/branches/other"),
66
properties.parse_externals_description("http://example.com/trunk",
67
"third-party/sounds ../branches/other"))
69
def test_parse_repos_root_relative(self):
71
'third-party/sounds': (None, "http://example.com/bar/bla/branches/other"),
73
properties.parse_externals_description("http://example.com/trunk",
74
"third-party/sounds /bar/bla/branches/other"))
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"))
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/"))
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"))
91
def test_simple_range_uninheritable(self):
92
self.assertEquals({"/trunk": [(1,2,False)]}, properties.parse_mergeinfo_property("/trunk:1-2*\n"))
94
def test_simple_individual(self):
95
self.assertEquals({"/trunk": [(1,1,True)]}, properties.parse_mergeinfo_property("/trunk:1\n"))
98
self.assertEquals({}, properties.parse_mergeinfo_property(""))
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)]}))
105
def test_simple_individual(self):
106
self.assertEquals("/trunk:1\n", properties.generate_mergeinfo_property({"/trunk": [(1,1,True)]}))
108
def test_empty(self):
109
self.assertEquals("", properties.generate_mergeinfo_property({}))
112
class RevnumRangeTests(TestCase):
113
def test_add_revnum_empty(self):
114
self.assertEquals([(1,1,True)], properties.range_add_revnum([], 1))
116
def test_add_revnum_before(self):
117
self.assertEquals([(2,2,True), (8,8,True)], properties.range_add_revnum([(2,2,True)], 8))
119
def test_add_revnum_included(self):
120
self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,3,True)], 2))
122
def test_add_revnum_after(self):
123
self.assertEquals([(1,3,True),(5,5,True)], properties.range_add_revnum([(1,3,True)], 5))
125
def test_add_revnum_extend_before(self):
126
self.assertEquals([(1,3,True)], properties.range_add_revnum([(2,3,True)], 1))
128
def test_add_revnum_extend_after(self):
129
self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,2,True)], 3))
131
def test_revnum_includes_empty(self):
132
self.assertFalse(properties.range_includes_revnum([], 2))
134
def test_revnum_includes_oor(self):
135
self.assertFalse(properties.range_includes_revnum([(1,3,True), (4,5, True)], 10))
137
def test_revnum_includes_in(self):
138
self.assertTrue(properties.range_includes_revnum([(1,3,True), (4,5, True)], 2))
141
class MergeInfoIncludeTests(TestCase):
142
def test_includes_individual(self):
143
self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,1,True)]}, "/trunk", 1))
145
def test_includes_range(self):
146
self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 3))
148
def test_includes_invalid_path(self):
149
self.assertFalse(properties.mergeinfo_includes_revision({"/somepath": [(1,5,True)]}, "/trunk", 3))
151
def test_includes_invalid_revnum(self):
152
self.assertFalse(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 30))