File: test_lock.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (26 lines) | stat: -rw-r--r-- 698 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
25
26
# fmt: off
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