How to use get_valid_lang method in toolium

Best Python code snippet using toolium_python

translate.py

Source:translate.py Github

copy

Full Screen

...52 warning = 'WARNING! Your terminal does not support UTF-8 encoding. Unicode will be shown on the raw format.'53 #On the POSIX systems set locale to LANG=cs_CZ.UTF-8.54 valid_charset = sys.stdout.encoding55 return valid_charset,warning56def get_valid_lang(code, type_of_value):57 available_langs = langs.keys()58 if code in available_langs:59 error = ''60 else:61 error = "Unsupported language code: '%s' in %s. Available codes are: %s."%(code, type_of_value, ', '.join(available_langs))62 code = default_lang63 return code, error64def install_translation(lang):65 'Install language translation'66 gt = langs[lang]67 gt.install()68 __builtin__.__dict__['_T'] = gt.gettext69 __builtin__.__dict__['_TP'] = gt.ngettext70 __builtin__.__dict__['_TU'] = gt.ugettext # used in GUI71 __builtin__.__dict__['_TPU'] = gt.ungettext # used in GUI72#---------------------------73# INIT options:74#---------------------------75app_name = 'FredClient'76##config_name = '.fred_client.conf'77domain = 'fred_client' # gettext translate domain78langs = {'en': 0, 'cs': 1} # 0 - no translate, 1 - make translation79default_lang = 'en'80optcols = (81 '? help',82 'b bar', # Used by fred_sender for display bar instead of common output. Suitable for huge command sets.83 'c:cert',84 'd:command', # used by creator85 'e:range', # Used by fred_create for generate range of documents.86 'f:config', # define your own config file87 'g:log', # save log in unittest.88 'h:host',89 'i:versions', # schmea versions "contact:1.0,nsset:1.1,domain:1.1"90 'k:privkey',91 'l:lang',92 'n nologin', # turn off automatic login process after start up93 'o:output',94 'p:port',95 'q qt', # run in Qt96 'r:cltrid', # define clTrID97 's:session',98 #'t timer', # for debug only; display duration of processes99 'u:user',100 'v:verbose',101 'w:password',102 'V version',103 'x no_validate', # switch off using validation by extern program (xmllint)104 )105options = {}106for key in optcols:107 options[key[2:]] = ''108#---------------------------109# Defaults:110#---------------------------111option_args = ()112errors = []113warnings = []114#---------------------------115# PARSE COMMAND LINE OPTIONS116#---------------------------117if len(sys.argv) > 1:118 try:119 opts, option_args = getopt.getopt(sys.argv[1:], 120 ''.join(map(lambda s:s[:2].strip(),optcols)),121 map(lambda s:('%s','%s=')[s[1]==':']%s[2:],optcols))122 except getopt.GetoptError, msg:123 errors.append('%s'%msg)124 else:125 if len(option_args):126 errors.append('%s: (%s)'%('unknown options',', '.join(option_args)))127 for k,v in opts:128 for key in optcols:129 keys = ('-%s'%key[0], '--%s'%key[2:])130 key = key[2:]131 if k in keys:132 if v=='': v='yes'133 if key == 'lang':134 options['lang'], error = get_valid_lang(v,'options')135 if error:136 errors.append(error)137 else:138 # need for overwrite value from config file:139 options['lang_option'] = options['lang']140 else:141 options[key] = v142if not len(options['lang']):143 # set language from environ144 code = os.environ.get('LANG') # 'cs_CZ.UTF-8'145 if type(code) is str and len(code) > 1:146 arg = code[:2].lower() # Windows returns 'CS'147 options['lang_environ'], error = get_valid_lang(arg,'os.environ.LANG')148 if error: warnings.append("%s Set default to: '%s'."%(error, default_lang))149 options['lang'] = options['lang_environ']150 else:151 options['lang'] = default_lang152#---------------------------153# SET LANGUAGE VERSION154#---------------------------155encoding, w = find_valid_encoding()156if w: warnings.append(w)157tpath = os.path.join(os.path.split(__file__)[0],'lang')158for key,value in langs.items():159 if value:160 try:161 langs[key] = gettext.translation(domain,tpath,(key,), codeset=encoding)...

Full Screen

Full Screen

test_poeditor.py

Source:test_poeditor.py Github

copy

Full Screen

...17import pytest18from toolium.config_parser import ExtendedConfigParser19from toolium.utils import dataset, poeditor20from toolium.utils.poeditor import get_valid_lang, load_poeditor_texts21def test_get_valid_lang():22 """23 Verification of a POEditor language param24 """25 language_codes = ['en-gb', 'de', 'pt-br', 'es', 'es-ar', 'es-cl', 'es-co', 'es-ec']26 assert get_valid_lang(language_codes, 'pt-br') == 'pt-br'27 assert get_valid_lang(language_codes, 'es') == 'es'28 assert get_valid_lang(language_codes, 'es-es') == 'es'29 assert get_valid_lang(language_codes, 'es-co') == 'es-co'30def test_get_valid_lang_wrong_lang():31 """32 Verification of a POEditor language param33 """34 language_codes = ['en-gb', 'de', 'pt-br']35 with pytest.raises(Exception) as excinfo:36 get_valid_lang(language_codes, 'en-en')37 assert "Language en-en is not included in valid codes: en-gb, de, pt-br" == str(excinfo.value)38def test_poe_lang_param_from_project_config():39 """40 Verification of a POEditor language param getting language from project config41 """42 config_file_path = os.path.join("toolium", "test", "resources", "toolium.cfg")43 dataset.toolium_config = ExtendedConfigParser.get_config_from_file(config_file_path)44 language_codes = ['en-gb', 'de', 'pt-br', 'es', 'es-ar', 'es-cl', 'es-co', 'es-ec', 'en']45 assert get_valid_lang(language_codes) == 'en'46def test_load_poeditor_texts_without_api_token():47 """48 Verification of POEditor texts load abortion when api_token is not configured49 """50 dataset.project_config = {51 "poeditor": {52 "project_name": "My-Bot"53 }54 }55 poeditor.logger = mock.MagicMock()56 load_poeditor_texts()57 poeditor.logger.info.assert_called_with("POEditor is not configured")58def test_load_poeditor_texts_without_api_token_deprecated():59 """...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful