| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import os |
| 6 |
import pytest |
| 7 |
from scalene.scalene_mapfile import ScaleneMapFile |
| 8 |
|
| 9 |
|
| 10 |
class MockScaleneMapFile(ScaleneMapFile): |
| 11 |
def __init__(self, name: str) -> None: |
| 12 |
self._name = name |
| 13 |
self._signal_fd = None |
| 14 |
self._lock_fd = None |
| 15 |
|
| 16 |
|
| 17 |
@pytest.fixture |
| 18 |
def scalene_mapfile(tmp_path): |
| 19 |
|
| 20 |
mapfile = MockScaleneMapFile(name=str(tmp_path)) |
| 21 |
signal_fd_path = tmp_path / "signal_fd" |
| 22 |
lock_fd_path = tmp_path / "lock_fd" |
| 23 |
|
| 24 |
with open(signal_fd_path, "wb") as signal_fd, open(lock_fd_path, "wb") as lock_fd: |
| 25 |
mapfile._signal_fd = signal_fd |
| 26 |
mapfile._lock_fd = lock_fd |
| 27 |
yield mapfile |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
def test_close_scalene_mapfile(scalene_mapfile): |
| 32 |
|
| 33 |
assert not scalene_mapfile._signal_fd.closed |
| 34 |
assert not scalene_mapfile._lock_fd.closed |
| 35 |
|
| 36 |
|
| 37 |
scalene_mapfile.close() |
| 38 |
|
| 39 |
|
| 40 |
assert scalene_mapfile._signal_fd.closed |
| 41 |
assert scalene_mapfile._lock_fd.closed |