-
Notifications
You must be signed in to change notification settings - Fork 40
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 #601 from yukinarit/add-skip-none
Add skip_none parameter
- Loading branch information
Showing
9 changed files
with
121 additions
and
34 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
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,56 @@ | ||
from serde import serde | ||
from serde.toml import to_toml, from_toml | ||
from typing import Optional | ||
import pytest | ||
|
||
|
||
def toml_basics() -> None: | ||
@serde | ||
class Foo: | ||
v: Optional[int] | ||
|
||
f = Foo(10) | ||
assert "v = 10\n" == to_toml(f) | ||
assert f == from_toml(Foo, "v = 10\n") | ||
|
||
@serde | ||
class Bar: | ||
v: set[int] | ||
|
||
b = Bar({1, 2, 3}) | ||
to_toml(b) | ||
|
||
|
||
def test_skip_none() -> None: | ||
@serde | ||
class Foo: | ||
a: int | ||
b: Optional[int] | ||
|
||
f = Foo(10, 100) | ||
assert ( | ||
to_toml(f) | ||
== """\ | ||
a = 10 | ||
b = 100 | ||
""" | ||
) | ||
|
||
f = Foo(10, None) | ||
assert ( | ||
to_toml(f) | ||
== """\ | ||
a = 10 | ||
""" | ||
) | ||
|
||
|
||
def test_skip_none_container_not_supported_yet() -> None: | ||
@serde | ||
class Foo: | ||
a: int | ||
b: list[Optional[int]] | ||
|
||
f = Foo(10, [100, None]) | ||
with pytest.raises(TypeError): | ||
to_toml(f) |