/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockable_files.py

  • Committer: Robert Collins
  • Date: 2006-03-03 02:09:49 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060303020949-0ddc6f33d0a43943
Smoke test for RevisionStore factories creating revision stores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005 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, TransportLock
22
 
from bzrlib.lockdir import LockDir
 
21
from bzrlib.lockable_files import LockableFiles
23
22
from bzrlib.tests import TestCaseInTempDir
24
 
from bzrlib.tests.test_transactions import DummyWeave
25
 
from bzrlib.transactions import (PassThroughTransaction,
26
 
                                 ReadOnlyTransaction,
27
 
                                 WriteTransaction,
28
 
                                 )
 
23
from bzrlib.transactions import PassThroughTransaction, ReadOnlyTransaction
29
24
from bzrlib.transport import get_transport
30
25
 
 
26
class TestLockableFiles(TestCaseInTempDir):
31
27
 
32
 
# these tests are applied in each parameterized suite for LockableFiles
33
 
class _TestLockableFiles_mixin(object):
 
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')
34
34
 
35
35
    def test_read_write(self):
36
36
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
82
82
                      PassThroughTransaction)
83
83
        self.lockable.lock_write()
84
84
        self.assertIs(self.lockable.get_transaction().__class__,
85
 
                      WriteTransaction)
86
 
        # check that finish is called:
87
 
        vf = DummyWeave('a')
88
 
        self.lockable.get_transaction().register_dirty(vf)
 
85
                      PassThroughTransaction)
89
86
        self.lockable.unlock()
90
 
        self.assertTrue(vf.finished)
91
87
 
92
88
    def test__escape(self):
93
89
        self.assertEqual('%25', self.lockable._escape('%'))
95
91
    def test__escape_empty(self):
96
92
        self.assertEqual('', self.lockable._escape(''))
97
93
 
98
 
 
99
 
# This method of adapting tests to parameters is different to 
100
 
# the TestProviderAdapters used elsewhere, but seems simpler for this 
101
 
# case.  
102
 
class TestLockableFiles_TransportLock(TestCaseInTempDir,
103
 
                                      _TestLockableFiles_mixin):
104
 
 
105
 
    def setUp(self):
106
 
        super(TestLockableFiles_TransportLock, self).setUp()
107
 
        transport = get_transport('.')
108
 
        transport.mkdir('.bzr')
109
 
        sub_transport = transport.clone('.bzr')
110
 
        self.lockable = LockableFiles(sub_transport, 'my-lock', TransportLock)
111
 
        self.lockable.create_lock()
112
 
        
113
 
 
114
 
class TestLockableFiles_LockDir(TestCaseInTempDir,
115
 
                              _TestLockableFiles_mixin):
116
 
    """LockableFile tests run with LockDir underneath"""
117
 
 
118
 
    def setUp(self):
119
 
        super(TestLockableFiles_LockDir, self).setUp()
120
 
        self.transport = get_transport('.')
121
 
        self.lockable = LockableFiles(self.transport, 'my-lock', LockDir)
122
 
        self.lockable.create_lock()
123
 
 
124
 
    def test_lock_is_lockdir(self):
125
 
        """Created instance should use a LockDir.
126
 
        
127
 
        This primarily tests the mixin adapter works properly.
128
 
        """
129
 
        ## self.assertIsInstance(self.lockable, LockableFiles)
130
 
        ## self.assertIsInstance(self.lockable._lock_strategy,
131
 
                              ## LockDirStrategy)
132
 
 
133
 
    def test_lock_created(self):
134
 
        self.assertTrue(self.transport.has('my-lock'))
135
 
        self.lockable.lock_write()
136
 
        self.assertTrue(self.transport.has('my-lock/held/info'))
137
 
        self.lockable.unlock()
138
 
        self.assertFalse(self.transport.has('my-lock/held/info'))
139
 
        self.assertTrue(self.transport.has('my-lock'))
140
 
 
141
 
 
142
 
    # TODO: Test the lockdir inherits the right file and directory permissions
143
 
    # from the LockableFiles.