From af8c461c928a2d110e49c2fbfcbea0ea74c43ede Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 14 Sep 2018 16:51:25 +0200 Subject: [PATCH] varLib_test: add test case for GSUB FeatureVariations --- Tests/varLib/data/FeatureVars.designspace | 71 +++++++ .../varLib/data/test_results/FeatureVars.ttx | 181 ++++++++++++++++++ Tests/varLib/varLib_test.py | 23 ++- 3 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 Tests/varLib/data/FeatureVars.designspace create mode 100644 Tests/varLib/data/test_results/FeatureVars.ttx diff --git a/Tests/varLib/data/FeatureVars.designspace b/Tests/varLib/data/FeatureVars.designspace new file mode 100644 index 000000000..d641ba21a --- /dev/null +++ b/Tests/varLib/data/FeatureVars.designspace @@ -0,0 +1,71 @@ + + + + + + Contrast + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/FeatureVars.ttx b/Tests/varLib/data/test_results/FeatureVars.ttx new file mode 100644 index 000000000..0764bb84e --- /dev/null +++ b/Tests/varLib/data/test_results/FeatureVars.ttx @@ -0,0 +1,181 @@ + + + + + + + + wght + 0x0 + 0.0 + 368.0 + 1000.0 + 256 + + + + + cntr + 0x0 + 0.0 + 0.0 + 100.0 + 257 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/varLib_test.py b/Tests/varLib/varLib_test.py index 05b4ef38f..2bfe0f2d4 100644 --- a/Tests/varLib/varLib_test.py +++ b/Tests/varLib/varLib_test.py @@ -95,7 +95,7 @@ class BuildTest(unittest.TestCase): return font, savepath def _run_varlib_build_test(self, designspace_name, font_name, tables, - expected_ttx_name): + expected_ttx_name, save_before_dump=False): suffix = '.ttf' ds_path = self.get_test_input(designspace_name + '.designspace') ufo_dir = self.get_test_input('master_ufo') @@ -109,6 +109,15 @@ class BuildTest(unittest.TestCase): finder = lambda s: s.replace(ufo_dir, self.tempdir).replace('.ufo', suffix) varfont, model, _ = build(ds_path, finder) + if save_before_dump: + # some data (e.g. counts printed in TTX inline comments) is only + # calculated at compile time, so before we can compare the TTX + # dumps we need to save to a temporary stream, and realod the font + buf = BytesIO() + varfont.save(buf) + buf.seek(0) + varfont = TTFont(buf) + expected_ttx_path = self.get_test_output(expected_ttx_name + '.ttx') self.expect_ttx(varfont, expected_ttx_path, tables) self.check_ttx_dump(varfont, expected_ttx_path, tables, suffix) @@ -183,6 +192,18 @@ class BuildTest(unittest.TestCase): expected_ttx_name=test_name ) + def test_varlib_build_feature_variations(self): + """Designspace file contains element, used to build + GSUB FeatureVariations table. + """ + self._run_varlib_build_test( + designspace_name="FeatureVars", + font_name="TestFamily", + tables=["fvar", "GSUB"], + expected_ttx_name="FeatureVars", + save_before_dump=True, + ) + def test_varlib_main_ttf(self): """Mostly for testing varLib.main() """