From ad69b8b63b86e2b4e5c328f33a7e9ae7472598e5 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Sun, 8 Oct 2023 10:57:00 +0200 Subject: [PATCH] Add tests --- pyodide_pack/tests/test_runtime_detection.py | 32 +++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/pyodide_pack/tests/test_runtime_detection.py b/pyodide_pack/tests/test_runtime_detection.py index dff1bba..3a68549 100644 --- a/pyodide_pack/tests/test_runtime_detection.py +++ b/pyodide_pack/tests/test_runtime_detection.py @@ -1,13 +1,18 @@ import json from pyodide_pack.dynamic_lib import DynamicLib -from pyodide_pack.runtime_detection import RuntimeResults +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"], - "find_object_calls": ["c.so"], + "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: @@ -16,11 +21,30 @@ def test_runtime_results(tmp_path): res = RuntimeResults.from_json(tmp_path / "results.json") assert list(res.keys()) == [ "opened_file_names", - "find_object_calls", + "load_dyn_lib_calls", + "dl_accessed_symbols", "dynamic_libs_map", ] assert res["opened_file_names"] == ["a.py", "b.py"] + # d.so not included as it's not in accessed LDSO symbols + # g.so is include as it's globally loaded assert res["dynamic_libs_map"] == { - "c.so": DynamicLib(path="c.so", load_order=0, shared=False) + "c.so": DynamicLib(path="c.so", load_order=0, 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) + + 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"