Skip to content

Commit

Permalink
Add ideal test for round-trip deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Jun 20, 2024
1 parent 64cce52 commit 4a23bdf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/test_bonsai.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ def __init__(self, bonsai_property: str, json_root: Path, model: TModel):
self.deserialized_model: Optional[TModel] = None

def validate_deserialization(self) -> bool:
return self.input_model == self.deserialized_model
if not self.input_model:
raise ValueError("Input model is not set.")
if not self.deserialized_model:
raise ValueError("Deserialized model is not set.")
_round_trip = self.input_model.model_validate_json(
self.input_model.model_dump_json()
)
return _round_trip == self.deserialized_model

def try_deserialization(self, json_str: Union[str, List[str]]) -> TModel:
_deserialized: Optional[TModel] = None
Expand Down

0 comments on commit 4a23bdf

Please sign in to comment.