mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-devtest
synced 2026-01-15 02:22:56 +01:00
os.CmdTestOs: Add get_ run_ test_cases() and friend
Make the private CmdTestOs.__run_test_cases() method available to external code interested in running a selection of test cases. This is useful, e.g. for re-running a failed firmware installation encapsulated in a test case from inside another test case. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
d747aa78d5
commit
82bb65b6c0
1 changed files with 36 additions and 25 deletions
|
|
@ -13,6 +13,40 @@ from .TestPhases import TestPhases
|
||||||
from .TestCases import TestCases
|
from .TestCases import TestCases
|
||||||
from .TestResults import TestResults
|
from .TestResults import TestResults
|
||||||
|
|
||||||
|
def get_test_cases(env, pattern): # export
|
||||||
|
slog(INFO, "looking for test cases matching pattern list: {}".format(pattern))
|
||||||
|
return TestCases(env.args.test_case_path, include=pattern)
|
||||||
|
|
||||||
|
async def run_test_case(phase, env, machine, case): # export
|
||||||
|
connections = [ c.instance for c in env.connections if c.instance ]
|
||||||
|
delim = '--- running test case "{}"'.format(case)
|
||||||
|
prio = NOTICE
|
||||||
|
prefix = ' {}|{}'.format(*console_color_chars(prio))
|
||||||
|
slog(prio, ',' + delim)
|
||||||
|
jwutils.log.append_to_prefix(prefix)
|
||||||
|
try:
|
||||||
|
if not machine.clear_for_tests():
|
||||||
|
raise Exception("machine is not clear for running tests")
|
||||||
|
rr = await case.run(env, machine, phase)
|
||||||
|
if rr:
|
||||||
|
slog(ERR, "FAIL: ", rr)
|
||||||
|
except Exception:
|
||||||
|
rr = sys.exc_info()[1]
|
||||||
|
slog(ERR, "FAIL: ", rr)
|
||||||
|
slog_m(ERR, traceback.format_exc())
|
||||||
|
jwutils.log.remove_from_prefix(len(prefix))
|
||||||
|
slog(prio, '`' + delim)
|
||||||
|
return rr
|
||||||
|
|
||||||
|
async def run_test_cases(phase, env, machine, cases): # export
|
||||||
|
ret = TestResults()
|
||||||
|
for case in cases:
|
||||||
|
if not phase in case.phases:
|
||||||
|
continue
|
||||||
|
rr = await run_test_case(phase, env, machine, case)
|
||||||
|
ret.add(case, phase, rr)
|
||||||
|
return ret
|
||||||
|
|
||||||
class CmdTestOs(MachineCmd): # export
|
class CmdTestOs(MachineCmd): # export
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -49,30 +83,6 @@ class CmdTestOs(MachineCmd): # export
|
||||||
slog(INFO, 'Phase "{}": opening connection "{}" with phases [{}]'.format(phase.name, conn.info, conn.info.phases_str))
|
slog(INFO, 'Phase "{}": opening connection "{}" with phases [{}]'.format(phase.name, conn.info, conn.info.phases_str))
|
||||||
conn.instance = machine.register_connection(env, conn.info)
|
conn.instance = machine.register_connection(env, conn.info)
|
||||||
|
|
||||||
async def __run_test_cases(self, phase, env, machine, cases):
|
|
||||||
connections = [ c.instance for c in env.connections if c.instance ]
|
|
||||||
for case in cases:
|
|
||||||
if not phase in case.phases:
|
|
||||||
continue
|
|
||||||
delim = '--- running test case "{}"'.format(case)
|
|
||||||
prio = NOTICE
|
|
||||||
prefix = ' {}|{}'.format(*console_color_chars(prio))
|
|
||||||
slog(prio, ',' + delim)
|
|
||||||
jwutils.log.append_to_prefix(prefix)
|
|
||||||
try:
|
|
||||||
if not machine.clear_for_tests():
|
|
||||||
raise Exception("machine is not clear for running tests")
|
|
||||||
rr = await case.run(env, machine, phase)
|
|
||||||
if rr:
|
|
||||||
slog(ERR, "FAIL: ", rr)
|
|
||||||
except Exception:
|
|
||||||
rr = sys.exc_info()[1]
|
|
||||||
slog(ERR, "FAIL: ", rr)
|
|
||||||
slog_m(ERR, traceback.format_exc())
|
|
||||||
self.__results.add(case, phase, rr)
|
|
||||||
jwutils.log.remove_from_prefix(len(prefix))
|
|
||||||
slog(prio, '`' + delim)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __get_trigger(cls, phase):
|
def __get_trigger(cls, phase):
|
||||||
return getattr(cls, '_{}__trigger_{}'.format(cls.__name__, phase.name.lower()), None)
|
return getattr(cls, '_{}__trigger_{}'.format(cls.__name__, phase.name.lower()), None)
|
||||||
|
|
@ -97,7 +107,8 @@ class CmdTestOs(MachineCmd): # export
|
||||||
if trigger_method is not None:
|
if trigger_method is not None:
|
||||||
await trigger_method(phase, env, machine)
|
await trigger_method(phase, env, machine)
|
||||||
await self.__establish_connections(phase, env, machine)
|
await self.__establish_connections(phase, env, machine)
|
||||||
await self.__run_test_cases(phase, env, machine, test_cases)
|
results = await run_test_cases(phase, env, machine, test_cases)
|
||||||
|
self.__results.addResults(results)
|
||||||
finally:
|
finally:
|
||||||
jwutils.log.remove_from_prefix(len(prefix))
|
jwutils.log.remove_from_prefix(len(prefix))
|
||||||
slog(prio, '`' + delim + '<')
|
slog(prio, '`' + delim + '<')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue