Debian Codegraph @

tests/test_coverup_56.py

raw symbols SCIP
1 # file scalene/scalene_mapfile.py:19-53
2 # lines [20, 21, 23, 24, 26, 27, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52]
3 # branches []
4
5 import os
6 import mmap
7 import pytest
8 from scalene.scalene_mapfile import ScaleneMapFile
9
10
11 @pytest.fixture
12 def cleanup_files():
13 # Setup code to create filenames
14 name = "test_mapfile"
15 signal_filename = f"/tmp/scalene-{name}-signal{os.getpid()}"
16 lock_filename = f"/tmp/scalene-{name}-lock{os.getpid()}"
17 init_filename = f"/tmp/scalene-{name}-init{os.getpid()}"
18
19 # Create files with some content for the test
20 with open(signal_filename, "wb") as f:
21 f.write(b"\0" * mmap.PAGESIZE)
22 with open(lock_filename, "wb") as f:
23 f.write(b"\0" * mmap.PAGESIZE)
24 with open(init_filename, "wb") as f:
25 f.write(b"\0" * mmap.PAGESIZE)
26
27 yield signal_filename, lock_filename, init_filename
28
29 # Cleanup code to remove files
30 if os.path.exists(signal_filename):
31 os.remove(signal_filename)
32 if os.path.exists(lock_filename):
33 os.remove(lock_filename)
34 if os.path.exists(init_filename):
35 os.remove(init_filename)
36
37
38 def test_scalene_mapfile(cleanup_files):
39 signal_filename, lock_filename, init_filename = cleanup_files
40 mapfile = ScaleneMapFile("test_mapfile")
41
42 # Assertions to ensure that the mapfile object is initialized correctly
43 assert mapfile._name == "test_mapfile"
44 assert mapfile._signal_filename == signal_filename
45 assert mapfile._lock_filename == lock_filename
46 assert mapfile._init_filename == init_filename
47 assert mapfile._signal_position == 0
48 assert isinstance(mapfile._signal_mmap, mmap.mmap)
49 assert isinstance(mapfile._lock_mmap, mmap.mmap)
50
51 # Check that the files are unlinked (do not exist)
52 assert not os.path.exists(signal_filename)
53 assert not os.path.exists(lock_filename)
54 # The init file is not unlinked by the __init__ method, so it should still exist
55 assert os.path.exists(init_filename)