Skip to content

Commit

Permalink
Merge pull request #190 from fonttools/structure-unstructure-default-…
Browse files Browse the repository at this point in the history
…methods

export structure/unstructure public methods using default_converter
  • Loading branch information
anthrotype authored Dec 17, 2021
2 parents 66d3de0 + 7f01997 commit e08a421
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/ufoLib2/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def get_origin(cl: Type[Any]) -> Any:


__all__ = [
"default_converter",
"register_hooks",
"structure",
"unstructure",
]


Expand Down Expand Up @@ -139,3 +140,6 @@ def structure_bytes(v: str, _: Any) -> bytes:
prefer_attrib_converters=False,
)
register_hooks(default_converter, allow_bytes=False)

structure = default_converter.structure
unstructure = default_converter.unstructure
14 changes: 7 additions & 7 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# isort: off
cattr = pytest.importorskip("cattr")
from ufoLib2.converters import default_converter, register_hooks # noqa: E402
from ufoLib2.converters import register_hooks, structure, unstructure # noqa: E402


@pytest.mark.parametrize(
Expand Down Expand Up @@ -499,17 +499,17 @@
],
)
def test_unstructure_structure(obj: Any, expected: dict[str, Any]) -> None:
assert default_converter.unstructure(obj) == expected
assert default_converter.structure(expected, type(obj)) == obj
assert unstructure(obj) == expected
assert structure(expected, type(obj)) == obj


def test_unstructure_lazy_font(ufo_UbuTestData: Font) -> None:
font1 = ufo_UbuTestData
assert font1._lazy

font_data = default_converter.unstructure(font1)
font_data = unstructure(font1)

font2 = default_converter.structure(font_data, Font)
font2 = structure(font_data, Font)
assert font2 == font1

assert not font2._lazy
Expand Down Expand Up @@ -683,7 +683,7 @@ def test_json_dumps(datadir: pathlib.Path) -> None:
# opening the UFO on Windows
font.features.normalize_newlines()

data = default_converter.unstructure(font)
data = unstructure(font)

expected = (datadir / "MutatorSansBoldCondensed.json").read_text()

Expand All @@ -698,4 +698,4 @@ def test_json_loads(datadir: pathlib.Path) -> None:
# opening the UFO on Windows
expected.features.normalize_newlines()

assert default_converter.structure(data, Font) == expected
assert structure(data, Font) == expected

0 comments on commit e08a421

Please sign in to comment.