Skip to content

Commit a509f36

Browse files
committed
add initial set of unit tests
1 parent 8d4a341 commit a509f36

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

tests/test_size.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
from pathlib import Path
2+
3+
from fontTools.ttLib import TTFont
4+
5+
import pytest
6+
7+
from fontsize.size import FontSize
8+
9+
10+
def get_ttf_fontpath():
11+
return Path("tests/fonts/Inter-Regular.ttf")
12+
13+
14+
def get_otf_fontpath():
15+
return Path("tests/fonts/Inter-Regular.otf")
16+
17+
18+
def get_woff_fontpath():
19+
return Path("tests/fonts/Inter-Regular.woff")
20+
21+
22+
def get_woff2_fontpath():
23+
return Path("tests/fonts/Inter-Regular.woff2")
24+
25+
26+
def test_fontsize_obj_instantiation_with_ttf():
27+
fs = FontSize(get_ttf_fontpath())
28+
assert type(fs.ttfont) is TTFont
29+
assert fs.filepath == get_ttf_fontpath()
30+
assert fs.total_glyphs == 2548
31+
assert fs.encoded_glyphs == 2500
32+
assert fs.total_bytes == 680112
33+
assert fs.per_enc_glyph_bytes == 680112 / 2500
34+
assert fs.per_total_glyph_bytes == 680112 / 2548
35+
assert len(fs.tables) == 17
36+
expected_tables = [
37+
"GDEF",
38+
"GPOS",
39+
"GSUB",
40+
"OS/2",
41+
"cmap",
42+
"cvt ",
43+
"fpgm",
44+
"gasp",
45+
"glyf",
46+
"head",
47+
"hhea",
48+
"hmtx",
49+
"loca",
50+
"maxp",
51+
"name",
52+
"post",
53+
"prep",
54+
]
55+
for table in expected_tables:
56+
assert table in fs.tables
57+
58+
# confirmed with data output from DTL OTM
59+
assert fs.tables["GDEF"] == 1030
60+
assert fs.tables["GPOS"] == 69754
61+
assert fs.tables["GSUB"] == 22092
62+
assert fs.tables["OS/2"] == 96
63+
assert fs.tables["cmap"] == 25916
64+
assert fs.tables["cvt "] == 316
65+
assert fs.tables["fpgm"] == 3605
66+
assert fs.tables["gasp"] == 8
67+
assert fs.tables["glyf"] == 508792
68+
assert fs.tables["head"] == 54
69+
assert fs.tables["hhea"] == 36
70+
assert fs.tables["hmtx"] == 10190
71+
assert fs.tables["loca"] == 10196
72+
assert fs.tables["maxp"] == 32
73+
assert fs.tables["name"] == 1682
74+
assert fs.tables["post"] == 25775
75+
assert fs.tables["prep"] == 239
76+
77+
78+
def test_fontsize_obj_instantiation_with_otf():
79+
fs = FontSize(get_otf_fontpath())
80+
assert type(fs.ttfont) is TTFont
81+
assert fs.filepath == get_otf_fontpath()
82+
assert fs.total_glyphs == 2548
83+
assert fs.encoded_glyphs == 2500
84+
assert fs.total_bytes == 254772
85+
assert fs.per_enc_glyph_bytes == 254772 / 2500
86+
assert fs.per_total_glyph_bytes == 254772 / 2548
87+
assert len(fs.tables) == 12
88+
expected_tables = [
89+
"CFF ",
90+
"GDEF",
91+
"GPOS",
92+
"GSUB",
93+
"OS/2",
94+
"cmap",
95+
"head",
96+
"hhea",
97+
"hmtx",
98+
"maxp",
99+
"name",
100+
"post",
101+
]
102+
for table in expected_tables:
103+
assert table in fs.tables
104+
105+
# confirmed with data from DTL OTM
106+
assert fs.tables["CFF "] == 123697
107+
assert fs.tables["GDEF"] == 1030
108+
assert fs.tables["GPOS"] == 69754
109+
assert fs.tables["GSUB"] == 22092
110+
assert fs.tables["OS/2"] == 96
111+
assert fs.tables["cmap"] == 25916
112+
assert fs.tables["head"] == 54
113+
assert fs.tables["hhea"] == 36
114+
assert fs.tables["hmtx"] == 10190
115+
assert fs.tables["maxp"] == 6
116+
assert fs.tables["name"] == 1650
117+
assert fs.tables["post"] == 32
118+
119+
120+
# TODO: add woff tests
121+
# TODO: add woff2 tests

0 commit comments

Comments
 (0)