Add exception and test

This commit is contained in:
Tom Archer 2021-01-19 17:53:53 +00:00
parent 9c0bc9e554
commit 7c6337facf
2 changed files with 14 additions and 1 deletions

View File

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

View File

@ -1101,6 +1101,18 @@ class ClassDefBuilderTest(object):
assert not b.canAdd({"d", "e", "f"})
assert not b.canAdd({"f"})
def test_add_exception(self):
b = builder.ClassDefBuilder(useClass0=True)
b.add({"a", "b", "c", "d"})
with pytest.raises(TypeError):
b.add({"a"})
with pytest.raises(TypeError):
b.add({"b"})
with pytest.raises(TypeError):
b.add({"c"})
with pytest.raises(TypeError):
b.add({"d"})
buildStatTable_test_data = [
([