Skip to content

Commit

Permalink
[tx_test.py] Parametrized 4 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaydeearts committed May 4, 2021
1 parent a7f3917 commit 797c664
Showing 1 changed file with 31 additions and 53 deletions.
84 changes: 31 additions & 53 deletions tests/tx_test.py
Expand Up @@ -1103,61 +1103,40 @@ def test_cffread_bug1343():
assert differ([expected_path, actual_path, '-s', '## Filename'])


def test_roundtrip_cid_ufo():
@pytest.mark.parametrize('arg, input, output, expected', [
('ufo', 'cidfont.subset', 'cidfont_subset.ufo', 'testCID.ufo'),
('t1', 'testCID.ufo', 'cidfont_subset.ufo', 'cidfont.subset'),
(('ufo', 't1'), 'cidfont.subset', 'cidfont_subset.ufo', 'cidfont.subset'),
(('t1', 'ufo'), 'testCID.ufo', 'cidfont_subset.ufo', 'testCID.ufo'),
])
def test_cidkeyed_read_write(arg, input, output, expected):
"""
Tests reading & writing CID-Keyed fonts in tx (uforead & ufowrite)
CID -> UFO (one-way test)
UFO -> CID (one-way test)
CID -> UFO -> CID (round-trip test)
UFO -> CID -> UFO (round-trip test)
"""
folder = "cid_roundtrip/"
cid_input_path = get_input_path(folder + "cidfont.subset")
ufo_expected_path = get_expected_path(folder + 'testCID.ufo')
input_path = get_input_path(folder + input)
output_dir = get_temp_dir_path()
ufo_output_path = os.path.join(output_dir, "cidfont_subset.ufo")
runner(CMD + ['-a', '-o', 'ufo', '-f',
cid_input_path, ufo_output_path])
assert differ([ufo_expected_path, ufo_output_path])


def test_roundtrip_ufo_cid():
folder = "cid_roundtrip/"
ufo_input_path = get_input_path(folder + 'testCID.ufo')
cid_expected_path = get_expected_path(folder + 'cidfont.subset')
cid_actual_path = get_temp_file_path()
runner(CMD + ['-a', '-o', 't1', 'n', '-f',
ufo_input_path, cid_actual_path])
cid_new_expected_path = generate_ps_dump(cid_expected_path)
output_path = generate_ps_dump(cid_actual_path)
assert differ([cid_new_expected_path, output_path])

output_path = os.path.join(output_dir, output)
expected_path = get_expected_path(folder + expected)
if isinstance(arg, tuple): # round-trip tests
runner(CMD + ['-a', '-o', 't1', 'n', '-f',
input_path, output_path])
final_output_dir = get_temp_dir_path()
final_output_path = os.path.join(final_output_dir, output)
runner(CMD + ['-a', '-o', arg[1], '-f',
output_path, final_output_path])
output_path = final_output_path
else: # one-way tests
runner(CMD + ['-a', '-o', arg, '-f', input_path, output_path])
if '.subset' in expected_path:
expected_path = generate_ps_dump(expected_path)
output_path = generate_ps_dump(output_path)
assert differ([expected_path, output_path])

def test_roundtrip_cid_ufo_cid():
folder = "cid_roundtrip/"
cid_input_path = get_input_path(folder + "cidfont.subset")
cid_expected_path = get_expected_path(folder + 'cidfont.subset')
output_dir = get_temp_dir_path()
ufo_output_path = os.path.join(output_dir, "cidfont_subset.ufo")
# cid -> ufo
runner(CMD + ['-a', '-o', 'ufo', '-f',
cid_input_path, ufo_output_path])
# ufo -> cid
cid_actual_path = get_temp_file_path()
runner(CMD + ['-a', '-o', 't1', 'n', '-f',
ufo_output_path, cid_actual_path])
cid_new_expected_path = generate_ps_dump(cid_expected_path)
cid_output_path = generate_ps_dump(cid_actual_path)
assert differ([cid_new_expected_path, cid_output_path])


def test_roundtrip_ufo_cid_ufo():
folder = "cid_roundtrip/"
ufo_input_path = get_input_path(folder + 'testCID.ufo')
ufo_expected_path = get_expected_path(folder + 'testCID.ufo')
# ufo -> cid
cid_actual_path = get_temp_file_path()
runner(CMD + ['-a', '-o', 't1', 'n', '-f',
ufo_input_path, cid_actual_path])
output_dir = get_temp_dir_path()
ufo_output_path = os.path.join(output_dir, "cidfont_subset.ufo")
# cid -> ufo
runner(CMD + ['-a', '-o', 'ufo', '-f',
cid_actual_path, ufo_output_path])
assert differ([ufo_expected_path, ufo_output_path])

@pytest.mark.parametrize("file", [
"missing_CID.ufo",
Expand All @@ -1168,4 +1147,3 @@ def test_cidkeyed_lib_missing(file):
ufo_input_path = get_input_path(folder + file)
arg = [TOOL, '-t1', '-f', ufo_input_path]
assert subprocess.call(arg) == 6

0 comments on commit 797c664

Please sign in to comment.