2
# arch-tag: fb639c6b-566d-4b7c-be27-cfc406fc2fb8
3
# Copyright (C) 2004 David Allouche <david@allouche.net>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
"""Test access to containers and name part properties of namespace classes.
25
from arch.tests import framework
26
from arch.tests.framework import TestCase, TestParams
29
class ArchNameProperties(TestCase):
31
"""Test cases access to container and name part properties
33
Check the availability and correctness of the "archive",
34
"category", "branch", "version", "nonarch", and "patchlevel" of
39
self.params = TestParams()
41
for k, v in kw.items():
44
setattr(self, k+'_full', '%s/%s' % (self.arch_name, v))
46
set(branch='%(category)s--devo')
47
set(version='%(branch)s--1.0')
48
self.patchlevel = 'patch-1'
49
set(revision='%(version)s--%(patchlevel)s')
50
set(nameless_branch='%(category)s')
51
set(nameless_version='%(category)s--1.0')
52
set(nameless_revision='%(nameless_version)s--%(patchlevel)s')
56
def readonly(self, obj, *attrs):
58
def try_set(): setattr(obj, attr, 'error')
59
self.assertRaises(AttributeError, try_set)
61
def check_hasnot(self, obj, *attrs):
63
self.assert_(not hasattr(obj, attr))
65
def assertInstance(self, obj, cls):
66
self.assert_(isinstance(obj, cls))
68
def check_names(self, obj, namekind):
69
self.readonly(obj, 'nonarch', 'fullname')
70
self.assertEqual(obj.nonarch, getattr(self, namekind))
71
self.assertEqual(str(obj), obj.fullname)
72
self.assertEqual(obj.fullname, getattr(self, namekind+'_full'))
74
enclosing = {'category': 'archive', 'branch': 'category',
75
'version': 'branch', 'revision': 'version'}
77
def check_init(self, cls, kind, nameless=''):
78
def check_names(obj): self.check_names(obj, nameless+kind)
79
obj = cls(getattr(self, nameless+kind+'_full'))
81
def unsafe_ctor(*args): return cls(arch._builtin._unsafe(args))
82
if kind != 'revision':
83
obj = unsafe_ctor(self.arch_name, getattr(self, nameless+kind))
85
obj = unsafe_ctor(self.arch_name,
86
getattr(self, nameless+self.enclosing[kind]),
93
def check_badinit(self, cls, *names):
95
func = lambda: cls(getattr(self, name))
96
self.assertRaises(arch.errors.NamespaceError, func)
98
def check_container_helper(self, obj, prop, strval):
99
self.readonly(obj, prop)
100
val = getattr(obj, prop)
101
typ = getattr(arch, prop.capitalize())
102
self.assertInstance(val, typ)
103
self.assertEqual(str(val), strval)
105
def check_containers(self, obj, kind, nameless=''):
106
if kind == 'archive':
107
self.check_container_helper(obj, 'archive', self.arch_name)
109
self.check_containers(obj, self.enclosing[kind], nameless)
110
if kind == 'category': namekind=kind
111
else: namekind = nameless+kind
112
self.check_container_helper(obj, kind, getattr(self, namekind+'_full'))
114
def test_category(self):
115
"""Category has correct constructor and properties."""
116
cat = self.check_init(arch.Category, 'category')
117
self.check_containers(cat, 'archive')
118
self.check_badinit(arch.Category, 'arch_name', 'branch_full')
119
self.check_hasnot(cat, 'category', 'branch', 'version', 'patchlevel')
121
tests.append('test_category')
123
def test_branch(self, nameless=False):
124
"""Branch has correct constructor and properties."""
125
nameless = nameless and 'nameless_' or ''
126
brn = self.check_init(arch.Branch, 'branch', nameless)
127
self.check_containers(brn, 'category')
128
self.check_badinit(arch.Branch, 'arch_name',
129
nameless+'version_full')
130
self.check_hasnot(brn, 'branch', 'version', 'patchlevel')
132
tests.append('test_branch')
134
def test_version(self, nameless=False):
135
"""Version has correct constructor and properties."""
136
nameless = nameless and 'nameless_' or ''
137
vsn = self.check_init(arch.Version, 'version', nameless)
138
self.check_containers(vsn, 'branch', nameless)
139
self.check_badinit(arch.Version, nameless+'branch_full',
140
nameless+'revision_full')
141
self.check_hasnot(vsn, 'version', 'patchlevel')
143
tests.append('test_version')
145
def test_revision(self, nameless=False):
146
"""Revision has correct constructor and properties."""
147
nameless = nameless and 'nameless_' or ''
148
rvsn = self.check_init(arch.Revision, 'revision', nameless)
149
self.check_containers(rvsn, 'version', nameless)
150
self.check_badinit(arch.Revision, nameless+'version_full')
151
self.readonly(rvsn, 'patchlevel')
152
self.assertEqual(rvsn.patchlevel, self.patchlevel)
154
tests.append('test_revision')
156
def test_nameless_branch(self):
157
"""Branch (nameless branch) has correct ctor and properties."""
158
self.test_branch(nameless=True)
159
tests.append('test_nameless_branch')
161
def test_nameless_version(self):
162
"""Version (nameless branch) has correct ctor and properties."""
163
self.test_version(nameless=True)
164
tests.append('test_nameless_version')
166
def test_nameless_revision(self):
167
"""Revision (nameless branch) has correct ctor and properties."""
168
self.test_revision(nameless=True)
169
tests.append('test_nameless_revision')
172
def test_suite(limit=()):
174
'ArchNameProperties',
176
return framework.make_test_suite(globals(), classes, limit)
179
return framework.run_test_suite(argv, test_suite)
181
if __name__ == "__main__":
182
sys.exit(main(sys.argv))