~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockable_files.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
 
19
19
from bzrlib.branch import Branch
20
20
from bzrlib.errors import BzrBadParameterNotString, NoSuchFile, ReadOnlyError
21
 
from bzrlib.lockable_files import LockableFiles
 
21
from bzrlib.lockable_files import LockableFiles, TransportLock
 
22
from bzrlib.lockdir import LockDir
22
23
from bzrlib.tests import TestCaseInTempDir
23
24
from bzrlib.transactions import PassThroughTransaction, ReadOnlyTransaction
24
25
from bzrlib.transport import get_transport
25
26
 
26
 
class TestLockableFiles(TestCaseInTempDir):
27
27
 
28
 
    def setUp(self):
29
 
        super(TestLockableFiles, self).setUp()
30
 
        transport = get_transport('.')
31
 
        transport.mkdir('.bzr')
32
 
        transport.put('.bzr/my-lock', StringIO(''))
33
 
        self.lockable = LockableFiles(transport.clone('.bzr'), 'my-lock')
 
28
# these tests are applied in each parameterized suite for LockableFiles
 
29
class _TestLockableFiles_mixin(object):
34
30
 
35
31
    def test_read_write(self):
36
32
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
91
87
    def test__escape_empty(self):
92
88
        self.assertEqual('', self.lockable._escape(''))
93
89
 
 
90
 
 
91
# This method of adapting tests to parameters is different to 
 
92
# the TestProviderAdapters used elsewhere, but seems simpler for this 
 
93
# case.  
 
94
class TestLockableFiles_TransportLock(TestCaseInTempDir,
 
95
                                      _TestLockableFiles_mixin):
 
96
 
 
97
    def setUp(self):
 
98
        super(TestLockableFiles_TransportLock, self).setUp()
 
99
        transport = get_transport('.')
 
100
        transport.mkdir('.bzr')
 
101
        sub_transport = transport.clone('.bzr')
 
102
        self.lockable = LockableFiles(sub_transport, 'my-lock', TransportLock)
 
103
        self.lockable.create_lock()
 
104
        
 
105
 
 
106
class TestLockableFiles_LockDir(TestCaseInTempDir,
 
107
                              _TestLockableFiles_mixin):
 
108
    """LockableFile tests run with LockDir underneath"""
 
109
 
 
110
    def setUp(self):
 
111
        super(TestLockableFiles_LockDir, self).setUp()
 
112
        self.transport = get_transport('.')
 
113
        self.lockable = LockableFiles(self.transport, 'my-lock', LockDir)
 
114
        self.lockable.create_lock()
 
115
 
 
116
    def test_lock_is_lockdir(self):
 
117
        """Created instance should use a LockDir.
 
118
        
 
119
        This primarily tests the mixin adapter works properly.
 
120
        """
 
121
        ## self.assertIsInstance(self.lockable, LockableFiles)
 
122
        ## self.assertIsInstance(self.lockable._lock_strategy,
 
123
                              ## LockDirStrategy)
 
124
 
 
125
    def test_lock_created(self):
 
126
        self.assertTrue(self.transport.has('my-lock'))
 
127
        self.lockable.lock_write()
 
128
        self.assertTrue(self.transport.has('my-lock/held/info'))
 
129
        self.lockable.unlock()
 
130
        self.assertFalse(self.transport.has('my-lock/held/info'))
 
131
        self.assertTrue(self.transport.has('my-lock'))
 
132
 
 
133
 
 
134
    # TODO: Test the lockdir inherits the right file and directory permissions
 
135
    # from the LockableFiles.