| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import os |
| 6 |
import pytest |
| 7 |
import tempfile |
| 8 |
from scalene.scalene_profiler import Scalene |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
def test_exit_handler_cleanup(monkeypatch): |
| 13 |
|
| 14 |
temp_dir = tempfile.TemporaryDirectory() |
| 15 |
monkeypatch.setattr(Scalene, "_Scalene__python_alias_dir", temp_dir, raising=False) |
| 16 |
monkeypatch.setattr(Scalene, "_Scalene__pid", 0) |
| 17 |
|
| 18 |
|
| 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 |
|
| 24 |
assert os.path.exists(malloc_lock_file) |
| 25 |
|
| 26 |
|
| 27 |
Scalene.exit_handler() |
| 28 |
|
| 29 |
|
| 30 |
assert not os.path.exists(malloc_lock_file) |
| 31 |
|
| 32 |
|
| 33 |
temp_dir.cleanup() |