-
Notifications
You must be signed in to change notification settings - Fork 23
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 #248 from reagento/fix/original-field-order-on-dump
saving original field order on dumping (#247)
- Loading branch information
Showing
4 changed files
with
58 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Model dumping now trying to save the original order of fields inside the dict |
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,35 @@ | ||
from dataclasses import dataclass | ||
|
||
from adaptix import Retort, name_mapping | ||
|
||
|
||
def test_simple(accum): | ||
@dataclass | ||
class Example: | ||
c: int | ||
a: int | ||
b: int | ||
|
||
retort = Retort(recipe=[accum]) | ||
|
||
dumper = retort.get_dumper(Example) | ||
assert list(dumper(Example(c=1, a=2, b=3)).items()) == [("c", 1), ("a", 2), ("b", 3)] | ||
|
||
|
||
def test_name_flatenning(accum): | ||
@dataclass | ||
class Example: | ||
c: int | ||
a: int | ||
e: int | ||
b: int | ||
|
||
retort = Retort( | ||
recipe=[ | ||
accum, | ||
name_mapping(Example, map={"e": ("q", "e")}), | ||
], | ||
) | ||
|
||
dumper = retort.get_dumper(Example) | ||
assert list(dumper(Example(c=1, a=2, e=3, b=4)).items()) == [("c", 1), ("a", 2), ("b", 4), ("q", {"e": 3})] |