mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-08-21 16:23:50 +08:00
dragonpilot beta3
date: 2023-10-09T10:55:55 commit: 91b6e3aecd7170f24bccacb10c515ec281c30295
This commit is contained in:
@@ -6,11 +6,12 @@ import shutil
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations
|
||||
from openpilot.selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations
|
||||
|
||||
TMP_TRANSLATIONS_DIR = os.path.join(TRANSLATIONS_DIR, "tmp")
|
||||
UNFINISHED_TRANSLATION_TAG = "<translation type=\"unfinished\"" # non-empty translations can be marked unfinished
|
||||
LOCATION_TAG = "<location "
|
||||
FORMAT_ARG = re.compile("%[0-9]+")
|
||||
|
||||
|
||||
class TestTranslations(unittest.TestCase):
|
||||
@@ -67,11 +68,15 @@ class TestTranslations(unittest.TestCase):
|
||||
self.assertTrue("<translation type=\"vanished\">" not in cur_translations,
|
||||
f"{file} ({name}) translation file has obsolete translations. Run selfdrive/ui/update_translations.py --vanish to remove them")
|
||||
|
||||
def test_plural_translations(self):
|
||||
def test_finished_translations(self):
|
||||
"""
|
||||
Tests:
|
||||
- that any numerus (plural) translations marked "finished" have all plural forms non-empty
|
||||
Tests ran on each translation marked "finished"
|
||||
Plural:
|
||||
- that any numerus (plural) translations have all plural forms non-empty
|
||||
- that the correct format specifier is used (%n)
|
||||
Non-plural:
|
||||
- that translation is not empty
|
||||
- that translation format arguments are consistent
|
||||
"""
|
||||
for name, file in self.translation_files.items():
|
||||
with self.subTest(name=name, file=file):
|
||||
@@ -79,17 +84,28 @@ class TestTranslations(unittest.TestCase):
|
||||
|
||||
for context in tr_xml.getroot():
|
||||
for message in context.iterfind("message"):
|
||||
translation = message.find("translation")
|
||||
source_text = message.find("source").text
|
||||
|
||||
# Do not test unfinished translations
|
||||
if translation.get("type") == "unfinished":
|
||||
continue
|
||||
|
||||
if message.get("numerus") == "yes":
|
||||
translation = message.find("translation")
|
||||
numerusform = [t.text for t in translation.findall("numerusform")]
|
||||
|
||||
# Do not assert finished translations
|
||||
if translation.get("type") == "unfinished":
|
||||
continue
|
||||
for nf in numerusform:
|
||||
self.assertIsNotNone(nf, f"Ensure all plural translation forms are completed: {source_text}")
|
||||
self.assertIn("%n", nf, "Ensure numerus argument (%n) exists in translation.")
|
||||
self.assertIsNone(FORMAT_ARG.search(nf), "Plural translations must use %n, not %1, %2, etc.: {}".format(numerusform))
|
||||
|
||||
self.assertNotIn(None, numerusform, "Ensure all plural translation forms are completed.")
|
||||
self.assertTrue(all(re.search("%[0-9]+", t) is None for t in numerusform),
|
||||
"Plural translations must use %n, not %1, %2, etc.: {}".format(numerusform))
|
||||
else:
|
||||
self.assertIsNotNone(translation.text, f"Ensure translation is completed: {source_text}")
|
||||
|
||||
source_args = FORMAT_ARG.findall(source_text)
|
||||
translation_args = FORMAT_ARG.findall(translation.text)
|
||||
self.assertEqual(sorted(source_args), sorted(translation_args),
|
||||
f"Ensure format arguments are consistent: `{source_text}` vs. `{translation.text}`")
|
||||
|
||||
def test_no_locations(self):
|
||||
for name, file in self.translation_files.items():
|
||||
@@ -98,6 +114,13 @@ class TestTranslations(unittest.TestCase):
|
||||
self.assertFalse(line.strip().startswith(LOCATION_TAG),
|
||||
f"Line contains location tag: {line.strip()}, remove all line numbers.")
|
||||
|
||||
def test_entities_error(self):
|
||||
for name, file in self.translation_files.items():
|
||||
with self.subTest(name=name, file=file):
|
||||
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file)
|
||||
matches = re.findall(r'@(\w+);', cur_translations)
|
||||
self.assertEqual(len(matches), 0, f"The string(s) {matches} were found with '@' instead of '&'")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user