@@ -22,140 +22,16 @@ def read_file(path):
2222 return data
2323
2424
25+ # unit tests
26+ # ----------
27+
2528def test_get_args ():
2629 argparse_args = vars (get_args (['dummy' ])) # args through argparse
2730 dummy_args = Defaults ().__dict__ # hard-coded dummy arguments
2831 dummy_args ['input_file' ] = 'dummy'
2932 assert argparse_args == dummy_args
3033
3134
32- def test_full_run ():
33- args = Defaults ()
34- ufo_path = TEST_DIR / 'kern_example.ufo'
35- tmp_feature = TEST_DIR / 'tmp_kern_example.fea'
36- example_feature = read_file (TEST_DIR / 'kern_example.fea' )
37- args .input_file = ufo_path
38- args .output_name = tmp_feature
39- f = defcon .Font (ufo_path )
40- run (f , args )
41- assert read_file (tmp_feature ) == example_feature
42-
43- '''
44- test with --dissolve_single option, which should not make a difference
45- for this UFO (no single-item groups)
46- '''
47- args .dissolve_single = True
48- run (f , args )
49- assert read_file (tmp_feature ) == example_feature
50- tmp_feature .unlink ()
51-
52-
53- def test_main ():
54- '''
55- use main() path into the module
56- '''
57- ufo_path = TEST_DIR / 'kern_example.ufo'
58- kern_example = TEST_DIR / 'kern_example.fea'
59- kern_tmp = TEST_DIR / 'tmp_kern_example.fea'
60- args = Defaults ()
61- args .input_file = ufo_path
62- args .output_name = kern_tmp
63- main ([str (ufo_path ), '--output_name' , str (kern_tmp )])
64- assert read_file (kern_example ) == read_file (kern_tmp )
65- kern_tmp .unlink ()
66-
67-
68- def test_full_run_rtl ():
69- args = Defaults ()
70- ufo_path = TEST_DIR / 'kern_example_rtl.ufo'
71- tmp_feature = TEST_DIR / 'tmp_kern_example_rtl.fea'
72- example_feature = read_file (TEST_DIR / 'kern_example_rtl.fea' )
73- args .input_file = ufo_path
74- args .output_name = tmp_feature
75- f = defcon .Font (ufo_path )
76- run (f , args )
77- assert read_file (tmp_feature ) == example_feature
78- tmp_feature .unlink ()
79-
80-
81- def test_subtable ():
82- '''
83- test writing a file with subtable breaks
84- '''
85- args = Defaults ()
86- ufo_path = TEST_DIR / 'kern_example.ufo'
87- tmp_feature = TEST_DIR / 'tmp_kern_example_subs.fea'
88- example_feature = read_file (TEST_DIR / 'kern_example_subs.fea' )
89- args .input_file = ufo_path
90- args .write_subtables = True
91- args .subtable_size = 128
92- args .output_name = tmp_feature
93- f = defcon .Font (ufo_path )
94- run (f , args )
95- assert read_file (tmp_feature ) == example_feature
96- tmp_feature .unlink ()
97-
98-
99- def test_subtable_rtl ():
100- '''
101- test writing a file with subtable breaks
102- '''
103- args = Defaults ()
104- ufo_path = TEST_DIR / 'kern_example_rtl.ufo'
105- tmp_feature = TEST_DIR / 'tmp_kern_example_rtl_subs.fea'
106- example_feature = read_file (TEST_DIR / 'kern_example_rtl_subs.fea' )
107- args .input_file = ufo_path
108- args .write_subtables = True
109- args .subtable_size = 128
110- args .output_name = tmp_feature
111- f = defcon .Font (ufo_path )
112- run (f , args )
113- assert read_file (tmp_feature ) == example_feature
114- tmp_feature .unlink ()
115-
116-
117- def test_dissolve ():
118- '''
119- test dissolving single-glyph groups
120- '''
121- args = Defaults ()
122- ufo_path = TEST_DIR / 'kern_AV.ufo'
123- tmp_feature_undissolved = TEST_DIR / 'tmp_kern_AV_undissolved.fea'
124- tmp_feature_dissolved = TEST_DIR / 'tmp_kern_AV_dissolved.fea'
125- example_feature_undissolved = read_file (
126- TEST_DIR / 'kern_AV_undissolved.fea' )
127- example_feature_dissolved = read_file (
128- TEST_DIR / 'kern_AV_dissolved.fea' )
129- args .input_file = ufo_path
130- args .output_name = tmp_feature_undissolved
131- f = defcon .Font (ufo_path )
132- run (f , args )
133- assert read_file (tmp_feature_undissolved ) == example_feature_undissolved
134- args .dissolve_single = True
135- args .output_name = tmp_feature_dissolved
136- run (f , args )
137- assert read_file (tmp_feature_dissolved ) == example_feature_dissolved
138- tmp_feature_undissolved .unlink ()
139- tmp_feature_dissolved .unlink ()
140-
141-
142- def test_left_side_exception ():
143- '''
144- test a kerning exception of a single member of a left-side group
145- (Adieresis for the A-group, Oslash for the O-group) to a right-side item.
146- '''
147- args = Defaults ()
148- ufo_path = TEST_DIR / 'kern_left_side_exception.ufo'
149- tmp_feature = TEST_DIR / 'tmp_left_side_exception.fea'
150- example_feature = read_file (TEST_DIR / 'kern_left_side_exception.fea' )
151- args .input_file = ufo_path
152- args .output_name = tmp_feature
153- f = defcon .Font (ufo_path )
154- run (f , args )
155- assert read_file (tmp_feature ) == example_feature
156- tmp_feature .unlink ()
157-
158-
15935def test_make_header ():
16036 kfw = run (None , None )
16137 dummy_args = Dummy ()
@@ -253,6 +129,9 @@ def test_remap_kerning():
253129 assert list (kp ._remap_kerning (f .kerning ).keys ()) == remapped_pairs
254130
255131
132+ # integration tests
133+ # -----------------
134+
256135def test_no_kerning (capsys ):
257136 ufo_path = TEST_DIR / 'kern_example.ufo'
258137 f = defcon .Font (ufo_path )
@@ -272,33 +151,163 @@ def test_all_zero(capsys):
272151 assert f'All kerning values are zero' in out
273152
274153
154+ def test_default ():
155+ '''
156+ normal LTR test with no options
157+ '''
158+ args = Defaults ()
159+ ufo_path = TEST_DIR / 'kern_example.ufo'
160+ fea_temp = TEST_DIR / 'tmp_kern_example.fea'
161+ fea_example = read_file (TEST_DIR / 'kern_example.fea' )
162+ args .input_file = ufo_path
163+ args .output_name = fea_temp
164+ f = defcon .Font (ufo_path )
165+ run (f , args )
166+ assert read_file (fea_temp ) == fea_example
167+
168+ '''
169+ test with --dissolve_single option, which should not make a difference
170+ for this UFO (no single-item groups)
171+ '''
172+ args .dissolve_single = True
173+ run (f , args )
174+ assert read_file (fea_temp ) == fea_example
175+ fea_temp .unlink ()
176+
177+
178+ def test_main ():
179+ '''
180+ same as test_default, using the main() path into the module
181+ '''
182+ ufo_path = TEST_DIR / 'kern_example.ufo'
183+ fea_example = TEST_DIR / 'kern_example.fea'
184+ fea_temp = TEST_DIR / 'tmp_kern_example.fea'
185+ args = Defaults ()
186+ args .input_file = ufo_path
187+ args .output_name = fea_temp
188+ main ([str (ufo_path ), '--output_name' , str (fea_temp )])
189+ assert read_file (fea_example ) == read_file (fea_temp )
190+ fea_temp .unlink ()
191+
192+
193+ def test_default_rtl ():
194+ args = Defaults ()
195+ ufo_path = TEST_DIR / 'kern_example_rtl.ufo'
196+ fea_temp = TEST_DIR / 'tmp_kern_example_rtl.fea'
197+ fea_example = read_file (TEST_DIR / 'kern_example_rtl.fea' )
198+ args .input_file = ufo_path
199+ args .output_name = fea_temp
200+ f = defcon .Font (ufo_path )
201+ run (f , args )
202+ assert read_file (fea_temp ) == fea_example
203+ fea_temp .unlink ()
204+
205+
206+ def test_subtable ():
207+ '''
208+ test writing a file with subtable breaks
209+ '''
210+ args = Defaults ()
211+ ufo_path = TEST_DIR / 'kern_example.ufo'
212+ fea_temp = TEST_DIR / 'tmp_kern_example_subs.fea'
213+ fea_example = read_file (TEST_DIR / 'kern_example_subs.fea' )
214+ args .input_file = ufo_path
215+ args .write_subtables = True
216+ args .subtable_size = 128
217+ args .output_name = fea_temp
218+ f = defcon .Font (ufo_path )
219+ run (f , args )
220+ assert read_file (fea_temp ) == fea_example
221+ fea_temp .unlink ()
222+
223+
224+ def test_subtable_rtl ():
225+ '''
226+ test writing a file with subtable breaks
227+ '''
228+ args = Defaults ()
229+ ufo_path = TEST_DIR / 'kern_example_rtl.ufo'
230+ fea_temp = TEST_DIR / 'tmp_kern_example_rtl_subs.fea'
231+ fea_example = read_file (TEST_DIR / 'kern_example_rtl_subs.fea' )
232+ args .input_file = ufo_path
233+ args .write_subtables = True
234+ args .subtable_size = 128
235+ args .output_name = fea_temp
236+ f = defcon .Font (ufo_path )
237+ run (f , args )
238+ assert read_file (fea_temp ) == fea_example
239+ fea_temp .unlink ()
240+
241+
242+ def test_dissolve ():
243+ '''
244+ test dissolving single-glyph groups
245+ '''
246+ args = Defaults ()
247+ ufo_path = TEST_DIR / 'kern_AV.ufo'
248+ tmp_feature_undissolved = TEST_DIR / 'tmp_kern_AV_undissolved.fea'
249+ tmp_feature_dissolved = TEST_DIR / 'tmp_kern_AV_dissolved.fea'
250+ example_feature_undissolved = read_file (
251+ TEST_DIR / 'kern_AV_undissolved.fea' )
252+ example_feature_dissolved = read_file (
253+ TEST_DIR / 'kern_AV_dissolved.fea' )
254+ args .input_file = ufo_path
255+ args .output_name = tmp_feature_undissolved
256+ f = defcon .Font (ufo_path )
257+ run (f , args )
258+ assert read_file (tmp_feature_undissolved ) == example_feature_undissolved
259+ args .dissolve_single = True
260+ args .output_name = tmp_feature_dissolved
261+ run (f , args )
262+ assert read_file (tmp_feature_dissolved ) == example_feature_dissolved
263+ tmp_feature_undissolved .unlink ()
264+ tmp_feature_dissolved .unlink ()
265+
266+
267+ def test_left_side_exception ():
268+ '''
269+ test a kerning exception of a single member of a left-side group
270+ (Adieresis for the A-group, Oslash for the O-group) to a right-side item.
271+ '''
272+ args = Defaults ()
273+ ufo_path = TEST_DIR / 'kern_left_side_exception.ufo'
274+ fea_temp = TEST_DIR / 'tmp_left_side_exception.fea'
275+ fea_example = read_file (TEST_DIR / 'kern_left_side_exception.fea' )
276+ args .input_file = ufo_path
277+ args .output_name = fea_temp
278+ f = defcon .Font (ufo_path )
279+ run (f , args )
280+ assert read_file (fea_temp ) == fea_example
281+ fea_temp .unlink ()
282+
283+
275284def test_unused_groups ():
276285 ufo_path = TEST_DIR / 'kern_unused_groups.ufo'
277- kern_example = TEST_DIR / 'kern_unused_groups.fea'
278- kern_tmp = TEST_DIR / 'tmp_kern_unused_groups.fea'
286+ fea_example = TEST_DIR / 'kern_unused_groups.fea'
287+ fea_temp = TEST_DIR / 'tmp_kern_unused_groups.fea'
279288 f = defcon .Font (ufo_path )
280289 args = Defaults ()
281290 args .input_file = ufo_path
282- args .output_name = kern_tmp
291+ args .output_name = fea_temp
283292 run (f , args )
284- assert read_file (kern_example ) == read_file (kern_tmp )
285- kern_tmp .unlink ()
293+ assert read_file (fea_example ) == read_file (fea_temp )
294+ fea_temp .unlink ()
286295
287296
288297def test_ignored_groups ():
289298 '''
290299 group/group kern value is 0, all pairs are exceptions
291300 '''
292301 ufo_path = TEST_DIR / 'kern_ignored_groups.ufo'
293- kern_example = TEST_DIR / 'kern_ignored_groups.fea'
294- kern_tmp = TEST_DIR / 'tmp_kern_ignored_groups.fea'
302+ fea_example = TEST_DIR / 'kern_ignored_groups.fea'
303+ fea_temp = TEST_DIR / 'tmp_kern_ignored_groups.fea'
295304 f = defcon .Font (ufo_path )
296305 args = Defaults ()
297306 args .input_file = ufo_path
298- args .output_name = kern_tmp
307+ args .output_name = fea_temp
299308 run (f , args )
300- assert read_file (kern_example ) == read_file (kern_tmp )
301- kern_tmp .unlink ()
309+ assert read_file (fea_example ) == read_file (fea_temp )
310+ fea_temp .unlink ()
302311
303312
304313def test_sanityCheck (capsys ):
@@ -320,47 +329,47 @@ def test_ss4_exceptions():
320329 This contains most exceptions from SS4.
321330 '''
322331 ufo_path = TEST_DIR / 'kern_ss4_exceptions.ufo'
323- kern_example = TEST_DIR / 'kern_ss4_exceptions.fea'
324- kern_tmp = TEST_DIR / 'tmp_kern_ss4_exceptions.fea'
332+ fea_example = TEST_DIR / 'kern_ss4_exceptions.fea'
333+ fea_temp = TEST_DIR / 'tmp_kern_ss4_exceptions.fea'
325334 f = defcon .Font (ufo_path )
326335 args = Defaults ()
327336 args .input_file = ufo_path
328- args .output_name = kern_tmp
337+ args .output_name = fea_temp
329338 run (f , args )
330- assert read_file (kern_example ) == read_file (kern_tmp )
331- kern_tmp .unlink ()
339+ assert read_file (fea_example ) == read_file (fea_temp )
340+ fea_temp .unlink ()
332341
333342
334343def test_mock_rtl ():
335344 '''
336345 A mock RTL project (mirrored version of ss4_exceptions)
337346 '''
338347 ufo_path = TEST_DIR / 'kern_mock_rtl.ufo'
339- kern_example = TEST_DIR / 'kern_mock_rtl.fea'
340- kern_tmp = TEST_DIR / 'tmp_kern_mock_rtl.fea'
348+ fea_example = TEST_DIR / 'kern_mock_rtl.fea'
349+ fea_temp = TEST_DIR / 'tmp_kern_mock_rtl.fea'
341350 f = defcon .Font (ufo_path )
342351 args = Defaults ()
343352 args .input_file = ufo_path
344- args .output_name = kern_tmp
353+ args .output_name = fea_temp
345354 run (f , args )
346- assert read_file (kern_example ) == read_file (kern_tmp )
347- kern_tmp .unlink ()
355+ assert read_file (fea_example ) == read_file (fea_temp )
356+ fea_temp .unlink ()
348357
349358
350359def test_example_trim (capsys ):
351360 ufo_path = TEST_DIR / 'kern_example.ufo'
352- kern_example = TEST_DIR / 'kern_example_trim.fea'
353- kern_tmp = TEST_DIR / 'tmp_kern_example_trim.fea'
361+ fea_example = TEST_DIR / 'kern_example_trim.fea'
362+ fea_temp = TEST_DIR / 'tmp_kern_example_trim.fea'
354363 f = defcon .Font (ufo_path )
355364 args = Defaults ()
356365 args .input_file = ufo_path
357- args .output_name = kern_tmp
366+ args .output_name = fea_temp
358367 args .min_value = 100
359368 args .write_trimmed_pairs = True
360369 run (f , args )
361370
362371 out , err = capsys .readouterr ()
363372 assert 'Trimmed pairs: 33' in out
364373
365- assert read_file (kern_example ) == read_file (kern_tmp )
366- kern_tmp .unlink ()
374+ assert read_file (fea_example ) == read_file (fea_temp )
375+ fea_temp .unlink ()
0 commit comments