forked from scribe-org/Scribe-Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_update_utils.py
274 lines (221 loc) · 7.33 KB
/
test_update_utils.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
"""
Tests for the update_utils file functions.
.. raw:: html
<!--
* Copyright (C) 2024 Scribe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
"""
import sys
import unittest
from pathlib import Path
import pytest
sys.path.append(Path(__file__).parent.parent.parent)
from scribe_data import utils
def test_get_scribe_languages():
test_case = unittest.TestCase()
# test for content, not order
test_case.assertCountEqual(
utils.get_scribe_languages(),
[
"English",
"French",
"German",
"Italian",
"Portuguese",
"Russian",
"Spanish",
"Swedish",
],
)
@pytest.mark.parametrize(
"language, qid_code",
[
("English", "Q1860"),
("french", "Q150"),
("GERMAN", "Q188"),
("iTalian", "Q652"),
("poRTUGuese", "Q5146"),
("russian", "Q7737"),
("spanish", "Q1321"),
("swedish", "Q9027"),
],
)
def test_get_language_qid_positive(language, qid_code):
assert utils.get_language_qid(language) == qid_code
def test_get_language_qid_negative():
with pytest.raises(ValueError) as excp:
_ = utils.get_language_qid("Newspeak")
assert (
str(excp.value)
== "NEWSPEAK is currently not a supported language for QID conversion."
)
@pytest.mark.parametrize(
"language, iso_code",
[
("English", "en"),
("french", "fr"),
("GERMAN", "de"),
("iTalian", "it"),
("poRTUGuese", "pt"),
("russian", "ru"),
("spanish", "es"),
("SwedisH", "sv"),
],
)
def test_get_language_iso_positive(language, iso_code):
assert utils.get_language_iso(language) == iso_code
def test_get_language_iso_negative():
with pytest.raises(ValueError) as excp:
_ = utils.get_language_iso("gibberish")
assert (
str(excp.value)
== "Gibberish is currently not a supported language for ISO conversion."
)
@pytest.mark.parametrize(
"iso_code, language",
[
("en", "English"),
("fr", "French"),
("de", "German"),
("it", "Italian"),
("pt", "Portuguese"),
("ru", "Russian"),
("es", "Spanish"),
("sv", "Swedish"),
],
)
def test_get_language_from_iso_positive(iso_code, language):
assert utils.get_language_from_iso(iso_code) == language
def test_get_language_from_iso_negative():
with pytest.raises(ValueError) as excp:
_ = utils.get_language_from_iso("ixi")
assert str(excp.value) == "IXI is currently not a supported ISO language."
@pytest.mark.parametrize(
"language, remove_words",
[
(
"english",
[
"of",
"the",
"The",
"and",
],
),
(
"french",
[
"of",
"the",
"The",
"and",
],
),
("german", ["of", "the", "The", "and", "NeinJa", "et", "redirect"]),
("italian", ["of", "the", "The", "and", "text", "from"]),
("portuguese", ["of", "the", "The", "and", "jbutadptflora"]),
(
"russian",
[
"of",
"the",
"The",
"and",
],
),
("spanish", ["of", "the", "The", "and"]),
("swedish", ["of", "the", "The", "and", "Checklist", "Catalogue"]),
],
)
def test_get_language_words_to_remove(language, remove_words):
test_case = unittest.TestCase()
# ignore order, only content matters
test_case.assertCountEqual(
utils.get_language_words_to_remove(language), remove_words
)
def test_get_language_words_to_remove_negative():
with pytest.raises(ValueError) as excp:
_ = utils.get_language_words_to_remove("python")
assert str(excp.value) == "Python is currently not a supported language."
@pytest.mark.parametrize(
"language, ignore_words",
[
(
"french",
[
"XXe",
],
),
("german", ["Gemeinde", "Familienname"]),
("italian", ["The", "ATP"]),
("portuguese", []),
("russian", []),
("spanish", []),
("swedish", ["databasdump"]),
],
)
def test_get_language_words_to_ignore(language, ignore_words):
test_case = unittest.TestCase()
# ignore order, only content matters
test_case.assertCountEqual(
utils.get_language_words_to_ignore(language), ignore_words
)
def test_get_language_words_to_ignore_negative():
with pytest.raises(ValueError) as excp:
_ = utils.get_language_words_to_ignore("JAVA")
assert str(excp.value) == "Java is currently not a supported language."
def test_get_ios_data_path():
assert (
utils.get_ios_data_path("suomi")
== Path("Scribe-iOS") / "Keyboards" / "LanguageKeyboards" / "suomi"
)
@pytest.mark.parametrize(
"passed_values, values_to_check, expected",
[
("['1', '2', '3']", ["1", "2", "3"], ["1", "2", "3"]),
("['1', '3', '2']", ["1", "2", "3"], ["1", "3", "2"]),
("['1', '2']", ["1", "2", "3"], ["1", "2"]),
("['abc']", ["def", "abc", "ghi"], ["abc"]),
("[]", ["1", "2", "3"], []),
],
)
def test_check_command_line_args_positive(passed_values, values_to_check, expected):
assert (
utils.check_command_line_args("pass.txt", passed_values, values_to_check)
== expected
)
def test_check_command_line_args_fail_not_subset():
with pytest.raises(ValueError):
_ = utils.check_command_line_args("Fail.txt", "['1', '2', '3']", ["1", "2"])
def test_check_command_line_args_passed_values_not_list():
with pytest.raises(ValueError):
_ = utils.check_command_line_args("Fail.txt", "('1', '2', '3')", ["1", "2"])
def test_check_command_line_args_passed_values_invalid_arg():
with pytest.raises(ValueError):
_ = utils.check_command_line_args("Fail.txt", 3, ["3"])
def test_check_and_return_command_line_args_one_arg():
assert utils.check_and_return_command_line_args(["1"]) == (None, None)
def test_check_and_return_command_line_args_two_args():
assert utils.check_and_return_command_line_args(
["a.txt", '["1","2"]'], ["1", "2", "3"], ["1", "2", "3"]
) == (["1", "2"], None)
def test_check_and_return_command_line_args_three_args():
assert utils.check_and_return_command_line_args(
["a.txt", '["1","2"]', '["3"]'], ["1", "2", "3"], ["1", "2", "3"]
) == (["1", "2"], ["3"])
def test_check_and_return_command_line_args_too_many_args():
with pytest.raises(ValueError):
_ = utils.check_and_return_command_line_args(["a", "b", "c", "d"])