Added test for searching not used translation strings

Signed-off-by: Serhy <sergii@status.im>
This commit is contained in:
yevh-berdnyk 2019-08-08 00:37:00 +03:00 committed by Serhy
parent cb90c1b715
commit fde55b80d0
No known key found for this signature in database
GPG Key ID: 5D7C4B9E2B6F500B
3 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,42 @@
from itertools import chain
import json
import os
import pytest
from tests import marks
from tests.base_test_case import NoDeviceTestCase
@marks.all
@marks.translations
class TestTranslations(NoDeviceTestCase):
@marks.testrail_id(6223)
def test_find_unused_translations(self):
directory = os.sep.join(__file__.split(os.sep)[:-5])
with open(os.path.join(directory, 'translations/en.json'), 'r') as f:
data = set(json.load(f).keys())
result = []
paths = ['src/status_im', 'components/src']
for root, dirs, files in chain.from_iterable(os.walk(os.path.join(directory, path)) for path in paths):
dirs[:] = [d for d in dirs if d not in ['test', 'translations']]
for file in [file for file in files if file.endswith('.cljs')]:
with open(os.path.join(root, file), "r") as source:
try:
content = source.read()
for key_name in data:
if key_name in content:
result.append(key_name)
except UnicodeDecodeError:
pass
unused = data - set(result)
recheck = [i for i in unused if i[-1].isdigit()]
error = ''
if recheck:
error += 'Translations to recheck: \n %s' % recheck
unused -= set(recheck)
if unused:
error += '\nUnused translations: \n %s' % unused
if error:
pytest.fail(error)

View File

@ -252,3 +252,12 @@ environment = LocalMultipleDeviceTestCase if pytest.config.getoption('env') == '
class MultipleDeviceTestCase(environment): class MultipleDeviceTestCase(environment):
pass pass
class NoDeviceTestCase(AbstractTestCase):
def setup_method(self, method, **kwargs):
pass
def teardown_method(self, method):
self.github_report.save_test(test_suite_data.current_test)

View File

@ -23,5 +23,5 @@ skip = pytest.mark.skip
logcat = pytest.mark.logcat logcat = pytest.mark.logcat
performance = pytest.mark.performance performance = pytest.mark.performance
battery_consumption = pytest.mark.battery_consumption battery_consumption = pytest.mark.battery_consumption
translations = pytest.mark.translations