-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Showing
6 changed files
with
54 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dataclasses import dataclass | ||
from datetime import date | ||
|
||
from mashumaro import DataClassDictMixin | ||
from mashumaro.codecs import BasicDecoder, BasicEncoder | ||
|
||
|
||
def test_type_alias_type_with_dataclass_dict_mixin(): | ||
type MyDate = date | ||
|
||
@dataclass | ||
class MyClass(DataClassDictMixin): | ||
x: MyDate | ||
|
||
obj = MyClass(date(2024, 4, 15)) | ||
assert MyClass.from_dict({"x": "2024-04-15"}) == obj | ||
assert obj.to_dict() == {"x": "2024-04-15"} | ||
|
||
|
||
def test_type_alias_type_with_codecs(): | ||
type MyDate = date | ||
decoder = BasicDecoder(MyDate) | ||
encoder = BasicEncoder(MyDate) | ||
|
||
obj = date(2024, 4, 15) | ||
assert decoder.decode("2024-04-15") == obj | ||
assert encoder.encode(obj) == "2024-04-15" |