320
Testing locking behaviour
321
-------------------------
323
In order to test the locking behaviour of commands, it is possible to install
324
a hook that is called when a write lock is: acquired, released or broken.
325
(Read locks also exist, they cannot be discovered in this way.)
327
A hook can be installed by calling bzrlib.lock.Lock.hooks.install_named_hook.
328
The three valid hooks are: `lock_acquired`, `lock_released` and `lock_broken`.
335
lock.Lock.hooks.install_named_hook('lock_acquired',
336
locks_acquired.append, None)
337
lock.Lock.hooks.install_named_hook('lock_released',
338
locks_released.append, None)
340
`locks_acquired` will now receive a LockResult instance for all locks acquired
341
since the time the hook is installed.
343
The last part of the `lock_url` allows you to identify the type of object that is locked.
345
- BzrDir: `/branch-lock`
346
- Working tree: `/checkout/lock`
347
- Branch: `/branch/lock`
348
- Repository: `/repository/lock`
350
To test if a lock is a write lock on a working tree, one can do the following::
352
self.assertEndsWith(locks_acquired[0].lock_url, "/checkout/lock")
354
See bzrlib/tests/commands/test_revert.py for an example of how to use this for
438
475
self.requireFeature(StraceFeature)
440
Features already defined in bzrlib.tests include:
480
Features already defined in bzrlib.tests or bzrlib.tests.features include:
442
482
- SymlinkFeature,
443
483
- HardlinkFeature,
445
485
- UnicodeFilenameFeature,
446
- FTPServerFeature, and
447
- CaseInsensitiveFilesystemFeature.
487
- CaseInsensitiveFilesystemFeature
488
- posix_permissions_feature: the test can rely on unix-style
489
permissions bits on files;
490
generally true on Unix but not on all filesystems
450
493
Defining a new feature that tests can require