From fde55b80d0f6d4f6997364f24b85bdc4de4df778 Mon Sep 17 00:00:00 2001 From: yevh-berdnyk Date: Thu, 8 Aug 2019 00:37:00 +0300 Subject: [PATCH] Added test for searching not used translation strings Signed-off-by: Serhy --- test/appium/tests/atomic/test_translations.py | 42 +++++++++++++++++++ test/appium/tests/base_test_case.py | 9 ++++ test/appium/tests/marks.py | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/appium/tests/atomic/test_translations.py diff --git a/test/appium/tests/atomic/test_translations.py b/test/appium/tests/atomic/test_translations.py new file mode 100644 index 0000000000..c26a0f2010 --- /dev/null +++ b/test/appium/tests/atomic/test_translations.py @@ -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) diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 8fd919716f..ca7420aebb 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -252,3 +252,12 @@ environment = LocalMultipleDeviceTestCase if pytest.config.getoption('env') == ' class MultipleDeviceTestCase(environment): 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) diff --git a/test/appium/tests/marks.py b/test/appium/tests/marks.py index a1cf15817d..f78f073ba8 100644 --- a/test/appium/tests/marks.py +++ b/test/appium/tests/marks.py @@ -23,5 +23,5 @@ skip = pytest.mark.skip logcat = pytest.mark.logcat performance = pytest.mark.performance - battery_consumption = pytest.mark.battery_consumption +translations = pytest.mark.translations