-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9370a40
commit 299cec2
Showing
3 changed files
with
62 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
PEP 0673 that allows self-references has only been added in 3.11 | ||
This suite verifies that we are somewhat able to serde self-referencing classes before 3.11. | ||
""" | ||
import json | ||
from typing import Dict | ||
|
||
import pytest | ||
|
||
from tests.entities import DataClassWithSelf | ||
|
||
|
||
class TestSelf: | ||
@pytest.mark.parametrize("entity, expected", [ | ||
(DataClassWithSelf(id="1", ref=None), { | ||
"id": "1", | ||
"ref": None | ||
}), | ||
(DataClassWithSelf(id="1", ref=DataClassWithSelf(id="2", ref=None)), { | ||
"id": "1", | ||
"ref": { "id": "2", "ref": None } | ||
}) | ||
]) | ||
def test_self_serde(self, entity: DataClassWithSelf, expected: Dict): | ||
assert entity.to_dict() == expected and DataClassWithSelf.from_dict(expected).to_json() == entity.to_json() | ||
|
||
@pytest.mark.parametrize("entity", [ | ||
({ | ||
"id": "1", | ||
"ref": {"id": "2", "ref": None} | ||
}), | ||
({ | ||
"id": "1", | ||
"ref": None | ||
}) | ||
]) | ||
def test_self_type(self, entity: Dict): | ||
obj = DataClassWithSelf.from_json(json.dumps(entity)) | ||
assert isinstance(obj, DataClassWithSelf) and (isinstance(obj.ref, DataClassWithSelf) or isinstance(obj.ref, type(None))) |
299cec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
299cec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
299cec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
299cec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
299cec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
299cec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report