Skip to content

Commit

Permalink
test unlazify, deepcopy, __eq__ and __ne__
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Dec 13, 2019
1 parent 765967c commit 15d6f0f
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions tests/test_ufoLib2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from copy import deepcopy

from fontTools import ufoLib

import ufoLib2
from ufoLib2.objects.misc import _NOT_LOADED

Expand Down Expand Up @@ -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

0 comments on commit 15d6f0f

Please sign in to comment.