From 6378e56c73626ea7799b31a6e5bc9180a9cb0bcc Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 28 Jul 2022 11:08:18 +0200 Subject: [PATCH] also test {json,msgpack}_load/dump with paths, in addition to files --- tests/serde/test_json.py | 18 ++++++++++++++++++ tests/serde/test_msgpack.py | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/serde/test_json.py b/tests/serde/test_json.py index 88d4c502..dd47bef8 100644 --- a/tests/serde/test_json.py +++ b/tests/serde/test_json.py @@ -63,6 +63,24 @@ def test_dump_load( assert font == font2 + with open(tmp_path / "test.json", "wb") as f: + font.json_dump(f, indent=indent, sort_keys=sort_keys) # type: ignore + + # load/dump work with paths too, not just file objects + font3 = ufoLib2.objects.Font.json_load(tmp_path / "test.json") # type: ignore + + assert font == font3 + + font.json_dump( # type: ignore + tmp_path / "test2.json", + indent=indent, + sort_keys=sort_keys, + ) + + assert (tmp_path / "test.json").read_bytes() == ( + tmp_path / "test2.json" + ).read_bytes() + @pytest.mark.parametrize("indent", [1, 3], ids=["indent-1", "indent-3"]) def test_indent_not_2_orjson(indent: int) -> None: diff --git a/tests/serde/test_msgpack.py b/tests/serde/test_msgpack.py index 55ef4117..6a697015 100644 --- a/tests/serde/test_msgpack.py +++ b/tests/serde/test_msgpack.py @@ -33,6 +33,17 @@ def test_dump_load(tmp_path: Path, ufo_UbuTestData: ufoLib2.objects.Font) -> Non assert font == font2 + # laod/dump work with paths too, not just file objects + font3 = ufoLib2.objects.Font.msgpack_load(tmp_path / "test.msgpack") # type: ignore + + assert font == font3 + + font.msgpack_dump(tmp_path / "test2.msgpack") # type: ignore + + assert (tmp_path / "test.msgpack").read_bytes() == ( + tmp_path / "test2.msgpack" + ).read_bytes() + def test_allow_bytes(ufo_UbuTestData: ufoLib2.objects.Font) -> None: font = ufo_UbuTestData