Last active
September 29, 2020 19:17
-
-
Save gidgid/3d1f7752fe9f4097307b2b2484a7b1f3 to your computer and use it in GitHub Desktop.
Basic non key-value models
This file contains hidden or 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
from pydantic import BaseModel | |
class Age(BaseModel): | |
__root__: int # 1 | |
def test_specialized_models_are_not_equal_to_their_primitives(): | |
age = Age(__root__=42) | |
assert age != 42 # 2 | |
def test_age_can_also_be_parsed(): | |
age = Age.parse_obj(42) # 3 | |
assert age != 42 | |
def test_specialized_models_can_ensure_we_represent_the_correct_types(): | |
age = Age(__root__='43') | |
assert age.__root__ == 43 # 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment