30
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)
66
def load_tests(basic_tests, module, loader):
67
result = loader.suiteClass()
68
# add the tests for this module
69
result.addTests(basic_tests)
71
test_lock_implementations = [
34
def make_scenarios(lock_classes):
36
for name, write_lock, read_lock in lock_classes:
38
(name, {'write_lock': write_lock, 'read_lock': read_lock}))
43
def load_tests(standard_tests, module, loader):
44
submod_tests = loader.loadTestsFromModuleNames([
72
45
'bzrlib.tests.per_lock.test_lock',
73
46
'bzrlib.tests.per_lock.test_temporary_write_lock',
75
adapter = LockTestProviderAdapter(lock._lock_classes)
48
scenarios = make_scenarios(lock._lock_classes)
76
49
# add the tests for the sub modules
77
tests.adapt_modules(test_lock_implementations, adapter, loader, result)
50
return tests.multiply_tests(submod_tests, scenarios,