1
# arch-tag: da321d26-9379-469d-b966-1cca8e5822ae
2
# Copyright (C) 2004 David Allouche <david@allouche.net>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
from arch.util import DirName
29
class Sandbox(object):
32
self._observers = list()
35
def subscribe(self, observer):
36
if observer in self._observers: return
37
self._observers.append(observer)
41
self.home_dir = os.environ.get('HOME')
42
self.tmp_dir = DirName(tempfile.mkdtemp(prefix='pyarch-')).realpath()
43
self.saved_editor = None
44
self.here = os.getcwd()
45
os.environ['HOME'] = self.tmp_dir
46
if os.environ.has_key('EDITOR'):
47
self.saved_editor = os.environ['EDITOR']
48
del(os.environ['EDITOR'])
49
for obs in self._observers:
50
obs.notify_setup(self)
53
if not self._set_up: return
54
os.environ['HOME'] = self.home_dir
55
shutil.rmtree(self.tmp_dir, ignore_errors=True)
56
if self.saved_editor is not None:
57
os.environ['EDITOR'] = self.saved_editor
61
class TestParams(object):
63
def __init__(self, sandbox=None):
64
if sandbox: sandbox.subscribe(self)
65
self.my_id = "John Doe <jdoe@example.com>"
66
self.arch_name = 'jdoe@example.com--example--9999'
67
self.arch_dir_base = DirName(r'pyarch\(sp)tests')
69
def notify_setup(self, sandbox):
70
self.arch_dir = sandbox.tmp_dir / self.arch_dir_base
71
os.mkdir(self.arch_dir)
72
self.working_dir = DirName(self.arch_dir/'workingtree')
73
self.nested_dir = DirName(self.working_dir/'nestedtree')
74
self.working_dir_newline = DirName(self.arch_dir/'working\ntree')
75
self.other_working_dir = DirName(self.arch_dir/'othertree')
79
arch.set_my_id(self.my_id)
81
def create_archive(self):
84
self.archive = arch.make_archive(name, self.arch_dir/name)
86
def _get_version(self):
88
return arch.Version(self.arch_name+'/cat--brn--1.0')
89
version = property(_get_version)
91
def _get_other_version(self):
93
return arch.Version(self.arch_name+'/cat--other--0')
94
other_version = property(_get_other_version)
96
def create_archive_and_mirror(self):
99
mirror_name = master.name + '-MIRROR'
100
location = self.arch_dir/mirror_name
101
self.mirror = master.make_mirror(mirror_name, location)
103
def _create_tree_helper(self, dirname, version):
107
return arch.init_tree(self.working_dir)
109
return arch.init_tree(self.working_dir, version)
111
def create_working_tree(self, version=None):
112
self.working_tree = self._create_tree_helper(self.working_dir, version)
114
def create_other_tree(self, version=None):
116
self._create_tree_helper(self.other_working_dir, version))
118
def create_branch(self):
119
self.version.branch.setup()
120
assert self.version.branch.exists()
122
def create_version(self):
125
def create_other_version(self):
126
self.other_version.setup()
128
def commit_summary(self, tree, summary):
129
m = tree.log_message()
130
m['Summary'] = m.description = summary
133
def make_history(self, tree, history):
134
for index, changes in enumerate(history):
135
for name, content in changes.items():
136
if name.startswith('%'): continue
137
open(tree/name, 'w').write(content)
138
for name in changes.get('%add', ()):
140
for old, new in changes.get('%mv', ()):
141
tree.move_file(old, new)
142
tree.move_tag(old, new)
146
self.commit_summary(tree, 'revision %d' % index)
149
class TestCase(unittest.TestCase):
154
def __getattribute__(self, name):
156
return unittest.TestCase.__getattribute__(self, name)
157
except AttributeError, exc:
158
params = unittest.TestCase.__getattribute__(self, 'params')
160
return getattr(params, name)
161
except AttributeError:
165
self.sandbox = Sandbox()
166
self.params = TestParams(self.sandbox)
170
def extraSetup(self):
175
self.sandbox.tearDown()
178
def make_test_suite(globals_, classes, limit=()):
180
limited_classes = limit
182
limited_classes = classes
183
suite = unittest.TestSuite()
184
for cls_name in limited_classes:
185
cls = globals_[cls_name]
186
if hasattr(cls, 'tests'):
187
suite.addTests(map(cls, cls.tests))
189
suite.addTest(unittest.makeSuite(cls))
193
def run_test_suite(argv, test_suite):
194
suite = unittest.TestSuite()
196
suite.addTest(test_suite(limit))
197
runner = unittest.TextTestRunner(verbosity=2)
198
if not runner.run(suite).wasSuccessful(): return 1