This commit is contained in:
Dale Myers 2019-08-29 13:59:37 +01:00
Родитель c1fedaa204
Коммит 68d805f73a
4 изменённых файлов: 79 добавлений и 0 удалений

Просмотреть файл

@ -121,6 +121,12 @@ _Note: Only languages that have latin style scripts are really supported for the
</details>
## Has Value
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.
## Invalid Tokens
Identifier: `invalid_tokens`

Просмотреть файл

@ -2,6 +2,7 @@
import localizationkit.tests.comment_similarity
import localizationkit.tests.has_comments
import localizationkit.tests.has_value
import localizationkit.tests.invalid_tokens
import localizationkit.tests.key_length
import localizationkit.tests.token_matching

Просмотреть файл

@ -0,0 +1,29 @@
"""Checks that the value is set."""
from typing import Any, Dict, List
from localizationkit.tests.test_case import LocalizationTestCase
class HasValue(LocalizationTestCase):
"""Check the length of the values."""
@classmethod
def name(cls) -> str:
return "has_value"
@classmethod
def default_settings(cls) -> Dict[str, Any]:
return {}
def run_test(self) -> List[str]:
violations: List[str] = []
for string in self.collection.strings_for_language(self.configuration.default_language()):
if string.value is None or len(string.value) == 0:
violations.append(f"Value was empty: {string}")
continue
return violations

43
tests/test_has_value.py Normal file
Просмотреть файл

@ -0,0 +1,43 @@
"""Has value tests."""
# pylint: disable=line-too-long
import os
import sys
import unittest
sys.path.insert(0, os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..")))
import localizationkit
class HasValueTests(unittest.TestCase):
"""Has value tests."""
def setUp(self):
current_file_path = os.path.abspath(__file__)
current_folder_path = os.path.dirname(current_file_path)
self.config_path = os.path.abspath(os.path.join(current_folder_path, "config.toml"))
self.configuration = localizationkit.Configuration.from_file(self.config_path)
def test_has_value(self):
"""Test that has value works"""
bad_values = [None, ""]
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 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))