Skip to content

Commit

Permalink
also test {json,msgpack}_load/dump with paths, in addition to files
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Nov 3, 2022
1 parent 0ac647b commit 6378e56
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/serde/test_json.py
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions tests/serde/test_msgpack.py
Expand Up @@ -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
Expand Down

0 comments on commit 6378e56

Please sign in to comment.