2353.3.9
by John Arbash Meinel
Update the lock code and test code so that if more than one |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
"""OS Lock implementation tests for bzr.
|
|
18 |
||
19 |
These test the conformance of all the lock variations to the expected API.
|
|
20 |
"""
|
|
21 |
||
22 |
from copy import deepcopy |
|
23 |
||
24 |
from bzrlib import ( |
|
25 |
lock, |
|
26 |
tests, |
|
27 |
)
|
|
28 |
||
29 |
||
30 |
class TestCaseWithLock(tests.TestCaseWithTransport): |
|
31 |
||
32 |
write_lock = None |
|
33 |
read_lock = None |
|
34 |
||
35 |
||
36 |
class LockTestProviderAdapter(object): |
|
37 |
"""A tool to generate a suite testing multiple lock formats at once.
|
|
38 |
||
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.
|
|
42 |
"""
|
|
43 |
||
44 |
def __init__(self, lock_classes): |
|
45 |
self._lock_classes = lock_classes |
|
46 |
||
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) |
|
54 |
return lambda: new_id |
|
55 |
new_test.id = make_new_test_id() |
|
56 |
return new_test |
|
57 |
||
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) |
|
63 |
return result |
|
64 |
||
65 |
||
66 |
def test_suite(): |
|
67 |
result = tests.TestSuite() |
|
68 |
test_lock_implementations = [ |
|
69 |
'bzrlib.tests.per_lock.test_lock', |
|
2353.4.3
by John Arbash Meinel
Implement a 'ReadLock.temporary_write_lock()' to upgrade to a write-lock in-process. |
70 |
'bzrlib.tests.per_lock.test_temporary_write_lock', |
2353.3.9
by John Arbash Meinel
Update the lock code and test code so that if more than one |
71 |
]
|
72 |
adapter = LockTestProviderAdapter(lock._lock_classes) |
|
73 |
loader = tests.TestLoader() |
|
74 |
tests.adapt_modules(test_lock_implementations, adapter, loader, result) |
|
75 |
return result |