From 0332c4cb5443f27ce87391cbbddf019d97a31955 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Wed, 3 Apr 2024 11:26:15 +0000 Subject: [PATCH] Fix test --- pyodide_lock/spec.py | 6 ++++-- pyodide_lock/utils.py | 6 +++--- tests/conftest.py | 3 +++ tests/test_spec.py | 6 +++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyodide_lock/spec.py b/pyodide_lock/spec.py index 8549c6a..f559e60 100644 --- a/pyodide_lock/spec.py +++ b/pyodide_lock/spec.py @@ -17,7 +17,7 @@ class PackageSpec(BaseModel): name: str version: str file_name: str = Field( - description="Path (or URL) to wheel.", format="uri-reference" + description="Path (or URL) to wheel.", ) install_dir: str sha256: str = "" @@ -49,7 +49,9 @@ def from_json(cls, path: Path) -> "PyodideLockSpec": def to_json(self, path: Path, indent: int | None = None) -> None: """Write the lock spec to a json file.""" with path.open("w", encoding="utf-8") as fh: - fh.write(self.json(indent=indent, sort_keys=True)) + model_dict = self.model_dump() + json_str = json.dumps(model_dict, indent=indent, sort_keys=True) + fh.write(json_str) def check_wheel_filenames(self) -> None: """Check that the package name and version are consistent in wheel filenames""" diff --git a/pyodide_lock/utils.py b/pyodide_lock/utils.py index a201850..95b53fa 100644 --- a/pyodide_lock/utils.py +++ b/pyodide_lock/utils.py @@ -179,7 +179,7 @@ def add_wheels_to_spec( not 100% reliable, because it ignores any extras and does not do any sub-dependency or version resolution. """ - new_spec = lock_spec.copy(deep=True) + new_spec = lock_spec.model_copy(deep=True) if not wheel_files: return new_spec wheel_files = [f.resolve() for f in wheel_files] @@ -211,7 +211,7 @@ def _fix_new_package_deps( from packaging.utils import canonicalize_name requirements_with_extras = [] - marker_environment = _get_marker_environment(**lock_spec.info.dict()) + marker_environment = _get_marker_environment(**lock_spec.info.model_dump()) for package in new_packages.values(): # add any requirements to the list of packages our_depends = [] @@ -261,7 +261,7 @@ def _fix_extra_dep( requirements_with_extras = [] - marker_environment = _get_marker_environment(**lock_spec.info.dict()) + marker_environment = _get_marker_environment(**lock_spec.info.model_dump()) extra_package_name = canonicalize_name(extra_req.name) if extra_package_name not in new_packages: return [] diff --git a/tests/conftest.py b/tests/conftest.py index 602fe0a..1c2d3ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,9 @@ import pytest from packaging.utils import canonicalize_name +import sys +sys.path.insert(0, str(Path(__file__).parent.parent)) + from pyodide_lock import PyodideLockSpec from pyodide_lock.utils import _get_marker_environment diff --git a/tests/test_spec.py b/tests/test_spec.py index 0a78576..10a4df9 100644 --- a/tests/test_spec.py +++ b/tests/test_spec.py @@ -95,11 +95,11 @@ def test_extra_config_forbidden(example_lock_data): info_data["extra"] = "extra" # type: ignore[index] package_data["extra"] = "extra" - with pytest.raises(ValidationError, match="extra fields not permitted"): + with pytest.raises(ValidationError, match="Extra inputs are not permitted"): PyodideLockSpec(**example_lock_data) - with pytest.raises(ValidationError, match="extra fields not permitted"): + with pytest.raises(ValidationError, match="Extra inputs are not permitted"): InfoSpec(**info_data) # type: ignore[arg-type] - with pytest.raises(ValidationError, match="extra fields not permitted"): + with pytest.raises(ValidationError, match="Extra inputs are not permitted"): PackageSpec(**package_data)