Set `has_value` test to scan all languages by default
This commit is contained in:
Родитель
b006781bdf
Коммит
d40b705591
|
@ -151,6 +151,15 @@ Identifier: `has_value`
|
|||
|
||||
Checks that strings have values. Since any value is enough for some strings, it simply makes sure that the string isn't None/null and isn't empty.
|
||||
|
||||
<details>
|
||||
<summary>Configuration</summary>
|
||||
|
||||
| Parameter | Type | Acceptable Values | Default | Details |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `default_language_only` | boolean | `true` or `false` | `false` | Set to true to only check the default language for missing values. Otherwise all languages will be checked. |
|
||||
|
||||
</details>
|
||||
|
||||
## Invalid Tokens
|
||||
|
||||
Identifier: `invalid_tokens`
|
||||
|
|
|
@ -14,14 +14,18 @@ class HasValue(LocalizationTestCase):
|
|||
|
||||
@classmethod
|
||||
def default_settings(cls) -> Dict[str, Any]:
|
||||
return {}
|
||||
return {"default_language_only": False}
|
||||
|
||||
def run_test(self) -> List[str]:
|
||||
|
||||
violations: List[str] = []
|
||||
|
||||
for string in self.collection.strings_for_language(self.configuration.default_language()):
|
||||
if self.get_setting("default_language_only"):
|
||||
test_collection = self.collection.strings_for_language(self.configuration.default_language())
|
||||
else:
|
||||
test_collection = self.collection.localized_strings
|
||||
|
||||
for string in test_collection:
|
||||
if string.value is None or len(string.value) == 0:
|
||||
violations.append(f"Value was empty: {string}")
|
||||
continue
|
||||
|
|
|
@ -25,19 +25,21 @@ class HasValueTests(unittest.TestCase):
|
|||
good_values = [" ", "1", "Two three four", " "]
|
||||
|
||||
for value in bad_values:
|
||||
string = localizationkit.LocalizedString("Key", value, "Comment", "en")
|
||||
collection = localizationkit.LocalizedCollection([string])
|
||||
has_value_test = localizationkit.tests.has_value.HasValue(
|
||||
self.configuration, collection
|
||||
)
|
||||
result = has_value_test.execute()
|
||||
self.assertFalse(result.succeeded())
|
||||
for language in ["en", "fr"]:
|
||||
string = localizationkit.LocalizedString("Key", value, "Comment", language)
|
||||
collection = localizationkit.LocalizedCollection([string])
|
||||
has_value_test = localizationkit.tests.has_value.HasValue(
|
||||
self.configuration, collection
|
||||
)
|
||||
result = has_value_test.execute()
|
||||
self.assertFalse(result.succeeded())
|
||||
|
||||
for value in good_values:
|
||||
string = localizationkit.LocalizedString("Key", value, "Comment", "en")
|
||||
collection = localizationkit.LocalizedCollection([string])
|
||||
has_value_test = localizationkit.tests.has_value.HasValue(
|
||||
self.configuration, collection
|
||||
)
|
||||
result = has_value_test.execute()
|
||||
self.assertTrue(result.succeeded(), str(result.violations))
|
||||
for language in ["en", "fr"]:
|
||||
string = localizationkit.LocalizedString("Key", value, "Comment", language)
|
||||
collection = localizationkit.LocalizedCollection([string])
|
||||
has_value_test = localizationkit.tests.has_value.HasValue(
|
||||
self.configuration, collection
|
||||
)
|
||||
result = has_value_test.execute()
|
||||
self.assertTrue(result.succeeded(), str(result.violations))
|
||||
|
|
Загрузка…
Ссылка в новой задаче