mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Fix TestShortcutKeys
This commit is contained in:
parent
27c112d4db
commit
c36434ebdd
2 changed files with 17 additions and 32 deletions
|
@ -180,7 +180,7 @@ class CuraEngineBackend(QObject, Backend):
|
||||||
# \return list of commands and args / parameters.
|
# \return list of commands and args / parameters.
|
||||||
def getEngineCommand(self) -> List[str]:
|
def getEngineCommand(self) -> List[str]:
|
||||||
json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json")
|
json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json")
|
||||||
command = [self._application.getPreferences().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, ""]
|
command = [self._application.getPreferences().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, "-m1"]
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog = "cura", add_help = False)
|
parser = argparse.ArgumentParser(prog = "cura", add_help = False)
|
||||||
parser.add_argument("--debug", action = "store_true", default = False, help = "Turn on the debug mode by setting this option.")
|
parser.add_argument("--debug", action = "store_true", default = False, help = "Turn on the debug mode by setting this option.")
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import unittest
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
MSGCTXT = "msgctxt" # Scope of the text . Like : msgctxt "@action:inmenu menubar:help"
|
MSGCTXT = "msgctxt" # Scope of the text . Like : msgctxt "@action:inmenu menubar:help"
|
||||||
|
@ -13,47 +11,41 @@ COLOR_ENDC = '\033[0m'
|
||||||
|
|
||||||
regex_patter = '(&[\w])' #"&[a-zA-Z0-9]" - Search char '&' and at least one character after it
|
regex_patter = '(&[\w])' #"&[a-zA-Z0-9]" - Search char '&' and at least one character after it
|
||||||
|
|
||||||
|
|
||||||
|
# Directory where this python file resides
|
||||||
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
# Check default language shortcut keys, by default it is English
|
# Check default language shortcut keys, by default it is English
|
||||||
def test_default_shortcut_keys():
|
def test_default_shortcut_keys():
|
||||||
|
|
||||||
language_folder = "de_DE" # choose German language folder, because we only need to test English shortcut keys, the message id is English translation
|
language_folder = "de_DE" # choose German language folder, because we only need to test English shortcut keys, the message id is English translation
|
||||||
|
|
||||||
translation_file_name = "cura.po"
|
translation_file_name = "cura.po"
|
||||||
|
|
||||||
plugin_file_path = os.path.dirname(os.path.abspath(__file__))
|
cura_path = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
|
||||||
path_records = os.path.split(plugin_file_path)
|
|
||||||
global_path = path_records[:-1]
|
|
||||||
cura_path = os.path.join(*global_path)
|
|
||||||
language_file_path = os.path.join(cura_path, "resources", "i18n", language_folder, translation_file_name)
|
language_file_path = os.path.join(cura_path, "resources", "i18n", language_folder, translation_file_name)
|
||||||
|
|
||||||
|
|
||||||
not_valid_shortcut_keys = getDuplicatedShortcutKeys(language_file_path, False)
|
not_valid_shortcut_keys = getDuplicatedShortcutKeys(language_file_path, False)
|
||||||
|
|
||||||
if len(not_valid_shortcut_keys) != 0:
|
if len(not_valid_shortcut_keys) != 0:
|
||||||
temp = '%s' % ', '.join(map(str, not_valid_shortcut_keys))
|
temp = '%s' % ', '.join(map(str, not_valid_shortcut_keys))
|
||||||
print(COLOR_WARNING + "NOT VALID SHORTCUT KEYS: " + temp + COLOR_ENDC)
|
print(COLOR_WARNING + "NOT VALID SHORTCUT KEYS: " + temp + COLOR_ENDC)
|
||||||
|
|
||||||
|
|
||||||
assert len(not_valid_shortcut_keys) == 0
|
assert len(not_valid_shortcut_keys) == 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# If the 'findShortcutKeysInTranslation' is False the function will search shortcut keys in message id
|
# If the 'findShortcutKeysInTranslation' is False the function will search shortcut keys in message id
|
||||||
def getDuplicatedShortcutKeys(language_file_path, findShortcutKeysInTranslation):
|
def getDuplicatedShortcutKeys(language_file_path: str, find_shortcut_keys_in_translation: bool):
|
||||||
last_translation_scope = ""
|
last_translation_scope = ""
|
||||||
|
|
||||||
|
|
||||||
# {shortcut_key, {scope, [translation_text]}}
|
# {shortcut_key, {scope, [translation_text]}}
|
||||||
shortcut_keys = dict()
|
shortcut_keys = dict()
|
||||||
with open(language_file_path, 'r') as f:
|
with open(language_file_path, 'r') as f:
|
||||||
for text in f:
|
for text in f:
|
||||||
|
|
||||||
if text.startswith(MSGCTXT):
|
if text.startswith(MSGCTXT):
|
||||||
last_translation_scope = text
|
last_translation_scope = text
|
||||||
|
|
||||||
|
elif text.startswith(MSGID) and find_shortcut_keys_in_translation or text.startswith(MSGTR) and not find_shortcut_keys_in_translation:
|
||||||
elif text.startswith(MSGID) and findShortcutKeysInTranslation or text.startswith(MSGTR) and not findShortcutKeysInTranslation:
|
|
||||||
|
|
||||||
# if text has '&'symbol and at least one character (char or digit) after it
|
# if text has '&'symbol and at least one character (char or digit) after it
|
||||||
# ex '&acr mytest' -> this should return '&a'
|
# ex '&acr mytest' -> this should return '&a'
|
||||||
# ex '& acr mytest' -> returns None
|
# ex '& acr mytest' -> returns None
|
||||||
|
@ -90,10 +82,8 @@ def getDuplicatedShortcutKeys(language_file_path, findShortcutKeysInTranslation)
|
||||||
|
|
||||||
# Validate all shortcut keys
|
# Validate all shortcut keys
|
||||||
for shortcut_key, scopes in shortcut_keys.items():
|
for shortcut_key, scopes in shortcut_keys.items():
|
||||||
|
|
||||||
# check, whether the key exist in the same scope multiple times or not
|
# check, whether the key exist in the same scope multiple times or not
|
||||||
for key, items in scopes.items():
|
for key, items in scopes.items():
|
||||||
|
|
||||||
# The shortcut keys should not be more than one time in the same scope
|
# The shortcut keys should not be more than one time in the same scope
|
||||||
if len(items) > 1:
|
if len(items) > 1:
|
||||||
not_valid_shortcut_keys += items
|
not_valid_shortcut_keys += items
|
||||||
|
@ -101,9 +91,9 @@ def getDuplicatedShortcutKeys(language_file_path, findShortcutKeysInTranslation)
|
||||||
return not_valid_shortcut_keys
|
return not_valid_shortcut_keys
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("language_type", [("de_DE"),("es_ES"),("fi_FI"),("fr_FR"),("it_IT"),("ja_JP"),("ko_KR"),("nl_NL"),("pl_PL"),("pt_BR"),("ru_RU"),("tr_TR")])
|
@pytest.mark.parametrize("language_type", [("de_DE"),("es_ES"),("fi_FI"),("fr_FR"),("it_IT"),("ja_JP"),("ko_KR"),
|
||||||
|
("nl_NL"),("pl_PL"),("pt_BR"),("ru_RU"),("tr_TR")])
|
||||||
def test_shortcut_keys(language_type):
|
def test_shortcut_keys(language_type):
|
||||||
|
|
||||||
language_folder = language_type
|
language_folder = language_type
|
||||||
|
|
||||||
translation_file_name = "cura.po"
|
translation_file_name = "cura.po"
|
||||||
|
@ -117,12 +107,7 @@ def test_shortcut_keys(language_type):
|
||||||
not_valid_shortcut_keys = getDuplicatedShortcutKeys(language_file_path, False)
|
not_valid_shortcut_keys = getDuplicatedShortcutKeys(language_file_path, False)
|
||||||
|
|
||||||
if len(not_valid_shortcut_keys) != 0:
|
if len(not_valid_shortcut_keys) != 0:
|
||||||
temp='%s' % ', '.join(map(str, not_valid_shortcut_keys))
|
temp = "%s" % ", ".join(map(str, not_valid_shortcut_keys))
|
||||||
print(COLOR_WARNING + "NOT VALID SHORTCUT KEYS: " + temp + COLOR_ENDC)
|
print(COLOR_WARNING + "NOT VALID SHORTCUT KEYS: " + temp + COLOR_ENDC)
|
||||||
|
|
||||||
|
|
||||||
assert len(not_valid_shortcut_keys) == 0
|
assert len(not_valid_shortcut_keys) == 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
Loading…
Add table
Add a link
Reference in a new issue