diff --git a/tests/test_ufoLib2.py b/tests/test_ufoLib2.py index 60c1658c..416eae10 100644 --- a/tests/test_ufoLib2.py +++ b/tests/test_ufoLib2.py @@ -1,3 +1,7 @@ +from copy import deepcopy + +from fontTools import ufoLib + import ufoLib2 from ufoLib2.objects.misc import _NOT_LOADED @@ -57,6 +61,53 @@ def test_constructor_from_path(datadir): assert font2._validate is False assert font2._reader is None - font.unlazify() - assert font == font2 + + +def test_deepcopy_lazy_object(datadir): + font1 = ufoLib2.Font.open(datadir / "UbuTestData.ufo", lazy=True) + + font2 = deepcopy(font1) + + assert font1 is not font2 + assert font1.layers is not font2.layers + assert font1.layers.defaultLayer is not font2.layers.defaultLayer + assert font1.data is not font2.data + assert font1.images is not font2.images + + +def test_unlazify(datadir): + reader = ufoLib.UFOReader(datadir / "UbuTestData.ufo") + font = ufoLib2.Font.read(reader, lazy=True) + + assert font._reader is reader + assert not reader.fs.isclosed() + + font.unlazify() # close_reader=False by default + + assert font._reader is None + assert not reader.fs.isclosed() + + +def test_unlazify_close_reader(datadir): + reader = ufoLib.UFOReader(datadir / "UbuTestData.ufo") + font = ufoLib2.Font.read(reader, lazy=True) + + assert font._reader is reader + assert not reader.fs.isclosed() + + font.unlazify(close_reader=True) + + assert font._reader is None + assert reader.fs.isclosed() + + +def test_font_eq_and_ne(ufo_UbuTestData): + font1 = ufo_UbuTestData + font2 = deepcopy(font1) + + assert font1 == font2 + + font1["a"].contours[0].points[0].x = 0 + + assert font1 != font2