-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_models_fontname.py
228 lines (194 loc) · 6.53 KB
/
test_models_fontname.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
from pathlib import Path
from PyQt5.QtWidgets import QTableView
from slice.models import FontNameModel, FontModel
def get_font_model():
return FontModel(Path("tests/assets/fonts/Recursive-VF.subset.ttf").resolve())
def get_font_model_woff():
return FontModel(Path("tests/assets/fonts/Recursive-VF.subset.woff").resolve())
def get_font_model_woff2():
return FontModel(Path("tests/assets/fonts/Recursive-VF.subset.woff2").resolve())
def test_fontname_model_default(qtbot, qtmodeltester):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
# check model with default instantiation
qtmodeltester.check(model)
# confirm that font data loaded appropriately
assert model._v_header == [
"01 Family",
"02 Subfamily",
"03 Unique",
"04 Full",
"06 Postscript",
"16 Typo Family",
"17 Typo Subfamily",
"21 WWS Family",
"22 WWS Subfamily",
]
assert model._data == [
[""], # nameID 1 (index 0)
[""], # nameID 2 (index 1)
[""], # nameID 3 (index 2)
[""], # nameID 4 (index 3)
[""], # nameID 6 (index 4)
[""], # nameID 16 (index 5)
[""], # nameID 17 (index 6)
[""], # nameID 21 (index 7)
[""], # nameID 22 (index 8)
]
def test_fontname_model_filled(qtbot, qtmodeltester):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
model.load_font(get_font_model())
# test with qtmodeltester
qtmodeltester.check(model)
# confirm that font data loaded appropriately
# The vertical headers should not change
assert model._v_header == [
"01 Family",
"02 Subfamily",
"03 Unique",
"04 Full",
"06 Postscript",
"16 Typo Family",
"17 Typo Subfamily",
"21 WWS Family",
"22 WWS Subfamily",
]
# default name table data from test font
assert model._data == [
["Recursive Sans Linear Light"], # nameID 1 (index 0)
["Regular"], # nameID 2 (index 1)
["1.077;ARRW;Recursive-SansLinearLight"], # nameID 3 (index 2)
["Recursive Sans Linear Light"], # nameID 4 (index 3)
["Recursive-SansLinearLight"], # nameID 6 (index 4)
[""], # nameID 16 (index 5)
[""], # nameID 17 (index 6)
[""], # nameID 21 (index 7)
[""], # nameID 22 (index 8)
]
def test_fontname_model_filled_woff(qtbot, qtmodeltester):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
model.load_font(get_font_model_woff())
# test with qtmodeltester
qtmodeltester.check(model)
# confirm that font data loaded appropriately
# The vertical headers should not change
assert model._v_header == [
"01 Family",
"02 Subfamily",
"03 Unique",
"04 Full",
"06 Postscript",
"16 Typo Family",
"17 Typo Subfamily",
"21 WWS Family",
"22 WWS Subfamily",
]
# default name table data from test font
assert model._data == [
["Recursive Sans Linear Light"], # nameID 1 (index 0)
["Regular"], # nameID 2 (index 1)
["1.077;ARRW;Recursive-SansLinearLight"], # nameID 3 (index 2)
["Recursive Sans Linear Light"], # nameID 4 (index 3)
["Recursive-SansLinearLight"], # nameID 6 (index 4)
[""], # nameID 16 (index 5)
[""], # nameID 17 (index 6)
[""], # nameID 21 (index 7)
[""], # nameID 22 (index 8)
]
def test_fontname_model_filled_woff2(qtbot, qtmodeltester):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
model.load_font(get_font_model_woff2())
# test with qtmodeltester
qtmodeltester.check(model)
# confirm that font data loaded appropriately
# The vertical headers should not change
assert model._v_header == [
"01 Family",
"02 Subfamily",
"03 Unique",
"04 Full",
"06 Postscript",
"16 Typo Family",
"17 Typo Subfamily",
"21 WWS Family",
"22 WWS Subfamily",
]
# default name table data from test font
assert model._data == [
["Recursive Sans Linear Light"], # nameID 1 (index 0)
["Regular"], # nameID 2 (index 1)
["1.077;ARRW;Recursive-SansLinearLight"], # nameID 3 (index 2)
["Recursive Sans Linear Light"], # nameID 4 (index 3)
["Recursive-SansLinearLight"], # nameID 6 (index 4)
[""], # nameID 16 (index 5)
[""], # nameID 17 (index 6)
[""], # nameID 21 (index 7)
[""], # nameID 22 (index 8)
]
def test_fontname_model_get_version(qtbot):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
model.load_font(get_font_model())
assert model.get_version() == "Version 1.077"
def test_fontname_model_get_family_name(qtbot):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
model.load_font(get_font_model())
assert model.get_family_name() == "Recursive Sans Linear Light"
def test_fontname_model_get_instance_data(qtbot):
tableview = QTableView()
model = FontNameModel()
tableview.setModel(model)
qtbot.addWidget(tableview)
model.load_font(get_font_model())
assert model.get_instance_data() == {
"nameID1": "Recursive Sans Linear Light",
"nameID2": "Regular",
"nameID3": "1.077;ARRW;Recursive-SansLinearLight",
"nameID4": "Recursive Sans Linear Light",
"nameID6": "Recursive-SansLinearLight",
"nameID16": "",
"nameID17": "",
"nameID21": "",
"nameID22": "",
}
# simulate update of model data with user input
# and check again to confirm that it is present
model._data = [
["One"],
["Two"],
["Three"],
["Four"],
["Six"],
["Sixteen"],
["Seventeen"],
["Twenty-one"],
["Twenty-two"],
]
model.layoutChanged.emit()
assert model.get_instance_data() == {
"nameID1": "One",
"nameID2": "Two",
"nameID3": "Three",
"nameID4": "Four",
"nameID6": "Six",
"nameID16": "Sixteen",
"nameID17": "Seventeen",
"nameID21": "Twenty-one",
"nameID22": "Twenty-two",
}