Skip to content

Commit 426174f

Browse files
committed
new tests for percent sub command for otf and ttf files
1 parent 7439eb8 commit 426174f

File tree

7 files changed

+127
-5
lines changed

7 files changed

+127
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## font-line [![Build Status](https://travis-ci.org/source-foundry/font-line.svg?branch=master)](https://travis-ci.org/source-foundry/font-line) [![Build status](https://ci.appveyor.com/api/projects/status/2s4725o5mxh2298c/branch/master?svg=true)](https://ci.appveyor.com/project/chrissimpkins/font-line/branch/master)
1+
## font-line [![Build Status](https://travis-ci.org/source-foundry/font-line.svg?branch=master)](https://travis-ci.org/source-foundry/font-line) [![Build status](https://ci.appveyor.com/api/projects/status/2s4725o5mxh2298c/branch/master?svg=true)](https://ci.appveyor.com/project/chrissimpkins/font-line/branch/master) [![codecov.io](https://codecov.io/github/source-foundry/font-line/coverage.svg?branch=master)](https://codecov.io/github/source-foundry/font-line?branch=master)
22

33

44
### About

coverage.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ coverage run --source fontline -m py.test
44
coverage report -m
55
coverage html
66

7-
#coverage xml
8-
#codecov --token=$CODECOV_{{fontline}}
7+
coverage xml
8+
codecov --token=$CODECOV_FONTLINE

tests/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from fontline.commands import get_linegap_percent_filepath
88

99

10-
def test_commands_function_getlg_percent_filepath():
10+
def test_commands_module_function_getlg_percent_filepath():
1111
response = get_linegap_percent_filepath("Test.ttf", "20")
1212
assert response == "Test-linegap20.ttf"
1313

tests/test_percent_cmd.py

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,33 @@
55
import pytest
66
import os.path
77
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+
831

932
# ///////////////////////////////////////////////////////
1033
#
11-
# report sub-command tests
34+
# percent sub-command command line logic tests
1235
#
1336
# ///////////////////////////////////////////////////////
1437

@@ -72,3 +95,101 @@ def test_percent_cmd_font_file_wrong_filetype(capsys):
7295
main()
7396
out, err = capsys.readouterr()
7497
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
157 KB
Binary file not shown.
390 KB
Binary file not shown.

tests/testingfiles/backup/bogus.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a file for testing.

0 commit comments

Comments
 (0)