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
|
#!/usr/bin/env python
# arch-tag: eb042c78-5862-40b9-8570-bf7d62419dca
# Copyright (C) 2004 David Allouche <david@allouche.net>
# 2004 Canonical Ltd.
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Test cases for revision library handling
"""
import os
import arch
from arch.tests import framework
from arch.tests.framework import TestCase
class Empty(TestCase):
tests = []
def list_revlibs_empty(self):
"""iter_revision_libraries works when no revlib is registered"""
self.assertEqual([], list(arch.iter_revision_libraries()))
tests.append('list_revlibs_empty')
class Register(TestCase):
tests = []
def register_revision_library(self):
"""register_revision_library works"""
revlib1_dir = self.arch_dir/'revlib1'
os.mkdir(revlib1_dir)
arch.register_revision_library(revlib1_dir)
expected = [revlib1_dir]
result = list(arch.iter_revision_libraries())
self.assertEqual(expected, result)
revlib2_dir = self.arch_dir/'revlib2'
os.mkdir(revlib2_dir)
arch.register_revision_library(revlib2_dir)
expected = [revlib1_dir, revlib2_dir]
expected.sort()
result = list(arch.iter_revision_libraries())
result.sort()
self.assertEqual(expected, result)
tests.append('register_revision_library')
def register_revision_library_wants_abspath(self):
"""register_revision_library requires absolute path"""
os.chdir(self.arch_dir)
revlib_dir = 'revlib'
os.mkdir(revlib_dir)
def func(): arch.register_revision_library(revlib_dir)
self.assertRaises(ValueError, func)
tests.append('register_revision_library_wants_abspath')
class Unregister(TestCase):
tests = []
def unregister_revision_library(self):
"""unregister_revision_library works"""
revlib1_dir = self.arch_dir/'revlib1'
os.mkdir(revlib1_dir)
arch.register_revision_library(revlib1_dir)
revlib2_dir = self.arch_dir/'revlib2'
os.mkdir(revlib2_dir)
arch.register_revision_library(revlib2_dir)
arch.unregister_revision_library(revlib1_dir)
result = list(arch.iter_revision_libraries())
self.assertEqual([revlib2_dir], result)
arch.unregister_revision_library(revlib2_dir)
result = list(arch.iter_revision_libraries())
self.assertEqual([], result)
tests.append('unregister_revision_library')
def unregister_relative_revlib(self):
"""unregister_revision_library requires absolute path"""
os.chdir(self.arch_dir)
revlib_dir = self.arch_dir/'revlib'
os.mkdir(revlib_dir)
arch.register_revision_library(revlib_dir)
def func():
arch.unregister_revision_library(os.path.basename(revlib_dir))
self.assertRaises(ValueError, func)
tests.append('unregister_relative_revlib')
class List(TestCase):
tests = []
def extraSetup(self):
self.set_my_id()
self.create_archive()
revlib1_dir = self.arch_dir/'revlib1'
os.mkdir(revlib1_dir)
arch.register_revision_library(revlib1_dir)
def empty(self):
self.assertEqual([], list(arch.iter_library_archives()))
tests.append('empty')
def one(self):
self.create_version()
self.create_working_tree(self.version)
tree = self.working_tree
tree.import_()
tree.tree_revision.library_add()
archive = tree.tree_version.archive
self.assertEqual([archive], list(arch.iter_library_archives()))
category = tree.tree_version.category
self.assertEqual([category], list(archive.iter_library_categories()))
branch = tree.tree_version.branch
self.assertEqual([branch], list(category.iter_library_branches()))
version = tree.tree_version
self.assertEqual([version], list(branch.iter_library_versions()))
tests.append('one')
def test_suite(limit=()):
classes = (
'Empty',
'Register',
'Unregister',
'List',
)
return framework.make_test_suite(globals(), classes, limit)
def main(argv):
return framework.run_test_suite(argv, test_suite)
if __name__ == "__main__":
sys.exit(main(sys.argv))
|