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 Lesser General Public License as published by
5 # the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 """Subversion core library tests."""
20 from subvertpy import properties
21 from subvertpy.tests import TestCase
23 class TestProperties(TestCase):
26 super(TestProperties, self).setUp()
28 def test_time_from_cstring(self):
29 self.assertEquals(1225704780716938L, properties.time_from_cstring("2008-11-03T09:33:00.716938Z"))
31 def test_time_from_cstring_independent_from_dst(self):
32 old_tz = os.environ.get('TZ', None)
33 # On Windows, there is no tzset function, so skip this test.
34 if not hasattr(time, 'tzset'):
38 # First specify a fixed timezone with known DST (late March to late October)
39 os.environ['TZ'] = 'Europe/London'
41 # Now test a time within that DST
42 self.assertEquals(1275295762430000L, properties.time_from_cstring("2010-05-31T08:49:22.430000Z"))
47 os.environ['TZ'] = old_tz
50 def test_time_to_cstring(self):
51 self.assertEquals("2008-11-03T09:33:00.716938Z", properties.time_to_cstring(1225704780716938L))
54 class TestExternalsParser(TestCase):
55 def test_parse_root_relative_externals(self):
56 self.assertRaises(NotImplementedError, properties.parse_externals_description,
57 "http://example.com", "third-party/skins ^/foo")
59 def test_parse_scheme_relative_externals(self):
60 self.assertRaises(NotImplementedError, properties.parse_externals_description,
61 "http://example.com", "third-party/skins //foo")
63 def test_parse_externals(self):
65 'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
66 'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
67 'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
68 properties.parse_externals_description("http://example.com",
69 """third-party/sounds http://sounds.red-bean.com/repos
70 third-party/skins http://skins.red-bean.com/repositories/skinproj
71 third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
73 def test_parse_externals_space_revno(self):
75 'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
76 properties.parse_externals_description("http://example.com",
77 """third-party/skins/toolkit -r 21 http://svn.red-bean.com/repos/skin-maker"""))
79 def test_parse_externals_swapped(self):
80 self.assertEqual({'third-party/sounds': (None, "http://sounds.red-bean.com/repos")},
81 properties.parse_externals_description("http://example.com",
82 """http://sounds.red-bean.com/repos third-party/sounds
85 def test_parse_comment(self):
87 'third-party/sounds': (None, "http://sounds.red-bean.com/repos")
89 properties.parse_externals_description("http://example.com/",
92 third-party/sounds http://sounds.red-bean.com/repos
93 #third-party/skins http://skins.red-bean.com/repositories/skinproj
94 #third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
96 def test_parse_relative(self):
98 'third-party/sounds': (None, "http://example.com/branches/other"),
100 properties.parse_externals_description("http://example.com/trunk",
101 "third-party/sounds ../branches/other"))
103 def test_parse_repos_root_relative(self):
105 'third-party/sounds': (None, "http://example.com/bar/bla/branches/other"),
107 properties.parse_externals_description("http://example.com/trunk",
108 "third-party/sounds /bar/bla/branches/other"))
110 def test_parse_invalid_missing_url(self):
111 """No URL specified."""
112 self.assertRaises(properties.InvalidExternalsDescription,
113 lambda: properties.parse_externals_description("http://example.com/", "bla"))
115 def test_parse_invalid_too_much_data(self):
116 """No URL specified."""
117 self.assertRaises(properties.InvalidExternalsDescription,
118 lambda: properties.parse_externals_description(None, "bla -R40 http://bla/"))
121 class MergeInfoPropertyParserTests(TestCase):
122 def test_simple_range(self):
123 self.assertEquals({"/trunk": [(1, 2, True)]}, properties.parse_mergeinfo_property("/trunk:1-2\n"))
125 def test_simple_range_uninheritable(self):
126 self.assertEquals({"/trunk": [(1, 2, False)]}, properties.parse_mergeinfo_property("/trunk:1-2*\n"))
128 def test_simple_individual(self):
129 self.assertEquals({"/trunk": [(1, 1, True)]}, properties.parse_mergeinfo_property("/trunk:1\n"))
131 def test_empty(self):
132 self.assertEquals({}, properties.parse_mergeinfo_property(""))
135 class MergeInfoPropertyCreatorTests(TestCase):
136 def test_simple_range(self):
137 self.assertEquals("/trunk:1-2\n", properties.generate_mergeinfo_property({"/trunk": [(1, 2, True)]}))
139 def test_simple_individual(self):
140 self.assertEquals("/trunk:1\n", properties.generate_mergeinfo_property({"/trunk": [(1, 1, True)]}))
142 def test_empty(self):
143 self.assertEquals("", properties.generate_mergeinfo_property({}))
146 class RevnumRangeTests(TestCase):
147 def test_add_revnum_empty(self):
148 self.assertEquals([(1, 1, True)], properties.range_add_revnum([], 1))
150 def test_add_revnum_before(self):
151 self.assertEquals([(2, 2, True), (8, 8, True)], properties.range_add_revnum([(2, 2, True)], 8))
153 def test_add_revnum_included(self):
154 self.assertEquals([(1, 3, True)], properties.range_add_revnum([(1, 3, True)], 2))
156 def test_add_revnum_after(self):
157 self.assertEquals([(1, 3, True), (5, 5, True)], properties.range_add_revnum([(1, 3, True)], 5))
159 def test_add_revnum_extend_before(self):
160 self.assertEquals([(1, 3, True)], properties.range_add_revnum([(2, 3, True)], 1))
162 def test_add_revnum_extend_after(self):
163 self.assertEquals([(1, 3, True)], properties.range_add_revnum([(1, 2, True)], 3))
165 def test_revnum_includes_empty(self):
166 self.assertFalse(properties.range_includes_revnum([], 2))
168 def test_revnum_includes_oor(self):
169 self.assertFalse(properties.range_includes_revnum([(1, 3, True), (4, 5, True)], 10))
171 def test_revnum_includes_in(self):
172 self.assertTrue(properties.range_includes_revnum([(1, 3, True), (4, 5, True)], 2))
175 class MergeInfoIncludeTests(TestCase):
176 def test_includes_individual(self):
177 self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1, 1, True)]}, "/trunk", 1))
179 def test_includes_range(self):
180 self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1, 5, True)]}, "/trunk", 3))
182 def test_includes_invalid_path(self):
183 self.assertFalse(properties.mergeinfo_includes_revision({"/somepath": [(1, 5, True)]}, "/trunk", 3))
185 def test_includes_invalid_revnum(self):
186 self.assertFalse(properties.mergeinfo_includes_revision({"/trunk": [(1, 5, True)]}, "/trunk", 30))