Debian Codegraph @

tests/test_coverup_52.py

raw symbols SCIP
1 # file scalene/scalene_mapfile.py:55-58
2 # lines [55, 57, 58]
3 # branches []
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 # Setup: create a mock ScaleneMapFile instance
20 mapfile = MockScaleneMapFile(name=str(tmp_path))
21 signal_fd_path = tmp_path / "signal_fd"
22 lock_fd_path = tmp_path / "lock_fd"
23 # Create temporary files to act as signal_fd and lock_fd
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 # Teardown: files will be closed and removed by the fixture system
29
30
31 def test_close_scalene_mapfile(scalene_mapfile):
32 # Precondition: file descriptors should be open
33 assert not scalene_mapfile._signal_fd.closed
34 assert not scalene_mapfile._lock_fd.closed
35
36 # Action: close the map file
37 scalene_mapfile.close()
38
39 # Postcondition: file descriptors should be closed
40 assert scalene_mapfile._signal_fd.closed
41 assert scalene_mapfile._lock_fd.closed