1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""OS Lock implementation tests for bzr.
19
These test the conformance of all the lock variations to the expected API.
22
from copy import deepcopy
30
class TestCaseWithLock(tests.TestCaseWithTransport):
36
class LockTestProviderAdapter(object):
37
"""A tool to generate a suite testing multiple lock formats at once.
39
This is done by copying the test once for each lock and injecting the
40
read_lock and write_lock classes.
41
They are also given a new test id.
44
def __init__(self, lock_classes):
45
self._lock_classes = lock_classes
47
def _clone_test(self, test, write_lock, read_lock, variation):
48
"""Clone test for adaption."""
49
new_test = deepcopy(test)
50
new_test.write_lock = write_lock
51
new_test.read_lock = read_lock
52
def make_new_test_id():
53
new_id = "%s(%s)" % (test.id(), variation)
55
new_test.id = make_new_test_id()
58
def adapt(self, test):
59
result = tests.TestSuite()
60
for name, write_lock, read_lock in self._lock_classes:
61
new_test = self._clone_test(test, write_lock, read_lock, name)
62
result.addTest(new_test)
67
result = tests.TestSuite()
68
test_lock_implementations = [
69
'bzrlib.tests.per_lock.test_lock',
70
'bzrlib.tests.per_lock.test_temporary_write_lock',
72
adapter = LockTestProviderAdapter(lock._lock_classes)
73
loader = tests.TestLoader()
74
tests.adapt_modules(test_lock_implementations, adapter, loader, result)