Debian Codegraph @

tests/test_coverup_84.py

raw symbols SCIP
1 # file scalene/scalene_profiler.py:1688-1697
2 # lines [1688, 1689, 1691, 1693, 1694, 1695, 1696, 1697]
3 # branches ['1694->1695', '1694->1696']
4
5 import os
6 import pytest
7 import tempfile
8 from scalene.scalene_profiler import Scalene
9
10
11 # Test function to improve coverage for Scalene.exit_handler
12 def test_exit_handler_cleanup(monkeypatch):
13 # Setup a temporary directory and patch Scalene to use it
14 temp_dir = tempfile.TemporaryDirectory()
15 monkeypatch.setattr(Scalene, "_Scalene__python_alias_dir", temp_dir, raising=False)
16 monkeypatch.setattr(Scalene, "_Scalene__pid", 0) # Ensure the cleanup code runs
17
18 # Create a temporary file to simulate the malloc lock file
19 malloc_lock_file = f"/tmp/scalene-malloc-lock{os.getpid()}"
20 with open(malloc_lock_file, "w") as f:
21 f.write("")
22
23 # Ensure the malloc lock file exists before calling the exit handler
24 assert os.path.exists(malloc_lock_file)
25
26 # Call the exit handler
27 Scalene.exit_handler()
28
29 # Check that the malloc lock file was removed
30 assert not os.path.exists(malloc_lock_file)
31
32 # Cleanup
33 temp_dir.cleanup()