2
# arch-tag: eb042c78-5862-40b9-8570-bf7d62419dca
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 cases for revision library handling
25
from arch.tests import framework
26
from arch.tests.framework import TestCase
29
class Empty(TestCase):
33
def list_revlibs_empty(self):
34
"""iter_revision_libraries works when no revlib is registered"""
35
self.assertEqual([], list(arch.iter_revision_libraries()))
36
tests.append('list_revlibs_empty')
39
class Register(TestCase):
43
def register_revision_library(self):
44
"""register_revision_library works"""
45
revlib1_dir = self.arch_dir/'revlib1'
47
arch.register_revision_library(revlib1_dir)
48
expected = [revlib1_dir]
49
result = list(arch.iter_revision_libraries())
50
self.assertEqual(expected, result)
51
revlib2_dir = self.arch_dir/'revlib2'
53
arch.register_revision_library(revlib2_dir)
54
expected = [revlib1_dir, revlib2_dir]
56
result = list(arch.iter_revision_libraries())
58
self.assertEqual(expected, result)
59
tests.append('register_revision_library')
61
def register_revision_library_wants_abspath(self):
62
"""register_revision_library requires absolute path"""
63
os.chdir(self.arch_dir)
66
def func(): arch.register_revision_library(revlib_dir)
67
self.assertRaises(ValueError, func)
68
tests.append('register_revision_library_wants_abspath')
71
class Unregister(TestCase):
75
def unregister_revision_library(self):
76
"""unregister_revision_library works"""
77
revlib1_dir = self.arch_dir/'revlib1'
79
arch.register_revision_library(revlib1_dir)
80
revlib2_dir = self.arch_dir/'revlib2'
82
arch.register_revision_library(revlib2_dir)
83
arch.unregister_revision_library(revlib1_dir)
84
result = list(arch.iter_revision_libraries())
85
self.assertEqual([revlib2_dir], result)
86
arch.unregister_revision_library(revlib2_dir)
87
result = list(arch.iter_revision_libraries())
88
self.assertEqual([], result)
89
tests.append('unregister_revision_library')
91
def unregister_relative_revlib(self):
92
"""unregister_revision_library requires absolute path"""
93
os.chdir(self.arch_dir)
94
revlib_dir = self.arch_dir/'revlib'
96
arch.register_revision_library(revlib_dir)
98
arch.unregister_revision_library(os.path.basename(revlib_dir))
99
self.assertRaises(ValueError, func)
100
tests.append('unregister_relative_revlib')
103
class List(TestCase):
107
def extraSetup(self):
109
self.create_archive()
110
revlib1_dir = self.arch_dir/'revlib1'
111
os.mkdir(revlib1_dir)
112
arch.register_revision_library(revlib1_dir)
115
self.assertEqual([], list(arch.iter_library_archives()))
116
tests.append('empty')
119
self.create_version()
120
self.create_working_tree(self.version)
121
tree = self.working_tree
123
tree.tree_revision.library_add()
124
archive = tree.tree_version.archive
125
self.assertEqual([archive], list(arch.iter_library_archives()))
126
category = tree.tree_version.category
127
self.assertEqual([category], list(archive.iter_library_categories()))
128
branch = tree.tree_version.branch
129
self.assertEqual([branch], list(category.iter_library_branches()))
130
version = tree.tree_version
131
self.assertEqual([version], list(branch.iter_library_versions()))
135
def test_suite(limit=()):
142
return framework.make_test_suite(globals(), classes, limit)
145
return framework.run_test_suite(argv, test_suite)
147
if __name__ == "__main__":
148
sys.exit(main(sys.argv))