Debian Codegraph @

tests/test_coverup_118.py

raw symbols SCIP
1 # file scalene/scalene_profiler.py:1156-1181
2 # lines [1161, 1162, 1164, 1165, 1166, 1167, 1170, 1171, 1172, 1173, 1174, 1175, 1177, 1178, 1180, 1181]
3 # branches ['1166->1167', '1166->1174', '1170->1166', '1170->1171', '1174->1175', '1174->1177']
4
5 import pytest
6 from scalene.scalene_profiler import Scalene
7 from scalene.scalene_statistics import ScaleneStatistics
8 from scalene.scalene_utility import enter_function_meta
9 from unittest.mock import MagicMock
10
11
12 # Mock classes to simulate the behavior of Scalene's Filename and LineNumber
13 class Filename(str):
14 pass
15
16
17 class LineNumber(int):
18 pass
19
20
21 def get_fully_qualified_name(frame: MagicMock) -> str:
22 return frame.f_globals.get("__name__", "") + "." + frame.f_code.co_name
23
24
25 # Mock function to simulate Scalene's should_trace method
26 def mock_should_trace(filename: str, func_name: str) -> bool:
27 return True
28
29
30 # Replace the actual should_trace with the mock version
31 Scalene.should_trace = staticmethod(mock_should_trace)
32
33
34 def test_enter_function_meta():
35 stats = ScaleneStatistics()
36 frame = MagicMock() # Create a MagicMock frame to simulate the behavior
37 frame.f_code.co_filename = "mock_filename.py"
38 frame.f_code.co_name = "<mock_function>"
39 frame.f_back = None # Set f_back to None to trigger the return in line 1171
40
41 # Call the method with the mock frame
42 enter_function_meta(frame, Scalene.should_trace, stats)
43
44 # Since the frame's f_back is None, the function_map and firstline_map should remain empty
45 assert not stats.function_map
46 assert not stats.firstline_map
47
48
49 # Run the test
50 pytest.main(["-v", __file__])