serde/fix: round trip string sanitizing

This commit is contained in:
Johannes Kirschbauer
2024-09-03 18:03:13 +02:00
parent 7da49a1538
commit caad48682d
2 changed files with 13 additions and 2 deletions

View File

@@ -265,6 +265,18 @@ def test_none_or_string() -> None:
assert checked3 is None
def test_roundtrip_escape() -> None:
assert from_dict(str, "\\n") == "\n"
assert dataclass_to_dict("\n") == "\\n"
# Test that the functions are inverses of each other
# f(g(x)) == x
# and
# g(f(x)) == x
assert from_dict(str, dataclass_to_dict("\n")) == "\n"
assert dataclass_to_dict(from_dict(str, "\\n")) == "\\n"
def test_path_field() -> None:
@dataclass
class Person: