/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 breezy/tests/test_lockable_files.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from StringIO import StringIO
18
 
 
19
 
import bzrlib
20
 
from bzrlib import (
 
17
import breezy
 
18
from .. import (
21
19
    errors,
22
20
    lockdir,
23
21
    osutils,
24
 
    )
25
 
from bzrlib.errors import BzrBadParameterNotString, NoSuchFile, ReadOnlyError
26
 
from bzrlib.lockable_files import LockableFiles, TransportLock
27
 
from bzrlib.symbol_versioning import (
28
 
    deprecated_in,
29
 
    )
30
 
from bzrlib.tests import (
 
22
    transport,
 
23
    )
 
24
from ..lockable_files import LockableFiles, TransportLock
 
25
from . import (
31
26
    TestCaseInTempDir,
32
27
    TestNotApplicable,
33
28
    )
34
 
from bzrlib.tests.test_smart import TestCaseWithSmartMedium
35
 
from bzrlib.tests.test_transactions import DummyWeave
36
 
from bzrlib.transactions import (PassThroughTransaction,
37
 
                                 ReadOnlyTransaction,
38
 
                                 WriteTransaction,
39
 
                                 )
40
 
from bzrlib.transport import get_transport
 
29
from .test_smart import TestCaseWithSmartMedium
 
30
from .test_transactions import DummyWeave
 
31
from ..transactions import (PassThroughTransaction,
 
32
                            ReadOnlyTransaction,
 
33
                            WriteTransaction,
 
34
                            )
41
35
 
42
36
 
43
37
# these tests are applied in each parameterized suite for LockableFiles
82
76
            self.lockable.unlock()
83
77
            raise TestNotApplicable("%r is not breakable" % (self.lockable,))
84
78
        l2 = self.get_lockable()
85
 
        orig_factory = bzrlib.ui.ui_factory
 
79
        orig_factory = breezy.ui.ui_factory
86
80
        # silent ui - no need for stdout
87
 
        bzrlib.ui.ui_factory = bzrlib.ui.CannedInputUIFactory([True])
 
81
        breezy.ui.ui_factory = breezy.ui.CannedInputUIFactory([True])
88
82
        try:
89
83
            l2.break_lock()
90
84
        finally:
91
 
            bzrlib.ui.ui_factory = orig_factory
 
85
            breezy.ui.ui_factory = orig_factory
92
86
        try:
93
87
            l2.lock_write()
94
88
            l2.unlock()
125
119
            # This test does not apply, because this lockable refuses
126
120
            # tokens.
127
121
            return
128
 
        different_token = token + 'xxx'
 
122
        different_token = token + b'xxx'
129
123
        # Re-using the same lockable instance with a different token will
130
124
        # raise TokenMismatch.
131
125
        self.assertRaises(errors.TokenMismatch,
278
272
                                      _TestLockableFiles_mixin):
279
273
 
280
274
    def setUp(self):
281
 
        TestCaseInTempDir.setUp(self)
282
 
        transport = get_transport('.')
283
 
        transport.mkdir('.bzr')
284
 
        self.sub_transport = transport.clone('.bzr')
 
275
        super(TestLockableFiles_TransportLock, self).setUp()
 
276
        t = transport.get_transport_from_path('.')
 
277
        t.mkdir('.bzr')
 
278
        self.sub_transport = t.clone('.bzr')
285
279
        self.lockable = self.get_lockable()
286
280
        self.lockable.create_lock()
287
281
 
299
293
 
300
294
 
301
295
class TestLockableFiles_LockDir(TestCaseInTempDir,
302
 
                              _TestLockableFiles_mixin):
 
296
                                _TestLockableFiles_mixin):
303
297
    """LockableFile tests run with LockDir underneath"""
304
298
 
305
299
    def setUp(self):
306
 
        TestCaseInTempDir.setUp(self)
307
 
        self.transport = get_transport('.')
 
300
        super(TestLockableFiles_LockDir, self).setUp()
 
301
        self.transport = transport.get_transport_from_path('.')
308
302
        self.lockable = self.get_lockable()
309
303
        # the lock creation here sets mode - test_permissions on branch
310
304
        # tests that implicitly, but it might be a good idea to factor
329
323
        lockable = LockableFiles(self.transport.clone('readonly'), 'test-lock',
330
324
                                 lockdir.LockDir)
331
325
        # The directory mode should be read-write-execute for the current user
332
 
        self.assertEqual(00700, lockable._dir_mode & 00700)
 
326
        self.assertEqual(0o0700, lockable._dir_mode & 0o0700)
333
327
        # Files should be read-write for the current user
334
 
        self.assertEqual(00600, lockable._file_mode & 00700)
 
328
        self.assertEqual(0o0600, lockable._file_mode & 0o0700)
335
329
 
336
330
 
337
331
class TestLockableFiles_RemoteLockDir(TestCaseWithSmartMedium,
338
 
                              _TestLockableFiles_mixin):
 
332
                                      _TestLockableFiles_mixin):
339
333
    """LockableFile tests run with RemoteLockDir on a branch."""
340
334
 
341
335
    def setUp(self):
342
 
        TestCaseWithSmartMedium.setUp(self)
 
336
        super(TestLockableFiles_RemoteLockDir, self).setUp()
343
337
        # can only get a RemoteLockDir with some RemoteObject...
344
338
        # use a branch as thats what we want. These mixin tests test the end
345
339
        # to end behaviour, so stubbing out the backend and simulating would
346
340
        # defeat the purpose. We test the protocol implementation separately
347
341
        # in test_remote and test_smart as usual.
348
342
        b = self.make_branch('foo')
349
 
        self.addCleanup(b.bzrdir.transport.disconnect)
350
 
        self.transport = get_transport('.')
 
343
        self.addCleanup(b.controldir.transport.disconnect)
 
344
        self.transport = transport.get_transport_from_path('.')
351
345
        self.lockable = self.get_lockable()
352
346
 
353
347
    def get_lockable(self):
354
348
        # getting a new lockable involves opening a new instance of the branch
355
 
        branch = bzrlib.branch.Branch.open(self.get_url('foo'))
356
 
        self.addCleanup(branch.bzrdir.transport.disconnect)
 
349
        branch = breezy.branch.Branch.open(self.get_url('foo'))
 
350
        self.addCleanup(branch.controldir.transport.disconnect)
357
351
        return branch.control_files