[ttGlyphPen_test] Parametrize test

This commit is contained in:
Behdad Esfahbod 2023-02-22 08:41:14 -07:00
parent bbdee18f67
commit 303eeeeec5

View File

@ -4,7 +4,7 @@ import struct
from fontTools import ttLib from fontTools import ttLib
from fontTools.pens.basePen import PenError from fontTools.pens.basePen import PenError
from fontTools.pens.recordingPen import RecordingPen from fontTools.pens.recordingPen import RecordingPen, RecordingPointPen
from fontTools.pens.ttGlyphPen import TTGlyphPen, TTGlyphPointPen, MAX_F2DOT14 from fontTools.pens.ttGlyphPen import TTGlyphPen, TTGlyphPointPen, MAX_F2DOT14
@ -638,65 +638,73 @@ class CubicGlyfTest:
("closePath", ()), ("closePath", ()),
] ]
def test_cubic_topology(self): @pytest.mark.parametrize(
for preserveTopology in (False, True): "preserveTopology, segment_pen_commands, point_pen_commands, expected_coordinates, expected_flags",
[
(
False,
[
("moveTo", ((0, 0),)),
("curveTo", ((0, 1), (1, 2), (2, 2))),
("curveTo", ((3, 2), (4, 1), (4, 0))),
("closePath", ()),
],
[
("beginPath", (), {}),
("addPoint", ((0, 0), "line", None, None), {}),
("addPoint", ((0, 1), None, None, None), {}),
("addPoint", ((1, 2), None, None, None), {}),
("addPoint", ((2, 2), "curve", None, None), {}),
("addPoint", ((3, 2), None, None, None), {}),
("addPoint", ((4, 1), None, None, None), {}),
("addPoint", ((4, 0), "curve", None, None), {}),
("endPath", (), {}),
],
[(0, 0), (0, 1), (1, 2), (3, 2), (4, 1), (4, 0)],
[0x01, 0x80, 0x80, 0x80, 0x80, 0x01],
),
(
True,
[
("moveTo", ((0, 0),)),
("curveTo", ((0, 1), (1, 2), (2, 2))),
("curveTo", ((3, 2), (4, 1), (4, 0))),
("closePath", ()),
],
[
("beginPath", (), {}),
("addPoint", ((0, 0), "line", None, None), {}),
("addPoint", ((0, 1), None, None, None), {}),
("addPoint", ((1, 2), None, None, None), {}),
("addPoint", ((2, 2), "curve", None, None), {}),
("addPoint", ((3, 2), None, None, None), {}),
("addPoint", ((4, 1), None, None, None), {}),
("addPoint", ((4, 0), "curve", None, None), {}),
("endPath", (), {}),
],
[(0, 0), (0, 1), (1, 2), (2, 2), (3, 2), (4, 1), (4, 0)],
[0x01, 0x80, 0x80, 0x01, 0x80, 0x80, 0x01],
),
],
)
def test_cubic_topology(
self,
preserveTopology,
segment_pen_commands,
point_pen_commands,
expected_coordinates,
expected_flags,
):
spen = TTGlyphPen(None) spen = TTGlyphPen(None)
spen.moveTo((0, 0)) rpen = RecordingPen()
spen.curveTo((0, 1), (1, 2), (2, 2)) rpen.value = segment_pen_commands
spen.curveTo((3, 2), (4, 1), (4, 0)) rpen.replay(spen)
spen.closePath()
ppen = TTGlyphPointPen(None) ppen = TTGlyphPointPen(None)
ppen.beginPath() rpen = RecordingPointPen()
ppen.addPoint((0, 0), "line") rpen.value = point_pen_commands
ppen.addPoint((0, 1)) rpen.replay(ppen)
ppen.addPoint((1, 2))
ppen.addPoint((2, 2), "curve")
ppen.addPoint((3, 2))
ppen.addPoint((4, 1))
ppen.addPoint((4, 0), "curve")
ppen.endPath()
expected_coordinates = (
[
(0, 0),
(0, 1),
(1, 2),
(2, 2),
(3, 2),
(4, 1),
(4, 0),
]
if preserveTopology
else [
(0, 0),
(0, 1),
(1, 2),
(3, 2),
(4, 1),
(4, 0),
]
)
expected_flags = (
[
0x01,
0x80,
0x80,
0x01,
0x80,
0x80,
0x01,
]
if preserveTopology
else [
0x01,
0x80,
0x80,
0x80,
0x80,
0x01,
]
)
for pen in (spen, ppen): for pen in (spen, ppen):
@ -707,26 +715,7 @@ class CubicGlyfTest:
rpen = RecordingPen() rpen = RecordingPen()
glyph.draw(rpen, None) glyph.draw(rpen, None)
assert rpen.value == [ assert rpen.value == segment_pen_commands
("moveTo", ((0, 0),)),
(
"curveTo",
(
(0, 1),
(1, 2),
(2, 2),
),
),
(
"curveTo",
(
(3, 2),
(4, 1),
(4, 0),
),
),
("closePath", ()),
]
class _TestGlyph(object): class _TestGlyph(object):