-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test!: test roundtrip serialisation against strict + lax schema (#982)
We also include some ops in testing, and apply required fixes. Note that we intend to replace this `rstest::case` style testing with `proptest`. BREAKING CHANGE: serialisation schema
- Loading branch information
Showing
12 changed files
with
5,404 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
from typing import Literal, Optional | ||
from pydantic import BaseModel | ||
from .tys import Type, SumType, PolyFuncType | ||
from .ops import Value | ||
from pydantic import ConfigDict | ||
from typing import Literal | ||
from .tys import Type, SumType, PolyFuncType, ConfiguredBaseModel, model_rebuild | ||
from .ops import Value, OpType, classes as ops_classes | ||
|
||
|
||
class TestingHugr(BaseModel): | ||
"""A serializable representation of a Hugr Type, SumType, PolyFuncType, or | ||
Value. Intended for testing only.""" | ||
class TestingHugr(ConfiguredBaseModel): | ||
"""A serializable representation of a Hugr Type, SumType, PolyFuncType, | ||
Value, OpType. Intended for testing only.""" | ||
|
||
version: Literal["v1"] = "v1" | ||
typ: Optional[Type] = None | ||
sum_type: Optional[SumType] = None | ||
poly_func_type: Optional[PolyFuncType] = None | ||
value: Optional[Value] = None | ||
typ: Type | None = None | ||
sum_type: SumType | None = None | ||
poly_func_type: PolyFuncType | None = None | ||
value: Value | None = None | ||
optype: OpType | None = None | ||
|
||
@classmethod | ||
def get_version(cls) -> str: | ||
"""Return the version of the schema.""" | ||
return cls().version | ||
|
||
@classmethod | ||
def _pydantic_rebuild(cls, config: ConfigDict = ConfigDict(), **kwargs): | ||
my_classes = dict(ops_classes) | ||
my_classes[cls.__name__] = cls | ||
model_rebuild(my_classes, config=config, **kwargs) | ||
|
||
class Config: | ||
title = "HugrTesting" |
Oops, something went wrong.