Debian Codegraph @

tests/test_coverup_24.py

raw symbols SCIP
1 # file scalene/scalene_profiler.py:879-893
2 # lines [879, 880, 883, 884, 885, 886, 888, 889, 890, 891, 893]
3 # branches ['883->884', '883->885', '885->886', '885->888']
4
5 import pytest
6 from scalene.scalene_profiler import Scalene
7 from scalene.scalene_arguments import ScaleneArguments
8
9 # Mock filename and line number
10 mock_filename = "mock_file.py"
11 mock_lineno = 10
12
13
14 # Create a test function to execute the missing lines/branches
15 def test_profile_this_code(monkeypatch):
16 # Set up the test environment
17 monkeypatch.setattr(Scalene, "_Scalene__files_to_profile", set())
18 Scalene._Scalene__files_to_profile.add(mock_filename)
19
20 # Mock the get_line_info method
21 def mock_get_line_info(filename):
22 if filename == mock_filename:
23 return [((mock_lineno, mock_lineno + 1), mock_lineno)]
24 return []
25
26 monkeypatch.setattr(Scalene, "get_line_info", mock_get_line_info)
27
28 # Test when the file is in the set and the line number is within the range
29 assert Scalene.profile_this_code(mock_filename, mock_lineno) == True
30
31 # Test when the file is in the set but the line number is not within the range
32 assert Scalene.profile_this_code(mock_filename, mock_lineno + 100) == False
33
34 # Test when the file is not in the set
35 assert Scalene.profile_this_code("other_file.py", mock_lineno) == False
36
37 # No need to clean up after the test since we used monkeypatch
38
39
40 # Run the test
41 def test_scalene_profiler(monkeypatch):
42 test_profile_this_code(monkeypatch)