From 88669c80883ead1327dc93e33abf3c8322a13b09 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Sun, 10 Nov 2024 11:11:56 +0900 Subject: [PATCH] TST Test micropip.freeze() with pyodide-lock (#153) * Add test dependency * Add compatibility test for freeze * async * No return * Update test * fix slice * Fix * Fix test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pyproject.toml | 1 + tests/conftest.py | 5 +++-- tests/test_freeze.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5039c30..d625ea7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ test = [ "pytest-cov", "pytest<8.0.0", "build==0.7.0", + "pyodide-lock==v0.1.0a8", ] diff --git a/tests/conftest.py b/tests/conftest.py index 6e903ae..b0151c3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -97,6 +97,7 @@ class Wheel: _path: Path name: str + version: str filename: str top_level: str url: str @@ -128,14 +129,14 @@ def _register_handler(self, path: Path) -> str: return self._httpserver.url_for(f"/{path.name}") def add_wheel(self, path: Path, replace: bool = True): - name = parse_wheel_filename(path.name)[0] + name, version = parse_wheel_filename(path.name)[0:2] url = self._register_handler(path) if name in self._wheels and not replace: return self._wheels[name] = self.Wheel( - path, name, path.name, name.replace("-", "_"), url + path, name, str(version), path.name, name.replace("-", "_"), url ) def get(self, name: str) -> Wheel: diff --git a/tests/test_freeze.py b/tests/test_freeze.py index 50b8eb8..d04c706 100644 --- a/tests/test_freeze.py +++ b/tests/test_freeze.py @@ -64,3 +64,31 @@ async def test_freeze_fix_depends( assert pkg_metadata["imports"] == toplevel[0] assert dep1_metadata["imports"] == toplevel[1] assert dep2_metadata["imports"] == toplevel[2] + + +def test_freeze_lockfile_compat(selenium_standalone_micropip, wheel_catalog, tmp_path): + from pyodide_lock import PyodideLockSpec + + selenium = selenium_standalone_micropip + snowball_wheel = wheel_catalog.get("snowballstemmer") + url = snowball_wheel.url + + lockfile_content = selenium.run_async( + f""" + await micropip.install("{url}") + micropip.freeze() + """ + ) + + lockfile_path = tmp_path / "lockfile.json" + with open(lockfile_path, "w") as f: + f.write(lockfile_content) + + lockfile = PyodideLockSpec.from_json(lockfile_path) + assert lockfile.packages["snowballstemmer"].file_name == url + assert lockfile.packages["snowballstemmer"].name == "snowballstemmer" + assert lockfile.packages["snowballstemmer"].depends == [] + assert lockfile.packages["snowballstemmer"].imports == ["snowballstemmer"] + assert lockfile.packages["snowballstemmer"].install_dir == "site" + assert not lockfile.packages["snowballstemmer"].unvendored_tests + assert lockfile.packages["snowballstemmer"].version == snowball_wheel.version