forked from adobe-type-tools/afdko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildcff2vf_test.py
178 lines (153 loc) · 6.58 KB
/
buildcff2vf_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import os
from shutil import copytree
import pytest
import subprocess
from afdko.fdkutils import get_temp_dir_path
from test_utils import (
get_input_path,
get_expected_path,
generate_ttx_dump,
)
from runner import main as runner
from differ import main as differ
TOOL = 'buildcff2vf'
CMD = ['-t', TOOL]
# -----
# Tests
# -----
def test_rvrn_vf():
input_dir = get_input_path('GSUBVar')
temp_dir = get_temp_dir_path('GSUBVar')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'GSUBVar.designspace')
runner(CMD + ['-o', 'd', f'_{ds_path}'])
actual_path = os.path.join(temp_dir, 'GSUBVar.otf')
actual_ttx = generate_ttx_dump(actual_path,
['CFF2', 'GSUB', 'avar', 'fvar'])
expected_ttx = get_expected_path('GSUBVar.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_cjk_vf():
input_dir = get_input_path('CJKVar')
temp_dir = get_temp_dir_path('CJKVar')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'CJKVar.designspace')
runner(CMD + ['-o', 'd', f'_{ds_path}'])
actual_path = os.path.join(temp_dir, 'CJKVar.otf')
actual_ttx = generate_ttx_dump(actual_path,
['CFF2', 'HVAR', 'avar', 'fvar'])
expected_ttx = get_expected_path('CJKVar.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_sparse_cjk_vf():
# subset fonts to lists in 'SHSansJPVFTest.subset.txt'
# Check compatibility. Issue is in cid00089.
# keep PostScript names
input_dir = get_input_path('CJKSparseVar')
temp_dir = get_temp_dir_path('CJKSparseVar')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'SHSansJPVFTest.designspace')
subset_path = os.path.join(temp_dir, 'SHSansJPVFTest.subset.txt')
runner(CMD + ['-o', 'd', f'_{ds_path}', 'i', f'_{subset_path}', 'c', 'k'])
actual_path = os.path.join(temp_dir, 'SHSansJPVFTest.otf')
actual_ttx = generate_ttx_dump(actual_path,
['CFF2', 'HVAR', 'avar', 'fvar'])
expected_ttx = get_expected_path('SHSansJPVFTest.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_compatibility_vf():
input_dir = get_input_path('bug816')
temp_dir = get_temp_dir_path('bug816var')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'bug816.designspace')
runner(CMD + ['-o', 'c', 'd', f'_{ds_path}'])
actual_path = os.path.join(temp_dir, 'bug816.otf')
actual_ttx = generate_ttx_dump(actual_path, ['CFF2'])
expected_ttx = get_expected_path('bug816.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_subset_vf():
input_dir = get_input_path('bug817')
temp_dir = get_temp_dir_path('bug817var')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'bug817.designspace')
subset_path = os.path.join(temp_dir, 'bug817.subset')
runner(CMD + ['-o', 'd', f'_{ds_path}', 'i', f'_{subset_path}'])
actual_path = os.path.join(temp_dir, 'bug817.otf')
actual_ttx = generate_ttx_dump(actual_path, ['GSUB'])
expected_ttx = get_expected_path('bug817.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_bug1003(capfd):
"""
Check that "the input set requires compatibilization" message is in
stderr when run without '-c' option.
"""
input_dir = get_input_path('bug1003')
temp_dir = get_temp_dir_path('bug1003var')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'bug1003.designspace')
runner(CMD + ['-o', 'd', f'_{ds_path}'])
captured = capfd.readouterr()
assert "The input set requires compatibilization" in captured.err
def test_bug1003_compat():
"""
Check that file is properly built when '-c' is specified.
"""
input_dir = get_input_path('bug1003')
temp_dir = get_temp_dir_path('bug1003cvar')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir, 'bug1003.designspace')
runner(CMD + ['-o', 'c' 'd', f'_{ds_path}'])
actual_path = os.path.join(temp_dir, 'bug1003.otf')
actual_ttx = generate_ttx_dump(actual_path, ['CFF2'])
expected_ttx = get_expected_path('bug1003.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_stat_axis_not_in_fvar():
"""
Fail if fvar axes are missing from STAT
"""
input_dir = get_input_path('STAT_tests')
temp_dir = get_temp_dir_path('STAT_tests')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir,
'STAT_axis_missing/STAT_axis_missing.designspace')
with pytest.raises(subprocess.CalledProcessError):
runner(CMD + ['-o', 'd', f'_{ds_path}'])
def test_stat_axis_values_range():
"""
Fail if STAT axis values are outside range defined in fvar
"""
input_dir = get_input_path('STAT_tests')
temp_dir = get_temp_dir_path('STAT_tests')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir,
'STAT_axis_ranges/STAT_axis_ranges.designspace')
with pytest.raises(subprocess.CalledProcessError):
runner(CMD + ['-o', 'd', f'_{ds_path}'])
def test_stat_axis_in_fvar():
"""
Basic check that fvar axes are defined in STAT
"""
input_dir = get_input_path('STAT_tests')
temp_dir = get_temp_dir_path('STAT_tests')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir,
'STAT_axis_in_fvar/STAT_axis_in_fvar.designspace')
runner(CMD + ['-o', 'd', f'_{ds_path}'])
actual_path = os.path.join(temp_dir,
'STAT_axis_in_fvar/STAT_axis_in_fvar.otf')
actual_ttx = generate_ttx_dump(actual_path, ['STAT'])
expected_ttx = get_expected_path('STAT_in_fvar.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_stat_infinite_range():
"""
Check that range tests work when infinite ranges are defined
"""
input_dir = get_input_path('STAT_tests')
temp_dir = get_temp_dir_path('STAT_tests')
copytree(input_dir, temp_dir)
ds_path = os.path.join(temp_dir,
'STAT_infinite_range/'
'STAT_infinite_range.designspace')
runner(CMD + ['-o', 'd', f'_{ds_path}'])
actual_path = os.path.join(temp_dir,
'STAT_infinite_range/STAT_infinite_range.otf')
actual_ttx = generate_ttx_dump(actual_path, ['STAT'])
expected_ttx = get_expected_path('STAT_infinite_range.ttx')
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])