Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for pydantic v2 #27

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/hdf5_reader_service/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import h5py as h5
from pydantic import BaseModel
from pydantic.generics import GenericModel


class DatasetMacroStructure(BaseModel):
Expand Down Expand Up @@ -55,7 +54,7 @@ class ShapeMetadata(BaseModel):
T = TypeVar("T")


class ValidNode(GenericModel, Generic[T]):
class ValidNode(BaseModel, Generic[T]):
contents: T
subnodes: List["DataTree"] = []

Expand All @@ -69,10 +68,10 @@ class InvalidNode(BaseModel):
reason: InvalidNodeReason


class DataTree(GenericModel, Generic[T]):
class DataTree(BaseModel, Generic[T]):
name: str
valid: bool
node: Union[InvalidNode, ValidNode[T]]


ValidNode.update_forward_refs()
ValidNode.model_rebuild()
2 changes: 1 addition & 1 deletion src/hdf5_reader_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def default(content):
return content.decode("utf-8")
elif isinstance(content, BaseModel):
# Handle the pydantic model case
return content.dict()
return content.model_dump()
raise TypeError

# Not all numpy dtypes are supported by orjson.
Expand Down
97 changes: 0 additions & 97 deletions tests/test_boilerplate_removed copy.py

This file was deleted.

64 changes: 0 additions & 64 deletions tests/test_boilerplate_removed.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_read_shapes(
"/shapes/", params={"path": str(test_data_path), "subpath": subpath}
)
assert response.status_code == 200
actual_shape = DataTree[ShapeMetadata].parse_obj(response.json())
actual_shape = DataTree[ShapeMetadata].model_validate(response.json())
assert actual_shape == shape


Expand All @@ -56,7 +56,7 @@ def test_read_tree(
"/tree/", params={"path": str(test_data_path), "subpath": subpath}
)
assert response.status_code == 200
actual_tree = DataTree[MetadataNode].parse_obj(response.json())
actual_tree = DataTree[MetadataNode].model_validate(response.json())
assert actual_tree == tree


Expand All @@ -68,7 +68,7 @@ def test_read_info(
"/info/", params={"path": str(test_data_path), "subpath": subpath}
)
assert response.status_code == 200
actual_metadata = MetadataNode.parse_obj(response.json())
actual_metadata = MetadataNode.model_validate(response.json())
assert actual_metadata == metadata


Expand All @@ -80,7 +80,7 @@ def test_read_search(
"/search/", params={"path": str(test_data_path), "subpath": subpath}
)
assert response.status_code == 200
actual_children = NodeChildren.parse_obj(response.json())
actual_children = NodeChildren.model_validate(response.json())
assert actual_children == children


Expand Down
Loading