~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lock.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-10 17:50:54 UTC
  • mto: (4523.4.6 1.18-lock-warnings)
  • mto: This revision was merged to the branch mainline in revision 4611.
  • Revision ID: john@arbash-meinel.com-20090710175054-u0mp3mc7pbjd8xgl
Start adding some direct testing for read and write locks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Tests for OS Locks."""
 
18
 
 
19
 
 
20
 
 
21
from bzrlib import (
 
22
    lock,
 
23
    errors,
 
24
    tests,
 
25
    )
 
26
 
 
27
 
 
28
def load_tests(standard_tests, module, loader):
 
29
    """Parameterize tests for all versions of groupcompress."""
 
30
    scenarios = []
 
31
    for name, write_lock, read_lock in lock._lock_classes:
 
32
        scenarios.append((name, {'write_lock': write_lock,
 
33
                                 'read_lock': read_lock}))
 
34
    suite = loader.suiteClass()
 
35
    result = tests.multiply_tests(standard_tests, scenarios, suite)
 
36
    return result
 
37
 
 
38
 
 
39
class TestOSLock(tests.TestCaseInTempDir):
 
40
 
 
41
    # Set by load_tests
 
42
    read_lock = None
 
43
    write_lock = None
 
44
 
 
45
    def test_create_read_lock(self):
 
46
        self.build_tree(['a-lock-file'])
 
47
        lock = self.read_lock('a-lock-file')
 
48
        lock.unlock()
 
49
 
 
50
    def test_create_write_lock(self):
 
51
        self.build_tree(['a-lock-file'])
 
52
        lock = self.write_lock('a-lock-file')
 
53
        lock.unlock()
 
54
 
 
55
    def test_write_locks_are_exclusive(self):
 
56
        self.build_tree(['a-lock-file'])
 
57
        lock = self.write_lock('a-lock-file')
 
58
        try:
 
59
            self.assertRaises(errors.LockContention,
 
60
                              self.write_lock, 'a-lock-file')
 
61
        finally:
 
62
            lock.unlock()