~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockable_files.py

  • Committer: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

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
 
from bzrlib.transactions import PassThroughTransaction, ReadOnlyTransaction
 
24
from bzrlib.transactions import (PassThroughTransaction,
 
25
                                 ReadOnlyTransaction,
 
26
                                 WriteTransaction,
 
27
                                 )
24
28
from bzrlib.transport import get_transport
25
29
 
26
 
class TestLockableFiles(TestCaseInTempDir):
27
30
 
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')
 
31
# these tests are applied in each parameterized suite for LockableFiles
 
32
class _TestLockableFiles_mixin(object):
34
33
 
35
34
    def test_read_write(self):
36
35
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
82
81
                      PassThroughTransaction)
83
82
        self.lockable.lock_write()
84
83
        self.assertIs(self.lockable.get_transaction().__class__,
85
 
                      PassThroughTransaction)
 
84
                      WriteTransaction)
86
85
        self.lockable.unlock()
87
86
 
88
87
    def test__escape(self):
91
90
    def test__escape_empty(self):
92
91
        self.assertEqual('', self.lockable._escape(''))
93
92
 
 
93
 
 
94
# This method of adapting tests to parameters is different to 
 
95
# the TestProviderAdapters used elsewhere, but seems simpler for this 
 
96
# case.  
 
97
class TestLockableFiles_TransportLock(TestCaseInTempDir,
 
98
                                      _TestLockableFiles_mixin):
 
99
 
 
100
    def setUp(self):
 
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()
 
107
        
 
108
 
 
109
class TestLockableFiles_LockDir(TestCaseInTempDir,
 
110
                              _TestLockableFiles_mixin):
 
111
    """LockableFile tests run with LockDir underneath"""
 
112
 
 
113
    def setUp(self):
 
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()
 
118
 
 
119
    def test_lock_is_lockdir(self):
 
120
        """Created instance should use a LockDir.
 
121
        
 
122
        This primarily tests the mixin adapter works properly.
 
123
        """
 
124
        ## self.assertIsInstance(self.lockable, LockableFiles)
 
125
        ## self.assertIsInstance(self.lockable._lock_strategy,
 
126
                              ## LockDirStrategy)
 
127
 
 
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'))
 
135
 
 
136
 
 
137
    # TODO: Test the lockdir inherits the right file and directory permissions
 
138
    # from the LockableFiles.