Skip to content

Commit

Permalink
TST Test micropip.freeze() with pyodide-lock (#153)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ryanking13 and pre-commit-ci[bot] authored Nov 10, 2024
1 parent a3bdb1c commit 88669c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test = [
"pytest-cov",
"pytest<8.0.0",
"build==0.7.0",
"pyodide-lock==v0.1.0a8",
]


Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Wheel:
_path: Path

name: str
version: str
filename: str
top_level: str
url: str
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 88669c8

Please sign in to comment.