Пример #1
0
def test_lockmanager_release(nlocks, tmpdir):
    lockman = LockManager()
    dir_template = 'dir{}'

    lock_list = []

    for n in range(nlocks):
        try:
            path = tmpdir.mkdir(dir_template.format(n))
            lockman.lock(str(path))
        except OSError:
            raise
        else:
            lock_list.append(join(str(path), lockman.filename))

    while len(lock_list) is not 0:
        lockfile = lock_list.pop()
        assert lockfile in lockman.locks
        try:
            lockman.release(lockfile)
        except OSError:
            raise
        else:
            assert lockfile not in lockman.locks

    assert len(lockman.locks) is 0
Пример #2
0
def test_lockmanager_release_suppress_filenotfounderror(tmpdir):
    lockman = LockManager()

    try:
        lockman.lock(str(tmpdir))
    except OSError:
        raise
    else:
        lockfile = tmpdir.join(lockman.filename)

    try:
        lockfile.remove()
    except OSError:
        raise

    try:
        lockman.release(str(lockfile))
    except FileNotFoundError:
        pytest.fail('LockManager.release raised a FileNotFoundError.')
    except OSError:
        raise
    else:
        assert len(lockman.locks) is 0