mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
resulttool/manualexecution: Refactor and simplify codebase
Simplify and removed unnecessary codes. Refactor to allow pythonic loop. (From OE-Core rev: 31449f3a7649be781b7b61f915d5e879728e87af) Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
e29a39142e
commit
f2f7099b8a
@@ -24,24 +24,12 @@ def load_json_file(file):
|
|||||||
with open(file, "r") as f:
|
with open(file, "r") as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
|
|
||||||
|
|
||||||
class ManualTestRunner(object):
|
class ManualTestRunner(object):
|
||||||
def __init__(self):
|
|
||||||
self.jdata = ''
|
|
||||||
self.test_module = ''
|
|
||||||
self.test_cases_id = ''
|
|
||||||
self.configuration = ''
|
|
||||||
self.starttime = ''
|
|
||||||
self.result_id = ''
|
|
||||||
self.write_dir = ''
|
|
||||||
|
|
||||||
def _get_testcases(self, file):
|
def _get_testcases(self, file):
|
||||||
self.jdata = load_json_file(file)
|
self.jdata = load_json_file(file)
|
||||||
self.test_cases_id = []
|
|
||||||
self.test_module = self.jdata[0]['test']['@alias'].split('.', 2)[0]
|
self.test_module = self.jdata[0]['test']['@alias'].split('.', 2)[0]
|
||||||
for i in self.jdata:
|
|
||||||
self.test_cases_id.append(i['test']['@alias'])
|
|
||||||
|
|
||||||
def _get_input(self, config):
|
def _get_input(self, config):
|
||||||
while True:
|
while True:
|
||||||
output = input('{} = '.format(config))
|
output = input('{} = '.format(config))
|
||||||
@@ -67,45 +55,42 @@ class ManualTestRunner(object):
|
|||||||
extra_config = set(store_map['manual']) - set(self.configuration)
|
extra_config = set(store_map['manual']) - set(self.configuration)
|
||||||
for config in sorted(extra_config):
|
for config in sorted(extra_config):
|
||||||
print('---------------------------------------------')
|
print('---------------------------------------------')
|
||||||
print('This is configuration #%s. Please provide configuration value(use "None" if not applicable).'
|
print('This is configuration #%s. Please provide configuration value(use "None" if not applicable).' % config)
|
||||||
% config)
|
|
||||||
print('---------------------------------------------')
|
print('---------------------------------------------')
|
||||||
value_conf = self._get_input('Configuration Value')
|
value_conf = self._get_input('Configuration Value')
|
||||||
print('---------------------------------------------\n')
|
print('---------------------------------------------\n')
|
||||||
self.configuration[config] = value_conf
|
self.configuration[config] = value_conf
|
||||||
|
|
||||||
def _create_result_id(self):
|
def _create_result_id(self):
|
||||||
self.result_id = 'manual_' + self.test_module + '_' + self.starttime
|
self.result_id = 'manual_%s_%s' % (self.test_module, self.starttime)
|
||||||
|
|
||||||
def _execute_test_steps(self, test_id):
|
def _execute_test_steps(self, test):
|
||||||
test_result = {}
|
test_result = {}
|
||||||
total_steps = len(self.jdata[test_id]['test']['execution'].keys())
|
|
||||||
print('------------------------------------------------------------------------')
|
print('------------------------------------------------------------------------')
|
||||||
print('Executing test case:' + '' '' + self.test_cases_id[test_id])
|
print('Executing test case: %s' % test['test']['@alias'])
|
||||||
print('------------------------------------------------------------------------')
|
print('------------------------------------------------------------------------')
|
||||||
print('You have total ' + str(total_steps) + ' test steps to be executed.')
|
print('You have total %s test steps to be executed.' % len(test['test']['execution']))
|
||||||
print('------------------------------------------------------------------------\n')
|
print('------------------------------------------------------------------------\n')
|
||||||
for step, _ in sorted(self.jdata[test_id]['test']['execution'].items(), key=lambda x: int(x[0])):
|
for step, _ in sorted(test['test']['execution'].items(), key=lambda x: int(x[0])):
|
||||||
print('Step %s: ' % step + self.jdata[test_id]['test']['execution']['%s' % step]['action'])
|
print('Step %s: %s' % (step, test['test']['execution'][step]['action']))
|
||||||
expected_output = self.jdata[test_id]['test']['execution']['%s' % step]['expected_results']
|
expected_output = test['test']['execution'][step]['expected_results']
|
||||||
if expected_output:
|
if expected_output:
|
||||||
print('Expected output: ' + expected_output)
|
print('Expected output: %s' % expected_output)
|
||||||
while True:
|
while True:
|
||||||
done = input('\nPlease provide test results: (P)assed/(F)ailed/(B)locked/(S)kipped? \n')
|
done = input('\nPlease provide test results: (P)assed/(F)ailed/(B)locked/(S)kipped? \n').lower()
|
||||||
done = done.lower()
|
|
||||||
result_types = {'p':'PASSED',
|
result_types = {'p':'PASSED',
|
||||||
'f':'FAILED',
|
'f':'FAILED',
|
||||||
'b':'BLOCKED',
|
'b':'BLOCKED',
|
||||||
's':'SKIPPED'}
|
's':'SKIPPED'}
|
||||||
if done in result_types:
|
if done in result_types:
|
||||||
for r in result_types:
|
for r in result_types:
|
||||||
if done == r:
|
if done == r:
|
||||||
res = result_types[r]
|
res = result_types[r]
|
||||||
if res == 'FAILED':
|
if res == 'FAILED':
|
||||||
log_input = input('\nPlease enter the error and the description of the log: (Ex:log:211 Error Bitbake)\n')
|
log_input = input('\nPlease enter the error and the description of the log: (Ex:log:211 Error Bitbake)\n')
|
||||||
test_result.update({self.test_cases_id[test_id]: {'status': '%s' % res, 'log': '%s' % log_input}})
|
test_result.update({test['test']['@alias']: {'status': '%s' % res, 'log': '%s' % log_input}})
|
||||||
else:
|
else:
|
||||||
test_result.update({self.test_cases_id[test_id]: {'status': '%s' % res}})
|
test_result.update({test['test']['@alias']: {'status': '%s' % res}})
|
||||||
break
|
break
|
||||||
print('Invalid input!')
|
print('Invalid input!')
|
||||||
return test_result
|
return test_result
|
||||||
@@ -120,9 +105,9 @@ class ManualTestRunner(object):
|
|||||||
self._create_result_id()
|
self._create_result_id()
|
||||||
self._create_write_dir()
|
self._create_write_dir()
|
||||||
test_results = {}
|
test_results = {}
|
||||||
print('\nTotal number of test cases in this test suite: ' + '%s\n' % len(self.jdata))
|
print('\nTotal number of test cases in this test suite: %s\n' % len(self.jdata))
|
||||||
for i in range(0, len(self.jdata)):
|
for t in self.jdata:
|
||||||
test_result = self._execute_test_steps(i)
|
test_result = self._execute_test_steps(t)
|
||||||
test_results.update(test_result)
|
test_results.update(test_result)
|
||||||
return self.configuration, self.result_id, self.write_dir, test_results
|
return self.configuration, self.result_id, self.write_dir, test_results
|
||||||
|
|
||||||
@@ -130,8 +115,7 @@ def manualexecution(args, logger):
|
|||||||
testrunner = ManualTestRunner()
|
testrunner = ManualTestRunner()
|
||||||
get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file)
|
get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file)
|
||||||
resultjsonhelper = OETestResultJSONHelper()
|
resultjsonhelper = OETestResultJSONHelper()
|
||||||
resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id,
|
resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results)
|
||||||
get_test_results)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def register_commands(subparsers):
|
def register_commands(subparsers):
|
||||||
|
|||||||
Reference in New Issue
Block a user