-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_runtime_detection.py
More file actions
50 lines (41 loc) · 1.64 KB
/
test_runtime_detection.py
File metadata and controls
50 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
from pyodide_pack.config import PackConfig
from pyodide_pack.dynamic_lib import DynamicLib
from pyodide_pack.runtime_detection import PackageBundler, RuntimeResults
def test_runtime_results(tmp_path):
input_data = {
"opened_file_names": ["a.py", "b.py", "__pycache__/a.cpython-38.pyc"],
"load_dyn_lib_calls": [
{"path": "c.so", "global": False},
{"path": "d.so", "global": False},
{"path": "g.so", "global": True},
],
"dl_accessed_symbols": {"c.so": None},
}
with open(tmp_path / "results.json", "w") as fh:
json.dump(input_data, fh)
res = RuntimeResults.from_json(tmp_path / "results.json")
assert list(res.keys()) == [
"opened_file_names",
"load_dyn_lib_calls",
"dl_accessed_symbols",
"dynamic_libs_map",
]
assert res["opened_file_names"] == ["a.py", "b.py"]
assert res["dynamic_libs_map"] == {
"c.so": DynamicLib(path="c.so", load_order=0, shared=False),
"d.so": DynamicLib(path="d.so", load_order=1, shared=False),
"g.so": DynamicLib(path="g.so", load_order=2, shared=True),
}
def test_bundler_process_path(tmp_path):
db = RuntimeResults(
opened_file_names=["a.py", "d/b.py", "d/f.so", "c.so"],
dynamic_libs_map={
"d/f.so": DynamicLib(path="d/f.so", load_order=0, shared=False)
},
)
bundler = PackageBundler(db, config=PackConfig())
assert bundler.process_path("k.py") is None
assert bundler.process_path("a.py") == "a.py"
assert bundler.process_path("b.py") == "d/b.py"
assert bundler.process_path("f.so") == "d/f.so"