File: test_lock.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (24 lines) | stat: -rw-r--r-- 686 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pytest
from ase.utils import Lock


def test_cannot_acquire_lock_twice(tmp_path):
    """Test timeout on Lock.acquire()."""

    lock = Lock(tmp_path / 'lockfile', timeout=0.3)
    with lock:
        with pytest.raises(TimeoutError):
            with lock:
                ...


def test_lock_close_file_descriptor(tmp_path):
    """Test that lock file descriptor is properly closed."""
    # The choice of timeout=1.0 is arbitrary but we don't want to use
    # something that is too large since it could mean that the test
    # takes long to fail.
    lock = Lock(tmp_path / 'lockfile', timeout=1.0)
    with lock:
        assert not lock.fd.closed

    assert lock.fd.closed