translations tests: ignore line numbers (#25675)

* no line numbers

* remove locations

* test

* ignore line numbers

* revert

revert

* fix that

* use relative

* non bytes, global

* clean up
old-commit-hash: 719d5f78560c393732df240f1b6e053113aef2f8
This commit is contained in:
Shane Smiskol
2022-09-06 13:23:41 -07:00
committed by GitHub
parent 775d1beb66
commit d7e92fecc2
8 changed files with 1278 additions and 1271 deletions
+8 -5
View File
@@ -9,6 +9,7 @@ import xml.etree.ElementTree as ET
from selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations
TMP_TRANSLATIONS_DIR = os.path.join(TRANSLATIONS_DIR, "tmp")
LOCATION_TAG = "<location "
class TestTranslations(unittest.TestCase):
@@ -27,9 +28,11 @@ class TestTranslations(unittest.TestCase):
@staticmethod
def _read_translation_file(path, file):
tr_file = os.path.join(path, f"{file}.ts")
with open(tr_file, "rb") as f:
# fix relative path depth
return f.read().replace(b"filename=\"../../", b"filename=\"../")
with open(tr_file, "r") as f:
# ignore locations when checking if translations are updated
lines = [line for line in f.read().splitlines() if
not line.strip().startswith(LOCATION_TAG)]
return "\n".join(lines)
def test_missing_translation_files(self):
for name, file in self.translation_files.items():
@@ -56,14 +59,14 @@ class TestTranslations(unittest.TestCase):
for name, file in self.translation_files.items():
with self.subTest(name=name, file=file):
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file)
self.assertTrue(b"<translation type=\"unfinished\">" not in cur_translations,
self.assertTrue("<translation type=\"unfinished\">" not in cur_translations,
f"{file} ({name}) translation file has unfinished translations. Finish translations or mark them as completed in Qt Linguist")
def test_vanished_translations(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)
self.assertTrue(b"<translation type=\"vanished\">" not in cur_translations,
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):