-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR makes the schema serializable to JSON via Object.json() PR includes feature, tests and documentation Link to Issue #177
- Loading branch information
1 parent
713c2bf
commit f910fc4
Showing
4 changed files
with
149 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
from kor import Bool, Number, Object, Text | ||
from kor.nodes import ExtractionSchemaNode | ||
|
||
|
||
@pytest.fixture(params=ExtractionSchemaNode.__subclasses__()) | ||
def extraction_subclass(request: Any) -> Any: | ||
return request.param | ||
|
||
|
||
def test_extractionschemanode_has_type_discriminator( | ||
extraction_subclass: Any, | ||
) -> None: | ||
sut = extraction_subclass(id="test") | ||
assert sut.dict()["$type"] == extraction_subclass.__name__ | ||
|
||
|
||
def test_serialize_deserialize_equals() -> None: | ||
expected = Object( | ||
id="root", | ||
description="root-object", | ||
attributes=[ | ||
Number(id="number", description="Number description", examples=[]), | ||
Text(id="text", description="text description", examples=[]), | ||
Bool(id="bool", description="bool description", examples=[]), | ||
], | ||
examples=[], | ||
) | ||
|
||
json = expected.json() | ||
sut = Object.parse_raw(json) | ||
|
||
assert sut == expected |