Debian Codegraph @

tests/test_coverup_19.py

raw symbols SCIP
1 # file scalene/scalene_analysis.py:16-42
2 # lines [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 38, 39, 41, 42]
3 # branches ['24->25', '24->30', '26->27', '26->30', '27->26', '27->28', '28->27', '28->29']
4
5 import os
6 import pytest
7 import tempfile
8 import shutil
9 import sys
10 from scalene.scalene_analysis import ScaleneAnalysis
11
12
13 @pytest.fixture
14 def create_native_package():
15 # Create a temporary directory to simulate a native package with a .so file
16 temp_dir = tempfile.mkdtemp()
17 package_name = "native_package"
18 package_dir = os.path.join(temp_dir, package_name)
19 os.makedirs(package_dir)
20 init_file = os.path.join(package_dir, "__init__.py")
21 so_file = os.path.join(package_dir, "module.so")
22 with open(init_file, "w") as f:
23 f.write("# This is a simulated native package")
24 with open(so_file, "w") as f:
25 f.write("This is a simulated shared object file")
26 # Add the temporary directory to sys.path so it can be imported
27 sys.path.append(temp_dir)
28 yield package_name
29 # Cleanup
30 sys.path.remove(temp_dir)
31 shutil.rmtree(temp_dir)
32
33
34 def test_is_native(create_native_package):
35 package_name = create_native_package
36 assert ScaleneAnalysis.is_native(package_name) == True
37
38
39 def test_is_not_native():
40 non_existent_package = "non_existent_package"
41 assert ScaleneAnalysis.is_native(non_existent_package) == False
42
43
44 def test_is_builtin():
45 builtin_package = "sys"
46 assert ScaleneAnalysis.is_native(builtin_package) == True
47
48
49 def test_is_python_package():
50 python_package = "json"
51 assert ScaleneAnalysis.is_native(python_package) == False