Debian Codegraph @

tests/test_coverup_10.py

raw symbols SCIP
1 # file scalene/scalene_profiler.py:581-604
2 # lines [581, 582, 585, 586, 587, 588, 590, 591, 592, 593, 594, 595, 597, 599, 600, 601, 602, 603]
3 # branches ['585->586', '585->588', '590->597', '590->599', '599->600', '599->601']
4
5 import os
6 import signal
7 import sys
8 import pytest
9 from scalene.scalene_profiler import Scalene
10
11 # Assuming the Scalene class is defined as shown in the snippet above
12 # and that it has the necessary static methods and attributes.
13
14
15 @pytest.fixture
16 def scalene_cleanup():
17 # Fixture to clean up any state after tests
18 yield
19 # Reset signal handlers to default
20 for sig in Scalene.__signals.get_all_signals():
21 signal.signal(sig, signal.SIG_DFL)
22
23
24 @pytest.mark.skipif(
25 sys.platform != "win32", reason="Test only applicable to win32 platform"
26 )
27 def test_enable_signals_win32(scalene_cleanup):
28 # Mock the necessary static methods and attributes
29 Scalene.__signals = type(
30 "Signals",
31 (),
32 {
33 "malloc_signal": signal.SIGINT,
34 "free_signal": signal.SIGINT,
35 "memcpy_signal": signal.SIGINT,
36 "cpu_signal": signal.SIGINT,
37 "cpu_timer_signal": signal.ITIMER_REAL,
38 "get_all_signals": staticmethod(lambda: [signal.SIGINT]),
39 },
40 )
41 Scalene.__args = type("Args", (), {"cpu_sampling_rate": 0.01})
42 Scalene.__orig_signal = staticmethod(signal.signal)
43 Scalene.__orig_siginterrupt = staticmethod(signal.siginterrupt)
44 Scalene.__orig_setitimer = staticmethod(signal.setitimer)
45
46 # Mock the enable_signals_win32 method
47 Scalene.enable_signals_win32 = staticmethod(lambda: None)
48
49 # Call the method under test
50 Scalene.enable_signals()
51
52 # Assertions to verify postconditions
53 # Since enable_signals_win32 is mocked to do nothing, there's no change in state
54 # to assert. In a real test, you would replace the mock with assertions on the
55 # expected changes in signal handlers.
56 assert Scalene.enable_signals_win32.called