Merge pull request #874 from miguelsousa/reorg-tests

Reorganize test data
This commit is contained in:
Cosimo Lupo 2017-03-05 23:16:01 +00:00 committed by GitHub
commit 35338369cf
11 changed files with 33 additions and 15 deletions

View File

@ -9,7 +9,7 @@ class DesignspaceTest(unittest.TestCase):
def test_load(self):
self.maxDiff = None
self.assertEqual(
designspace.load(_getpath("DesignspaceTest.designspace")),
designspace.load(_getpath("Designspace.designspace")),
{'sources':
[{'location': {'weight': 0.0},
@ -55,7 +55,7 @@ class DesignspaceTest(unittest.TestCase):
def test_load2(self):
self.assertEqual(
designspace.load(_getpath("DesignspaceTest2.designspace")),
designspace.load(_getpath("Designspace2.designspace")),
{'sources': [], 'instances': [{}]})

View File

@ -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)
@ -95,7 +100,7 @@ class InterpolateLayoutTest(unittest.TestCase):
base master.
"""
suffix = '.ttf'
ds_path = self.get_test_input('InterpolateLayoutTest.designspace')
ds_path = self.get_test_input('InterpolateLayout.designspace')
ufo_dir = self.get_test_input('master_ufo')
ttx_dir = self.get_test_input('master_ttx_interpolatable_ttf')
@ -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)

View File

@ -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)
@ -85,7 +90,7 @@ class MutatorTest(unittest.TestCase):
def test_varlib_mutator_ttf(self):
suffix = '.ttf'
ds_path = self.get_test_input('BuildTest.designspace')
ds_path = self.get_test_input('Build.designspace')
ufo_dir = self.get_test_input('master_ufo')
ttx_dir = self.get_test_input('master_ttx_interpolatable_ttf')
@ -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, 'MutatorTest' + 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('MutatorTest.ttx')
expected_ttx = self.get_test_output(varfont_name + '.ttx')
self.expect_ttx(instfont, expected_ttx, tables)

View File

@ -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))
@ -84,7 +95,7 @@ class BuildTest(unittest.TestCase):
def test_varlib_build_ttf(self):
suffix = '.ttf'
ds_path = self.get_test_input('BuildTest.designspace')
ds_path = self.get_test_input('Build.designspace')
ufo_dir = self.get_test_input('master_ufo')
ttx_dir = self.get_test_input('master_ttx_interpolatable_ttf')
@ -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('BuildTest.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, 'BuildTest.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__":