Debian Codegraph @

tests/test_coverup_1.py

raw symbols SCIP
1 # file scalene/scalene_analysis.py:69-99
2 # lines [69, 70, 82, 83, 84, 87, 88, 90, 91, 92, 94, 95, 96, 97, 99]
3 # branches ['87->88', '87->99', '88->90', '88->94', '90->87', '90->91', '91->90', '91->92', '94->87', '94->95', '96->87', '96->97']
4
5 import pytest
6 from scalene.scalene_analysis import ScaleneAnalysis
7 from unittest.mock import patch
8
9
10 @pytest.fixture
11 def cleanup_imports():
12 # Fixture to clean up sys.modules after the test
13 import sys
14
15 before = set(sys.modules.keys())
16 yield
17 after = set(sys.modules.keys())
18 for extra in after - before:
19 del sys.modules[extra]
20
21
22 def test_get_native_imported_modules(cleanup_imports):
23 # Mock the is_native method to control which modules are considered native
24 with patch.object(ScaleneAnalysis, "is_native", return_value=True):
25 source_code = """
26 import math
27 import os
28 from sys import path
29 """
30 expected_imports = ["import math", "import os", "from sys import path"]
31 actual_imports = ScaleneAnalysis.get_native_imported_modules(source_code)
32 assert set(actual_imports) == set(
33 expected_imports
34 ), "The list of native imports does not match the expected list."
35
36 with patch.object(ScaleneAnalysis, "is_native", return_value=False):
37 source_code = """
38 import math
39 import os
40 from sys import path
41 """
42 expected_imports = []
43 actual_imports = ScaleneAnalysis.get_native_imported_modules(source_code)
44 assert (
45 actual_imports == expected_imports
46 ), "The list of native imports should be empty."