summaryrefslogtreecommitdiffstats
path: root/scripts/lib/resulttool/manualexecution.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/resulttool/manualexecution.py')
-rwxr-xr-xscripts/lib/resulttool/manualexecution.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/scripts/lib/resulttool/manualexecution.py b/scripts/lib/resulttool/manualexecution.py
index 57e7b2999e..12ef90d6af 100755
--- a/scripts/lib/resulttool/manualexecution.py
+++ b/scripts/lib/resulttool/manualexecution.py
@@ -24,6 +24,11 @@ def load_json_file(file):
24 with open(file, "r") as f: 24 with open(file, "r") as f:
25 return json.load(f) 25 return json.load(f)
26 26
27def write_json_file(f, json_data):
28 os.makedirs(os.path.dirname(f), exist_ok=True)
29 with open(f, 'w') as filedata:
30 filedata.write(json.dumps(json_data, sort_keys=True, indent=4))
31
27class ManualTestRunner(object): 32class ManualTestRunner(object):
28 33
29 def _get_testcases(self, file): 34 def _get_testcases(self, file):
@@ -139,8 +144,53 @@ class ManualTestRunner(object):
139 test_results.update(test_result) 144 test_results.update(test_result)
140 return self.configuration, self.result_id, self.write_dir, test_results 145 return self.configuration, self.result_id, self.write_dir, test_results
141 146
147 def _get_true_false_input(self, input_message):
148 yes_list = ['Y', 'YES']
149 no_list = ['N', 'NO']
150 while True:
151 more_config_option = input(input_message).upper()
152 if more_config_option in yes_list or more_config_option in no_list:
153 break
154 print('Invalid input!')
155 if more_config_option in no_list:
156 return False
157 return True
158
159 def make_config_option_file(self, logger, manual_case_file, config_options_file):
160 config_options = {}
161 if config_options_file:
162 config_options = load_json_file(config_options_file)
163 new_test_module = os.path.basename(manual_case_file).split('.')[0]
164 print('Creating configuration options file for test module: %s' % new_test_module)
165 new_config_options = {}
166
167 while True:
168 config_name = input('\nPlease provide test configuration to create:\n').upper()
169 new_config_options[config_name] = {}
170 while True:
171 config_value = self._get_input('Configuration possible option value')
172 config_option_index = len(new_config_options[config_name]) + 1
173 new_config_options[config_name][config_option_index] = config_value
174 more_config_option = self._get_true_false_input('\nIs there more configuration option input: (Y)es/(N)o\n')
175 if not more_config_option:
176 break
177 more_config = self._get_true_false_input('\nIs there more configuration to create: (Y)es/(N)o\n')
178 if not more_config:
179 break
180
181 if new_config_options:
182 config_options[new_test_module] = new_config_options
183 if not config_options_file:
184 self._create_write_dir()
185 config_options_file = os.path.join(self.write_dir, 'manual_config_options.json')
186 write_json_file(config_options_file, config_options)
187 logger.info('Configuration option file created at %s' % config_options_file)
188
142def manualexecution(args, logger): 189def manualexecution(args, logger):
143 testrunner = ManualTestRunner() 190 testrunner = ManualTestRunner()
191 if args.make_config_options_file:
192 testrunner.make_config_option_file(logger, args.file, args.config_options_file)
193 return 0
144 get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file, args.config_options_file) 194 get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file, args.config_options_file)
145 resultjsonhelper = OETestResultJSONHelper() 195 resultjsonhelper = OETestResultJSONHelper()
146 resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results) 196 resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results)
@@ -154,4 +204,6 @@ def register_commands(subparsers):
154 parser_build.set_defaults(func=manualexecution) 204 parser_build.set_defaults(func=manualexecution)
155 parser_build.add_argument('file', help='specify path to manual test case JSON file.Note: Please use \"\" to encapsulate the file path.') 205 parser_build.add_argument('file', help='specify path to manual test case JSON file.Note: Please use \"\" to encapsulate the file path.')
156 parser_build.add_argument('-c', '--config-options-file', default='', 206 parser_build.add_argument('-c', '--config-options-file', default='',
157 help='the config options file to import and used as available configuration option selection') 207 help='the config options file to import and used as available configuration option selection or make config option file')
208 parser_build.add_argument('-m', '--make-config-options-file', action='store_true',
209 help='make the configuration options file based on provided inputs')