-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from mdrachuk/validate-options
Validate options
- Loading branch information
Showing
10 changed files
with
152 additions
and
56 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
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 |
---|---|---|
@@ -1,22 +1,41 @@ | ||
from typing import List, Set, Tuple, Optional, FrozenSet | ||
from collections import namedtuple | ||
from dataclasses import dataclass | ||
from decimal import Decimal | ||
from typing import List, Set, Tuple, Optional, FrozenSet, Type | ||
|
||
from serious import JsonModel, DictModel | ||
from serious.test_utils import assert_symmetric | ||
from tests.entities import dataclass_of | ||
from tests.utils import with_ | ||
|
||
Ex = namedtuple('Example', ['value_type', 'value']) | ||
|
||
models = [JsonModel, DictModel] | ||
objects = [ | ||
dataclass_of(List[int])([1, 2, 3]), | ||
dataclass_of(Set[int])({1, 2, 3}), | ||
dataclass_of(Tuple[int, Ellipsis])(tuple([1, 2, 3])), | ||
dataclass_of(Tuple[int, str, int])(tuple([1, 'two', 3])), | ||
dataclass_of(FrozenSet[int])(frozenset([1, 2, 3])), | ||
dataclass_of(Optional[int])(None), | ||
dataclass_of(Optional[int])(3), | ||
Ex(int, 3), | ||
Ex(float, 0.7), | ||
Ex(str, '¡hellø!'), | ||
Ex(Decimal, Decimal('3')), | ||
Ex(List[int], [1, 2, 3]), | ||
Ex(Set[int], {1, 2, 3}), | ||
Ex(Tuple[int, Ellipsis], tuple([1, 2, 3])), | ||
Ex(Tuple[int, str, int], tuple([1, 'two', 3])), | ||
Ex(FrozenSet[int], frozenset([1, 2, 3])), | ||
Ex(Optional[int], None), | ||
Ex(Optional[int], 3), | ||
] | ||
|
||
|
||
@with_(models, objects) | ||
def test_generic_encode_and_decode_are_inverses(new_model, dc): | ||
assert_symmetric(new_model(type(dc)), dc) | ||
def test_generic_encode_and_decode_are_inverses(new_model, example: Ex): | ||
type_ = generic_dataclass(example.value_type) | ||
model = new_model(type_) | ||
instance = type_(example.value) | ||
assert_symmetric(model, instance) | ||
|
||
|
||
def generic_dataclass(type_: Type): | ||
@dataclass(frozen=True) | ||
class GenDataclass: | ||
value: type_ | ||
|
||
return GenDataclass |
Oops, something went wrong.