1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005, 2006 by Canonical Ltd
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
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
from bzrlib.transactions import PassThroughTransaction, ReadOnlyTransaction
24
from bzrlib.transactions import (PassThroughTransaction,
24
28
from bzrlib.transport import get_transport
26
class TestLockableFiles(TestCaseInTempDir):
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')
31
# these tests are applied in each parameterized suite for LockableFiles
32
class _TestLockableFiles_mixin(object):
35
34
def test_read_write(self):
36
35
self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
91
90
def test__escape_empty(self):
92
91
self.assertEqual('', self.lockable._escape(''))
94
# This method of adapting tests to parameters is different to
95
# the TestProviderAdapters used elsewhere, but seems simpler for this
97
class TestLockableFiles_TransportLock(TestCaseInTempDir,
98
_TestLockableFiles_mixin):
101
super(TestLockableFiles_TransportLock, self).setUp()
102
transport = get_transport('.')
103
transport.mkdir('.bzr')
104
sub_transport = transport.clone('.bzr')
105
self.lockable = LockableFiles(sub_transport, 'my-lock', TransportLock)
106
self.lockable.create_lock()
109
class TestLockableFiles_LockDir(TestCaseInTempDir,
110
_TestLockableFiles_mixin):
111
"""LockableFile tests run with LockDir underneath"""
114
super(TestLockableFiles_LockDir, self).setUp()
115
self.transport = get_transport('.')
116
self.lockable = LockableFiles(self.transport, 'my-lock', LockDir)
117
self.lockable.create_lock()
119
def test_lock_is_lockdir(self):
120
"""Created instance should use a LockDir.
122
This primarily tests the mixin adapter works properly.
124
## self.assertIsInstance(self.lockable, LockableFiles)
125
## self.assertIsInstance(self.lockable._lock_strategy,
128
def test_lock_created(self):
129
self.assertTrue(self.transport.has('my-lock'))
130
self.lockable.lock_write()
131
self.assertTrue(self.transport.has('my-lock/held/info'))
132
self.lockable.unlock()
133
self.assertFalse(self.transport.has('my-lock/held/info'))
134
self.assertTrue(self.transport.has('my-lock'))
137
# TODO: Test the lockdir inherits the right file and directory permissions
138
# from the LockableFiles.