From 51eda21b0a41d325d00bea74d94e6ae57c436a1b Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Thu, 10 Feb 2022 17:11:26 +0100 Subject: [PATCH] Adding more unittests, based on feedback. --- Tests/otlLib/builder_test.py | 25 +++++++++++++++++++++++++ Tests/ttLib/tables/_n_a_m_e_test.py | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Tests/otlLib/builder_test.py b/Tests/otlLib/builder_test.py index c7872d0f2..ed6f1579c 100644 --- a/Tests/otlLib/builder_test.py +++ b/Tests/otlLib/builder_test.py @@ -1448,8 +1448,33 @@ def test_buildStatTable_name_duplicates(): builder.buildStatTable(font_obj, AXES, windowsNames=True, macNames=False) actual_names = [x.string for x in font_obj["name"].names] + # no new name records were added by buildStatTable + # because windows-only names with the same strings were already present assert expected_names == actual_names + font_obj["name"].removeNames(nameID=270) + expected_names = [x.string for x in font_obj["name"].names] + ['Weight'] + + builder.buildStatTable(font_obj, AXES, windowsNames=True, macNames=False) + actual_names = [x.string for x in font_obj["name"].names] + # One new name records 'Weight' were added by buildStatTable + assert expected_names == actual_names + + builder.buildStatTable(font_obj, AXES, windowsNames=True, macNames=True) + actual_names = [x.string for x in font_obj["name"].names] + expected_names = ['Weight', 'Weight', + 'ExtraLight', 'ExtraLight', + 'Light', 'Light', + 'Regular', 'Regular', + 'Medium', 'Medium', + 'Bold', 'Bold', + 'ExtraBold', 'ExtraBold', + 'Black', 'Black'] + # Multiple name records were added by buildStatTable + assert expected_names == actual_names + + + def test_stat_infinities(): negInf = floatToFixed(builder.AXIS_VALUE_NEGATIVE_INFINITY, 16) diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py index a9a641dd8..268870a6b 100644 --- a/Tests/ttLib/tables/_n_a_m_e_test.py +++ b/Tests/ttLib/tables/_n_a_m_e_test.py @@ -6,6 +6,7 @@ from fontTools.misc.xmlWriter import XMLWriter from io import BytesIO import struct import unittest +from fontTools import ttLib from fontTools.ttLib import newTable from fontTools.ttLib.tables._n_a_m_e import ( table__n_a_m_e, NameRecord, nameRecordFormat, nameRecordSize, makeName, log) @@ -305,6 +306,23 @@ class NameTableTest(unittest.TestCase): self.assertGreaterEqual(nameID, 256) self.assertEqual(nameID, table.findMultilingualName(names, minNameID=256)) + def test_addMultilingualName_no_mac_but_win(self): + ''' + Test if addMultilingualName adds + a Mac name table entry equal to Windows entry. + ''' + + font_obj = ttLib.TTFont() + font_obj["name"] = ttLib.newTable("name") + font_obj["name"].names = [] + + font_obj["name"].setName('Weight', 270, 3, 1, 0x409) + names = {'en': 'Weight', } + nameID = font_obj["name"].addMultilingualName(names, minNameID=256) + + self.assertEqual(270, nameID) + + def test_decompile_badOffset(self): # https://github.com/fonttools/fonttools/issues/525 table = table__n_a_m_e()