]>
git.saurik.com Git - apple/icu.git/blob - icuSources/python/icutools/databuilder/test/filtration_test.py
1 # Copyright (C) 2018 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
10 from ..comment_stripper
import CommentStripper
11 from ..filtration
import Filter
13 EXAMPLE_FILE_STEMS
= [
76 def read_locale_deps(self
, tree
):
77 if tree
not in ("brkitr", "locales", "rbnf"):
79 with pyio
.open(os
.path
.join(
80 os
.path
.dirname(__file__
),
84 ), "r", encoding
="utf-8-sig") as f
:
85 return json
.load(CommentStripper(f
))
88 class FiltrationTest(unittest
.TestCase
):
90 def test_exclude(self
):
91 self
._check
_filter
(Filter
.create_from_json({
92 "filterType": "exclude"
96 def test_default_whitelist(self
):
97 self
._check
_filter
(Filter
.create_from_json({
107 def test_default_blacklist(self
):
108 expected_matches
= set(EXAMPLE_FILE_STEMS
)
109 expected_matches
.remove("ars")
110 expected_matches
.remove("zh_Hans")
111 self
._check
_filter
(Filter
.create_from_json({
116 }, TestIO()), expected_matches
)
118 def test_language_whitelist(self
):
119 self
._check
_filter
(Filter
.create_from_json({
120 "filterType": "language",
140 def test_language_blacklist(self
):
141 expected_matches
= set(EXAMPLE_FILE_STEMS
)
142 expected_matches
.remove("af_NA")
143 expected_matches
.remove("af_VARIANT")
144 expected_matches
.remove("af_ZA_VARIANT")
145 expected_matches
.remove("af_ZA")
146 expected_matches
.remove("af")
147 self
._check
_filter
(Filter
.create_from_json({
148 "filterType": "language",
152 }, TestIO()), expected_matches
)
154 def test_regex_whitelist(self
):
155 self
._check
_filter
(Filter
.create_from_json({
156 "filterType": "regex",
168 def test_regex_blacklist(self
):
169 expected_matches
= set(EXAMPLE_FILE_STEMS
)
170 expected_matches
.remove("ar")
171 expected_matches
.remove("ar_SA")
172 expected_matches
.remove("ars")
173 expected_matches
.remove("zh")
174 self
._check
_filter
(Filter
.create_from_json({
175 "filterType": "regex",
180 }, TestIO()), expected_matches
)
182 def test_locale_basic(self
):
183 self
._check
_filter
(Filter
.create_from_json({
184 "filterType": "locale",
190 "bs_BA", # is an alias to bs_Latn_BA
192 "sr", # Language with no script
193 "vai_Latn", # Language with non-default script
194 "zh_Hans" # Language with default script
198 # bs: should include the full dependency tree of bs_BA
203 # en: should include the full dependency tree of en_DE
208 # sr: include Cyrl, the default, but not Latn.
216 # vai: include Latn but NOT Vaii.
219 # zh: include Hans but NOT Hant.
230 def test_locale_no_children(self
):
231 self
._check
_filter
(Filter
.create_from_json({
232 "filterType": "locale",
233 "includeChildren": False,
235 # See comments in test_locale_basic.
258 def test_locale_include_scripts(self
):
259 self
._check
_filter
(Filter
.create_from_json({
260 "filterType": "locale",
261 "includeScripts": True,
263 # See comments in test_locale_basic.
272 # bs: includeScripts only works for language-only (without region)
277 # en: should include the full dependency tree of en_DE
282 # sr: include Latn, since no particular script was requested.
291 "sr_Latn_ME_VARIANT",
296 # vai: do NOT include Vaii; the script was explicitly requested.
299 # zh: do NOT include Hant; the script was explicitly requested.
310 def test_locale_no_children_include_scripts(self
):
311 self
._check
_filter
(Filter
.create_from_json({
312 "filterType": "locale",
313 "includeChildren": False,
314 "includeScripts": True,
316 # See comments in test_locale_basic.
325 # bs: includeScripts only works for language-only (without region)
330 # en: should include the full dependency tree of en_DE
335 # sr: include Cyrl and Latn but no other children
339 # vai: include only the requested script
341 # zh: include only the requested script
346 def test_union(self
):
347 self
._check
_filter
(Filter
.create_from_json({
348 "filterType": "union",
357 "filterType": "regex",
376 def test_hk_deps_normal(self
):
377 self
._check
_filter
(Filter
.create_from_json({
378 "filterType": "locale",
389 def test_hk_deps_rbnf(self
):
390 self
._check
_filter
(Filter
.create_from_json({
391 "filterType": "locale",
402 def test_no_alias_parent_structure(self
):
403 self
._check
_filter
(Filter
.create_from_json({
404 "filterType": "locale",
414 def _check_filter(self
, filter, expected_matches
, tree
="locales"):
415 for file_stem
in EXAMPLE_FILE_STEMS
:
416 is_match
= filter.match(InFile("%s/%s.txt" % (tree
, file_stem
)))
417 expected_match
= file_stem
in expected_matches
418 self
.assertEqual(is_match
, expected_match
, file_stem
)
420 # Export the test for the runner
421 suite
= unittest
.makeSuite(FiltrationTest
)