How to use list_opts method in tempest

Best Python code snippet using tempest_python

testcmdline.py

Source:testcmdline.py Github

copy

Full Screen

1'''2Created on Oct 20, 20143@author: Hideki Ikeda4'''5import os6import sys7import random8import unittest9sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))10import hdemu as emu11import hseexceptions as emuex12def make_opt_list(list_of_list):13 opt_list = [ x for sublist in list_of_list for x in sublist ]14 opt_list.insert(0, 'hdemu') 15 return opt_list16 17class TestCommandLineOption(unittest.TestCase):18 '''19 Unit tests for analyzing command line options20 '''21 def setUp(self):22 self.opt_input = '-input'23 self.opt_output = '-output'24 self.opt_interim = '-interim'25 self.opt_mapper = '-mapper'26 self.opt_reducer = '-reducer'27 self.opt_cmdenv = '-cmdenv'28 self.opt_files = '-files'29 self.data_input = 'data_input'30 self.data_input_path = os.path.abspath(self.data_input)31 self.data_output = 'data_output'32 self.data_output_path = os.path.abspath(self.data_output)33 self.data_interim = 'data_interim'34 self.data_interim_path = os.path.abspath(self.data_interim)35 self.data_mapper = 'data_mapper'36 self.data_mapper_path = os.path.abspath(self.data_mapper)37 self.data_reducer = 'data_reducer'38 self.data_reducer_path = os.path.abspath(self.data_reducer)39 40 self.opt_unknown1 = '-doyouknowme'41 self.opt_unknown2 = 'youdonotknowme'42 43 def testCorrectOptions(self):44 # -cmdenv data45 env_var = 'HSETESTVAR'46 env_val = 'hsetestenv_val'47 val_cmdenv = env_var + '=' + env_val48 # -files data49 files = [ 'file1.txt', 'dir/file2.txt' ]50 val_files = ','.join(files)51 num_files = len(files)52 list_opts = [ [self.opt_input, self.data_input],53 [self.opt_output, self.data_output],54 [self.opt_interim, self.data_interim],55 [self.opt_mapper, self.data_mapper],56 [self.opt_reducer, self.data_reducer],57 [self.opt_cmdenv, val_cmdenv],58 [self.opt_files, val_files]59 ]60 emu_path = os.path.dirname(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))61 pseud_opts = make_opt_list(list_opts)62 args = emu.analyze_argv(pseud_opts)63 self.assertEqual(args.emulator_path, emu_path, 'Emulator directory')64 self.assertEqual(args.input_path, self.data_input_path, 'Input directory')65 self.assertEqual(args.output_path, self.data_output_path, 'Output directory')66 self.assertEqual(args.interim_dir, self.data_interim_path, 'Interim directory')67 self.assertEqual(args.mapper, self.data_mapper_path, 'Mapper')68 self.assertEqual(args.reducer, self.data_reducer_path, 'Reducer')69 ret_env_var, ret_env_val = args.cmdenv[0]70 self.assertEqual(ret_env_var, env_var, "Environment variable doesn't exist")71 self.assertEqual(ret_env_val, env_val, "Environment variable wrong value")72 list_files = args.files73 self.assertEqual(len(list_files), num_files, 'Number of files are incorrect')74 for f in files:75 self.assertIn(f, list_files, "{} is not included in file list".format(f))76 # change the order of options77 random.shuffle(list_opts)78 pseud_opts = make_opt_list(list_opts)79 args = emu.analyze_argv(pseud_opts)80 self.assertEqual(args.input_path, self.data_input_path, 'Input directory')81 self.assertEqual(args.output_path, self.data_output_path, 'Output directory')82 self.assertEqual(args.interim_dir, self.data_interim_path, 'Interim directory')83 self.assertEqual(args.mapper, self.data_mapper_path, 'Mapper')84 self.assertEqual(args.reducer, self.data_reducer_path, 'Reducer')85 ret_env_var, ret_env_val = args.cmdenv[0]86 self.assertEqual(ret_env_var, env_var, "Environment variable doesn't exist")87 self.assertEqual(ret_env_val, env_val, "Environment variable wrong value")88 list_files = args.files89 self.assertEqual(len(list_files), num_files, 'Number of files are incorrect')90 for f in files:91 self.assertIn(f, list_files, "{} is not included in file list".format(f))92 # change the order of options again93 random.shuffle(list_opts)94 pseud_opts = make_opt_list(list_opts)95 args = emu.analyze_argv(pseud_opts)96 self.assertEqual(args.input_path, self.data_input_path, 'Input directory')97 self.assertEqual(args.output_path, self.data_output_path, 'Output directory')98 self.assertEqual(args.interim_dir, self.data_interim_path, 'Interim directory')99 self.assertEqual(args.mapper, self.data_mapper_path, 'Mapper')100 self.assertEqual(args.reducer, self.data_reducer_path, 'Reducer')101 ret_env_var, ret_env_val = args.cmdenv[0]102 self.assertEqual(ret_env_var, env_var, "Environment variable doesn't exist")103 self.assertEqual(ret_env_val, env_val, "Environment variable wrong value")104 list_files = args.files105 self.assertEqual(len(list_files), num_files, 'Number of files are incorrect')106 for f in files:107 self.assertIn(f, list_files, "{} is not included in file list".format(f))108 def testCmdenvThree(self):109 '''110 -cmdenv test with three options111 '''112 values = { 'VAR1' : 'val1', 'VAR2' : 'val2', 'VAR3' : 'val3' }113 list_opts = [ [self.opt_cmdenv, var + '=' + values[var]] for var in iter(values) ]114 pseud_opts = make_opt_list(list_opts)115 args = emu.analyze_argv(pseud_opts)116 for var, val in args.cmdenv:117 self.assertTrue(var in values, 'Returned environment variable not match original' + var)118 self.assertEqual(val, values[var], 'Value for {} not match'.format(var))119 self.assertEqual(len(args.cmdenv), len(values), 'the wrong number of items')120 def testCmdenvEmptyVal(self):121 '''122 -cmdenv test with empty value123 '''124 test_var = 'TEST_VAR'125 expected = '' # empty value126 pseud_opts = make_opt_list( [ [self.opt_cmdenv, test_var + '=' + expected] ] )127 args = emu.analyze_argv(pseud_opts)128 var, val = args.cmdenv[0]129 self.assertTrue(var == test_var, 'Returned environment variable not match original' + var)130 self.assertEqual(val, expected, 'Value for {} not match'.format(var))131 self.assertEqual(len(args.cmdenv), 1, 'the wrong number of items')132 def testCmdenvDup(self):133 '''134 -cmdenv test with duplicate135 '''136 test_var = 'TEST_VAR'137 unexpected = 'unexpected'138 expected = 'expected_value'139 temp_opts = [ [self.opt_cmdenv, test_var + '=' + unexpected], [self.opt_cmdenv, test_var + '=' + expected] ]140 pseud_opts = make_opt_list(temp_opts)141 args = emu.analyze_argv(pseud_opts)142 var, val = args.cmdenv[0]143 self.assertTrue(var == test_var, 'Returned environment variable not match original' + var)144 self.assertEqual(val, expected, 'Value for {} not match'.format(var))145 self.assertEqual(len(args.cmdenv), 1, 'the wrong number of items')146 def testCmdenvNoValue(self):147 '''148 -cmdenv test with duplicate149 '''150 test_var = 'TEST_VAR'151 expected = 'expected_value'152 # 'TEST_VAR=expected_value' and 'TEST_VAR'153 # arg w/o the value part must be ignored154 temp_opts = [ [self.opt_cmdenv, test_var + '=' + expected], [self.opt_cmdenv, test_var] ]155 pseud_opts = make_opt_list( temp_opts )156 args = emu.analyze_argv(pseud_opts)157 var, val = args.cmdenv[0]158 self.assertTrue(var == test_var, 'Returned environment variable not match original' + var)159 self.assertEqual(val, expected, 'Value for {} not match'.format(var))160 self.assertEqual(len(args.cmdenv), 1, 'the wrong number of items')161 def testUnknownOptions(self):162 '''163 Unknown options should be gracefully ignored with error message164 to stderr165 TODO : add error message test 166 '''167 list_opts = [ [self.opt_unknown1],168 [self.opt_input, self.data_input],169 [self.opt_output, self.data_output],170 [self.opt_mapper, self.data_mapper],171 [self.opt_reducer, self.data_reducer],172 [self.opt_unknown2] ]173 174 emu_path = os.path.dirname(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))175 pseud_opts = make_opt_list(list_opts)176 args = emu.analyze_argv(pseud_opts)177 self.assertEqual(args.emulator_path, emu_path, 'Emulator directory')178 self.assertEqual(args.input_path, self.data_input_path, 'Input directory')179 self.assertEqual(args.output_path, self.data_output_path, 'Output directory')180 self.assertEqual(args.mapper, self.data_mapper_path, 'Mapper')181 self.assertEqual(args.reducer, self.data_reducer_path, 'Reducer')182 183 # change the order of options184 random.shuffle(list_opts)185 pseud_opts = make_opt_list(list_opts)186 args = emu.analyze_argv(pseud_opts)187 self.assertEqual(args.input_path, self.data_input_path, 'Input directory')188 self.assertEqual(args.output_path, self.data_output_path, 'Output directory')189 self.assertEqual(args.mapper, self.data_mapper_path, 'Mapper')190 self.assertEqual(args.reducer, self.data_reducer_path, 'Reducer')191 # change the order of options again192 random.shuffle(list_opts)193 pseud_opts = make_opt_list(list_opts)194 args = emu.analyze_argv(pseud_opts)195 self.assertEqual(args.input_path, self.data_input_path, 'Input directory')196 self.assertEqual(args.output_path, self.data_output_path, 'Output directory')197 self.assertEqual(args.mapper, self.data_mapper_path, 'Mapper')198 self.assertEqual(args.reducer, self.data_reducer_path, 'Reducer')199if __name__ == "__main__":200 #import sys;sys.argv = ['', 'Test.testName']...

Full Screen

Full Screen

opts.py

Source:opts.py Github

copy

Full Screen

...43 cfg.CONF(args,44 project='ironic-inspector',45 version=version.version_info.release_string(),46 default_config_files=default_config_files)47def list_opts():48 return [49 ('capabilities', ironic_inspector.conf.capabilities.list_opts()),50 ('DEFAULT', ironic_inspector.conf.default.list_opts()),51 ('discovery', ironic_inspector.conf.discovery.list_opts()),52 ('dnsmasq_pxe_filter',53 ironic_inspector.conf.dnsmasq_pxe_filter.list_opts()),54 ('swift', ironic_inspector.conf.swift.list_opts()),55 ('ironic', ironic_inspector.conf.ironic.list_opts()),56 ('iptables', ironic_inspector.conf.iptables.list_opts()),57 ('processing', ironic_inspector.conf.processing.list_opts()),58 ('pci_devices', ironic_inspector.conf.pci_devices.list_opts()),59 ('pxe_filter', ironic_inspector.conf.pxe_filter.list_opts()),...

Full Screen

Full Screen

update_res.py

Source:update_res.py Github

copy

Full Screen

1import sys2import awtk_locator as locator34LONGSOPTS = ['awtk_root=', 'AWTK_ROOT=']5def get_args(args, longsopts = []) :6 list_opts = []7 for arg in args:8 if arg.startswith('--') :9 tmp_opt = '';10 for opt in longsopts:11 if arg.find(opt) > 0 :12 tmp_opt = opt;13 break14 if tmp_opt != '' :15 list_opts.append(arg.split(tmp_opt)[1])16 continue17 else :18 print(arg + " not find command, command :")19 print(longsopts)20 sys.exit()21 return list_opts222324def update_res(ARGUMENTS, is_new_usage):25 locator.init(ARGUMENTS)2627 import update_res_app as updater28 if is_new_usage and not hasattr(updater, "getopt") :29 print(" must update awtk !!!")30 sys.exit()31 updater.run(locator.getAwtkRoot())3233is_new_usage = False34opts = get_args(sys.argv[1:], LONGSOPTS)35ARGUMENTS = dict()36if len(opts) > 0 :37 is_new_usage = True38 ARGUMENTS['AWTK_ROOT'] = opts[0]39else :40 ARGUMENTS['AWTK_ROOT'] = '' ...

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 tempest 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