~jelmer/bzr-svn/svn-1.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Subversion core library tests."""

from bzrlib.tests import TestCase
from bzrlib.plugins.svn import core, properties

class TestProperties(TestCase):
    def setUp(self):
        super(TestProperties, self).setUp()

    def test_time_from_cstring(self):
        self.assertEquals(1225704780716938L, properties.time_from_cstring("2008-11-03T09:33:00.716938Z"))

    def test_time_to_cstring(self):
        self.assertEquals("2008-11-03T09:33:00.716938Z", properties.time_to_cstring(1225704780716938L))


class TestExternalsParser(TestCase):
    def test_parse_root_relative_externals(self):
        self.assertRaises(NotImplementedError, properties.parse_externals_description, 
                    "http://example.com", "third-party/skins              ^/foo")

    def test_parse_scheme_relative_externals(self):
        self.assertRaises(NotImplementedError, properties.parse_externals_description, 
                    "http://example.com", "third-party/skins              //foo")

    def test_parse_externals(self):
        self.assertEqual({
            'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
            'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
            'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
            properties.parse_externals_description("http://example.com",
"""third-party/sounds             http://sounds.red-bean.com/repos
third-party/skins              http://skins.red-bean.com/repositories/skinproj
third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))

    def test_parse_comment(self):
        self.assertEqual({
            'third-party/sounds': (None, "http://sounds.red-bean.com/repos")
                },
            properties.parse_externals_description("http://example.com/",
"""

third-party/sounds             http://sounds.red-bean.com/repos
#third-party/skins              http://skins.red-bean.com/repositories/skinproj
#third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))

    def test_parse_relative(self):
        self.assertEqual({
            'third-party/sounds': (None, "http://example.com/branches/other"),
                },
            properties.parse_externals_description("http://example.com/trunk",
"third-party/sounds             ../branches/other"))

    def test_parse_repos_root_relative(self):
        self.assertEqual({
            'third-party/sounds': (None, "http://example.com/bar/bla/branches/other"),
                },
            properties.parse_externals_description("http://example.com/trunk",
"third-party/sounds             /bar/bla/branches/other"))

    def test_parse_invalid_missing_url(self):
        """No URL specified."""
        self.assertRaises(properties.InvalidExternalsDescription, 
            lambda: properties.parse_externals_description("http://example.com/", "bla"))
            
    def test_parse_invalid_too_much_data(self):
        """No URL specified."""
        self.assertRaises(properties.InvalidExternalsDescription, 
            lambda: properties.parse_externals_description(None, "bla -R40 http://bla/"))
 

class MergeInfoPropertyParserTests(TestCase):
    def test_simple_range(self):
        self.assertEquals({"/trunk": [(1,2,True)]}, properties.parse_mergeinfo_property("/trunk:1-2\n"))

    def test_simple_range_uninheritable(self):
        self.assertEquals({"/trunk": [(1,2,False)]}, properties.parse_mergeinfo_property("/trunk:1-2*\n"))

    def test_simple_individual(self):
        self.assertEquals({"/trunk": [(1,1,True)]}, properties.parse_mergeinfo_property("/trunk:1\n"))

    def test_empty(self):
        self.assertEquals({}, properties.parse_mergeinfo_property(""))
       

class MergeInfoPropertyCreatorTests(TestCase):
    def test_simple_range(self):
        self.assertEquals("/trunk:1-2\n", properties.generate_mergeinfo_property({"/trunk": [(1,2,True)]}))

    def test_simple_individual(self):
        self.assertEquals("/trunk:1\n", properties.generate_mergeinfo_property({"/trunk": [(1,1,True)]}))

    def test_empty(self):
        self.assertEquals("", properties.generate_mergeinfo_property({}))


class RevnumRangeTests(TestCase):
    def test_add_revnum_empty(self):
        self.assertEquals([(1,1,True)], properties.range_add_revnum([], 1))

    def test_add_revnum_before(self):
        self.assertEquals([(2,2,True), (8,8,True)], properties.range_add_revnum([(2,2,True)], 8))

    def test_add_revnum_included(self):
        self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,3,True)], 2))
        
    def test_add_revnum_after(self):
        self.assertEquals([(1,3,True),(5,5,True)], properties.range_add_revnum([(1,3,True)], 5))

    def test_add_revnum_extend_before(self):
        self.assertEquals([(1,3,True)], properties.range_add_revnum([(2,3,True)], 1))

    def test_add_revnum_extend_after(self):
        self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,2,True)], 3))

    def test_revnum_includes_empty(self):
        self.assertFalse(properties.range_includes_revnum([], 2))

    def test_revnum_includes_oor(self):
        self.assertFalse(properties.range_includes_revnum([(1,3,True), (4,5, True)], 10))

    def test_revnum_includes_in(self):
        self.assertTrue(properties.range_includes_revnum([(1,3,True), (4,5, True)], 2))


class MergeInfoIncludeTests(TestCase):
    def test_includes_individual(self):
        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,1,True)]}, "/trunk", 1))

    def test_includes_range(self):
        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 3))

    def test_includes_invalid_path(self):
        self.assertFalse(properties.mergeinfo_includes_revision({"/somepath": [(1,5,True)]}, "/trunk", 3))

    def test_includes_invalid_revnum(self):
        self.assertFalse(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 30))