From 274654d4407729910105792a6c5ba740ab6885dc Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Sun, 5 Mar 2017 13:44:32 -0800 Subject: [PATCH] [varLib tests] Move test results to separate folder --- .../varLib/data/{ => test_results}/Build.ttx | 0 .../{ => test_results}/InterpolateLayout.ttx | 0 .../data/{ => test_results}/Mutator.ttx | 0 Tests/varLib/interpolate_layout_test.py | 7 ++++++- Tests/varLib/mutator_test.py | 10 +++++++-- Tests/varLib/varLib_test.py | 21 ++++++++++++------- 6 files changed, 28 insertions(+), 10 deletions(-) rename Tests/varLib/data/{ => test_results}/Build.ttx (100%) rename Tests/varLib/data/{ => test_results}/InterpolateLayout.ttx (100%) rename Tests/varLib/data/{ => test_results}/Mutator.ttx (100%) diff --git a/Tests/varLib/data/Build.ttx b/Tests/varLib/data/test_results/Build.ttx similarity index 100% rename from Tests/varLib/data/Build.ttx rename to Tests/varLib/data/test_results/Build.ttx diff --git a/Tests/varLib/data/InterpolateLayout.ttx b/Tests/varLib/data/test_results/InterpolateLayout.ttx similarity index 100% rename from Tests/varLib/data/InterpolateLayout.ttx rename to Tests/varLib/data/test_results/InterpolateLayout.ttx diff --git a/Tests/varLib/data/Mutator.ttx b/Tests/varLib/data/test_results/Mutator.ttx similarity index 100% rename from Tests/varLib/data/Mutator.ttx rename to Tests/varLib/data/test_results/Mutator.ttx diff --git a/Tests/varLib/interpolate_layout_test.py b/Tests/varLib/interpolate_layout_test.py index a54094e72..e1351f7a6 100644 --- a/Tests/varLib/interpolate_layout_test.py +++ b/Tests/varLib/interpolate_layout_test.py @@ -31,6 +31,11 @@ class InterpolateLayoutTest(unittest.TestCase): path, _ = os.path.split(__file__) return os.path.join(path, "data", test_file_or_folder) + @staticmethod + def get_test_output(test_file_or_folder): + path, _ = os.path.split(__file__) + return os.path.join(path, "data", "test_results", test_file_or_folder) + @staticmethod def get_file_list(folder, suffix): all_files = os.listdir(folder) @@ -108,7 +113,7 @@ class InterpolateLayoutTest(unittest.TestCase): instfont = interpolate_layout(ds_path, {'weight': 500}, finder) tables = ['GSUB'] - expected_ttx_path = ds_path.replace('.designspace', '.ttx') + expected_ttx_path = self.get_test_output('InterpolateLayout.ttx') self.expect_ttx(instfont, expected_ttx_path, tables) self.check_ttx_dump(instfont, expected_ttx_path, tables, suffix) diff --git a/Tests/varLib/mutator_test.py b/Tests/varLib/mutator_test.py index 7ee916547..efebf710c 100644 --- a/Tests/varLib/mutator_test.py +++ b/Tests/varLib/mutator_test.py @@ -32,6 +32,11 @@ class MutatorTest(unittest.TestCase): path, _ = os.path.split(__file__) return os.path.join(path, "data", test_file_or_folder) + @staticmethod + def get_test_output(test_file_or_folder): + path, _ = os.path.split(__file__) + return os.path.join(path, "data", "test_results", test_file_or_folder) + @staticmethod def get_file_list(folder, suffix): all_files = os.listdir(folder) @@ -96,7 +101,8 @@ class MutatorTest(unittest.TestCase): finder = lambda s: s.replace(ufo_dir, self.tempdir).replace('.ufo', suffix) varfont, _, _ = build(ds_path, finder) - varfont_path = os.path.join(self.tempdir, 'Mutator' + suffix) + varfont_name = 'Mutator' + varfont_path = os.path.join(self.tempdir, varfont_name + suffix) varfont.save(varfont_path) args = [varfont_path, 'wght=500', 'cntr=50'] @@ -105,7 +111,7 @@ class MutatorTest(unittest.TestCase): instfont_path = os.path.splitext(varfont_path)[0] + '-instance' + suffix instfont = TTFont(instfont_path) tables = [table_tag for table_tag in instfont.keys() if table_tag != 'head'] - expected_ttx = self.get_test_input('Mutator.ttx') + expected_ttx = self.get_test_output(varfont_name + '.ttx') self.expect_ttx(instfont, expected_ttx, tables) diff --git a/Tests/varLib/varLib_test.py b/Tests/varLib/varLib_test.py index 1e531b46d..592d680b6 100644 --- a/Tests/varLib/varLib_test.py +++ b/Tests/varLib/varLib_test.py @@ -31,6 +31,11 @@ class BuildTest(unittest.TestCase): path, _ = os.path.split(__file__) return os.path.join(path, "data", test_file_or_folder) + @staticmethod + def get_test_output(test_file_or_folder): + path, _ = os.path.split(__file__) + return os.path.join(path, "data", "test_results", test_file_or_folder) + @staticmethod def get_file_list(folder, suffix): all_files = os.listdir(folder) @@ -70,6 +75,12 @@ class BuildTest(unittest.TestCase): sys.stdout.write(line) self.fail("TTX output is different from expected") + def check_ttx_dump(self, font, expected_ttx, tables, suffix): + """Ensure the TTX dump is the same after saving and reloading the font.""" + path = self.temp_path(suffix=suffix) + font.save(path) + self.expect_ttx(TTFont(path), expected_ttx, tables) + def compile_font(self, path, suffix, temp_dir): ttx_filename = os.path.basename(path) savepath = os.path.join(temp_dir, ttx_filename.replace('.ttx', suffix)) @@ -97,13 +108,9 @@ class BuildTest(unittest.TestCase): varfont, model, _ = build(ds_path, finder) tables = ['GDEF', 'HVAR', 'fvar', 'gvar'] - expected_ttx = self.get_test_input('Build.ttx') - self.expect_ttx(varfont, expected_ttx, tables) - - # ensure the TTX dump is the same after saving and reloading font - varfont_path = os.path.join(self.tempdir, 'Build.ttf') - varfont.save(varfont_path) - self.expect_ttx(TTFont(varfont_path), expected_ttx, tables) + expected_ttx_path = self.get_test_output('Build.ttx') + self.expect_ttx(varfont, expected_ttx_path, tables) + self.check_ttx_dump(varfont, expected_ttx_path, tables, suffix) if __name__ == "__main__":