Merge pull request #2155 from daltonmaag/add-verbose-error-for-classdefbuilder-add

Raise an exception when ClassDefBuilder attempts to add a duplicate glyph.
This commit is contained in:
Cosimo Lupo 2021-01-25 17:19:21 +00:00 committed by GitHub
commit 7db6b8aae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -2574,7 +2574,8 @@ class ClassDefBuilder(object):
return return
self.classes_.add(glyphs) self.classes_.add(glyphs)
for glyph in glyphs: for glyph in glyphs:
assert glyph not in self.glyphs_ if glyph in self.glyphs_:
raise OpenTypeLibError(f"Glyph {glyph} is already present in class.", None)
self.glyphs_[glyph] = glyphs self.glyphs_[glyph] = glyphs
def classes(self): def classes(self):

View File

@ -2,7 +2,7 @@ import io
import struct import struct
from fontTools.misc.fixedTools import floatToFixed from fontTools.misc.fixedTools import floatToFixed
from fontTools.misc.testTools import getXML from fontTools.misc.testTools import getXML
from fontTools.otlLib import builder from fontTools.otlLib import builder, error
from fontTools import ttLib from fontTools import ttLib
from fontTools.ttLib.tables import otTables from fontTools.ttLib.tables import otTables
import pytest import pytest
@ -1101,6 +1101,12 @@ class ClassDefBuilderTest(object):
assert not b.canAdd({"d", "e", "f"}) assert not b.canAdd({"d", "e", "f"})
assert not b.canAdd({"f"}) assert not b.canAdd({"f"})
def test_add_exception(self):
b = builder.ClassDefBuilder(useClass0=True)
b.add({"a", "b", "c"})
with pytest.raises(error.OpenTypeLibError):
b.add({"a", "d"})
buildStatTable_test_data = [ buildStatTable_test_data = [
([ ([