5
5
import pytest
6
6
import os .path
7
7
import os
8
+ import shutil
9
+ from fontTools import ttLib
10
+
11
+ from fontline .utilities import file_exists
12
+
13
+ # ///////////////////////////////////////////////////////
14
+ #
15
+ # utility functions for module tests
16
+ #
17
+ # ///////////////////////////////////////////////////////
18
+
19
+
20
+ def create_test_file (filepath ):
21
+ filepath_list = filepath .split ("." )
22
+ testpath = filepath_list [0 ] + "-test." + filepath_list [1 ]
23
+ shutil .copyfile (filepath , testpath )
24
+ return True
25
+
26
+
27
+ def erase_test_file (filepath ):
28
+ os .remove (filepath )
29
+ return True
30
+
8
31
9
32
# ///////////////////////////////////////////////////////
10
33
#
11
- # report sub-command tests
34
+ # percent sub-command command line logic tests
12
35
#
13
36
# ///////////////////////////////////////////////////////
14
37
@@ -72,3 +95,101 @@ def test_percent_cmd_font_file_wrong_filetype(capsys):
72
95
main ()
73
96
out , err = capsys .readouterr ()
74
97
assert ("does not appear to be a supported font file type." in err ) is True
98
+
99
+
100
+ # ///////////////////////////////////////////////////////
101
+ #
102
+ # percent sub-command command functionality tests
103
+ #
104
+ # ///////////////////////////////////////////////////////
105
+
106
+ def test_percent_cmd_ttf_file_10_percent (capsys ):
107
+ try :
108
+ from fontline .app import main
109
+ fontpath = os .path .join ('tests' , 'testingfiles' , 'Hack-Regular.ttf' )
110
+ testpath = os .path .join ('tests' , 'testingfiles' , 'Hack-Regular-test.ttf' )
111
+ newfont_path = os .path .join ('tests' , 'testingfiles' , 'Hack-Regular-test-linegap10.ttf' )
112
+ create_test_file (fontpath )
113
+ assert file_exists (testpath ) is True
114
+ sys .argv = ['font-line' , 'percent' , '10' , testpath ]
115
+ main ()
116
+
117
+ assert file_exists (newfont_path )
118
+
119
+ tt = ttLib .TTFont (newfont_path )
120
+
121
+ os2_typo_ascender = tt ['OS/2' ].__dict__ ['sTypoAscender' ]
122
+ os2_typo_descender = tt ['OS/2' ].__dict__ ['sTypoDescender' ]
123
+ os2_win_ascent = tt ['OS/2' ].__dict__ ['usWinAscent' ]
124
+ os2_win_descent = tt ['OS/2' ].__dict__ ['usWinDescent' ]
125
+ os2_typo_linegap = tt ['OS/2' ].__dict__ ['sTypoLineGap' ]
126
+ hhea_ascent = tt ['hhea' ].__dict__ ['ascent' ]
127
+ hhea_descent = tt ['hhea' ].__dict__ ['descent' ]
128
+ hhea_linegap = tt ['hhea' ].__dict__ ['lineGap' ]
129
+ units_per_em = tt ['head' ].__dict__ ['unitsPerEm' ]
130
+
131
+ assert os2_typo_ascender == 1556
132
+ assert os2_typo_descender == - 492
133
+ assert os2_win_ascent == 1658
134
+ assert os2_win_descent == 594
135
+ assert units_per_em == 2048
136
+ assert os2_typo_linegap == 204
137
+ assert hhea_ascent == 1658
138
+ assert hhea_descent == - 594
139
+ assert hhea_linegap == 0
140
+
141
+ erase_test_file (testpath )
142
+ erase_test_file (newfont_path )
143
+ except Exception as e :
144
+ # cleanup test files
145
+ if file_exists (testpath ):
146
+ erase_test_file (testpath )
147
+ if file_exists (newfont_path ):
148
+ erase_test_file (newfont_path )
149
+ raise e
150
+
151
+
152
+ def test_percent_cmd_otf_file_10_percent (capsys ):
153
+ try :
154
+ from fontline .app import main
155
+ fontpath = os .path .join ('tests' , 'testingfiles' , 'Hack-Regular.otf' )
156
+ testpath = os .path .join ('tests' , 'testingfiles' , 'Hack-Regular-test.otf' )
157
+ newfont_path = os .path .join ('tests' , 'testingfiles' , 'Hack-Regular-test-linegap10.otf' )
158
+ create_test_file (fontpath )
159
+ assert file_exists (testpath ) is True
160
+ sys .argv = ['font-line' , 'percent' , '10' , testpath ]
161
+ main ()
162
+
163
+ assert file_exists (newfont_path )
164
+
165
+ tt = ttLib .TTFont (newfont_path )
166
+
167
+ os2_typo_ascender = tt ['OS/2' ].__dict__ ['sTypoAscender' ]
168
+ os2_typo_descender = tt ['OS/2' ].__dict__ ['sTypoDescender' ]
169
+ os2_win_ascent = tt ['OS/2' ].__dict__ ['usWinAscent' ]
170
+ os2_win_descent = tt ['OS/2' ].__dict__ ['usWinDescent' ]
171
+ os2_typo_linegap = tt ['OS/2' ].__dict__ ['sTypoLineGap' ]
172
+ hhea_ascent = tt ['hhea' ].__dict__ ['ascent' ]
173
+ hhea_descent = tt ['hhea' ].__dict__ ['descent' ]
174
+ hhea_linegap = tt ['hhea' ].__dict__ ['lineGap' ]
175
+ units_per_em = tt ['head' ].__dict__ ['unitsPerEm' ]
176
+
177
+ assert os2_typo_ascender == 1556
178
+ assert os2_typo_descender == - 492
179
+ assert os2_win_ascent == 1658
180
+ assert os2_win_descent == 594
181
+ assert units_per_em == 2048
182
+ assert os2_typo_linegap == 204
183
+ assert hhea_ascent == 1658
184
+ assert hhea_descent == - 594
185
+ assert hhea_linegap == 0
186
+
187
+ erase_test_file (testpath )
188
+ erase_test_file (newfont_path )
189
+ except Exception as e :
190
+ # cleanup test files
191
+ if file_exists (testpath ):
192
+ erase_test_file (testpath )
193
+ if file_exists (newfont_path ):
194
+ erase_test_file (newfont_path )
195
+ raise e
0 commit comments