Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 committed Apr 3, 2024
1 parent fa14337 commit 0332c4c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pyodide_lock/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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"""
Expand Down
6 changes: 3 additions & 3 deletions pyodide_lock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 []
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0332c4c

Please sign in to comment.