~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_lock/__init__.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""OS Lock implementation tests for bzr.
18
18
 
28
28
 
29
29
 
30
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 load_tests(basic_tests, module, loader):
67
 
    result = loader.suiteClass()
68
 
    # add the tests for this module
69
 
    result.addTests(basic_tests)
70
 
 
71
 
    test_lock_implementations = [
 
31
    pass
 
32
 
 
33
 
 
34
def make_scenarios(lock_classes):
 
35
    result = []
 
36
    for name, write_lock, read_lock in lock_classes:
 
37
        result.append(
 
38
            (name, {'write_lock': write_lock, 'read_lock': read_lock}))
 
39
    return result
 
40
 
 
41
 
 
42
 
 
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',
74
 
        ]
75
 
    adapter = LockTestProviderAdapter(lock._lock_classes)
 
47
        ])
 
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)
78
 
    return result
 
50
    return tests.multiply_tests(submod_tests, scenarios,
 
51
        standard_tests)