]>
git.saurik.com Git - apple/icu.git/blob - icuSources/data/buildtool/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
7 from ..filtration
import Filter
63 class FiltrationTest(unittest
.TestCase
):
65 def test_exclude(self
):
66 self
._check
_filter
(Filter
.create_from_json({
67 "filterType": "exclude"
71 def test_default_whitelist(self
):
72 self
._check
_filter
(Filter
.create_from_json({
82 def test_default_blacklist(self
):
83 expected_matches
= set(EXAMPLE_FILE_STEMS
)
84 expected_matches
.remove("ars")
85 expected_matches
.remove("zh_Hans")
86 self
._check
_filter
(Filter
.create_from_json({
93 def test_language_whitelist(self
):
94 self
._check
_filter
(Filter
.create_from_json({
95 "filterType": "language",
113 def test_language_blacklist(self
):
114 expected_matches
= set(EXAMPLE_FILE_STEMS
)
115 expected_matches
.remove("af_NA")
116 expected_matches
.remove("af_ZA")
117 expected_matches
.remove("af")
118 self
._check
_filter
(Filter
.create_from_json({
119 "filterType": "language",
123 }), expected_matches
)
125 def test_regex_whitelist(self
):
126 self
._check
_filter
(Filter
.create_from_json({
127 "filterType": "regex",
139 def test_regex_blacklist(self
):
140 expected_matches
= set(EXAMPLE_FILE_STEMS
)
141 expected_matches
.remove("ar")
142 expected_matches
.remove("ar_SA")
143 expected_matches
.remove("ars")
144 expected_matches
.remove("zh")
145 self
._check
_filter
(Filter
.create_from_json({
146 "filterType": "regex",
151 }), expected_matches
)
153 def test_locale_basic(self
):
154 self
._check
_filter
(Filter
.create_from_json({
155 "filterType": "locale",
161 "bs_BA", # is an alias to bs_Latn_BA
163 "sr", # Language with no script
164 "vai_Latn", # Language with non-default script
165 "zh_Hans" # Language with default script
169 # bs: should include the full dependency tree of bs_BA
174 # en: should include the full dependency tree of en_DE
179 # sr: include Cyrl, the default, but not Latn.
187 # vai: include Latn but NOT Vaii.
190 # zh: include Hans but NOT Hant.
201 def test_locale_no_children(self
):
202 self
._check
_filter
(Filter
.create_from_json({
203 "filterType": "locale",
204 "includeChildren": False,
206 # See comments in test_locale_basic.
229 def test_locale_include_scripts(self
):
230 self
._check
_filter
(Filter
.create_from_json({
231 "filterType": "locale",
232 "includeScripts": True,
234 # See comments in test_locale_basic.
243 # bs: includeScripts only works for language-only (without region)
248 # en: should include the full dependency tree of en_DE
253 # sr: include Latn, since no particular script was requested.
266 # vai: do NOT include Vaii; the script was explicitly requested.
269 # zh: do NOT include Hant; the script was explicitly requested.
280 def test_locale_no_children_include_scripts(self
):
281 self
._check
_filter
(Filter
.create_from_json({
282 "filterType": "locale",
283 "includeChildren": False,
284 "includeScripts": True,
286 # See comments in test_locale_basic.
295 # bs: includeScripts only works for language-only (without region)
300 # en: should include the full dependency tree of en_DE
305 # sr: include Cyrl and Latn but no other children
309 # vai: include only the requested script
311 # zh: include only the requested script
316 def test_union(self
):
317 self
._check
_filter
(Filter
.create_from_json({
318 "filterType": "union",
327 "filterType": "regex",
346 def _check_filter(self
, filter, expected_matches
):
347 for file_stem
in EXAMPLE_FILE_STEMS
:
348 is_match
= filter.match(InFile("locales/%s.txt" % file_stem
))
349 expected_match
= file_stem
in expected_matches
350 self
.assertEqual(is_match
, expected_match
, file_stem
)
352 # Export the test for the runner
353 suite
= unittest
.makeSuite(FiltrationTest
)