From 8d58f162b96014472c14cc13ef8c14f4b8cc8485 Mon Sep 17 00:00:00 2001 From: Jany Belluz Date: Mon, 27 Aug 2018 14:18:39 +0100 Subject: [PATCH] Add failing tests for bad glyph names in the source UFO --- tests/featureWriters/kernFeatureWriter_test.py | 10 ++++++++++ tests/featureWriters/markFeatureWriter_test.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/featureWriters/kernFeatureWriter_test.py b/tests/featureWriters/kernFeatureWriter_test.py index 3fba94167..77126f870 100644 --- a/tests/featureWriters/kernFeatureWriter_test.py +++ b/tests/featureWriters/kernFeatureWriter_test.py @@ -10,6 +10,7 @@ from ufo2ft.featureCompiler import parseLayoutFeatures from ufo2ft.featureWriters import KernFeatureWriter, ast +from ufo2ft.errors import InvalidFontData import pytest from . import FeatureWriterTest @@ -722,6 +723,15 @@ def test_kern_RTL_and_DFLT_numbers(self, FontClass): """ ) + def test_error_on_bad_glyph_name(self, FontClass): + # One glyph has an invalid glyph name (in fea syntax): "V," + glyphs = {"A": ord('A'), "V,": ord("V")} + kerning = {("A", "V,"): -40} + features = "languagesystem latn dflt;" + ufo = makeUFO(FontClass, glyphs, kerning=kerning, features=features) + with pytest.raises(InvalidFontData): + generated = self.writeFeatures(ufo) + if __name__ == "__main__": import sys diff --git a/tests/featureWriters/markFeatureWriter_test.py b/tests/featureWriters/markFeatureWriter_test.py index 10465c3c0..086d31d8d 100644 --- a/tests/featureWriters/markFeatureWriter_test.py +++ b/tests/featureWriters/markFeatureWriter_test.py @@ -13,6 +13,7 @@ parseAnchorName, ) from ufo2ft.featureCompiler import parseLayoutFeatures +from ufo2ft.errors import InvalidFontData import pytest from . import FeatureWriterTest @@ -579,6 +580,14 @@ def test_all_features(self, testufo): """ ) + def test_error_on_bad_glyph_name(self, testufo): + # Add a glyph with an invalid name to the test UFO: "f_i," + testufo.newGlyph("a,").appendAnchor({"name": "top", "x": 100, "y": 200}) + writer = MarkFeatureWriter() + feaFile = ast.FeatureFile() + with pytest.raises(InvalidFontData): + writer.write(testufo, feaFile) + if __name__ == "__main__": import sys