From: vsr Date: Fri, 12 Feb 2021 14:22:13 +0000 (+0300) Subject: Adapt SALOME non-regression test bases for salome test driver X-Git-Tag: V9_7_0a1~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=44c8d76a1872e40721159956521071b067df51f3;p=modules%2Fkernel.git Adapt SALOME non-regression test bases for salome test driver --- diff --git a/bin/appliskel/salome_tester/salome_test_driver.py b/bin/appliskel/salome_tester/salome_test_driver.py index d3d6bb99e..4bc37aa4c 100755 --- a/bin/appliskel/salome_tester/salome_test_driver.py +++ b/bin/appliskel/salome_tester/salome_test_driver.py @@ -26,6 +26,7 @@ import sys import os import subprocess import signal +from contextlib import suppress # Run test def runTest(command): @@ -41,18 +42,42 @@ def runTest(command): # Display output and errors def processResult(res, out, err): + # Decode output + out = out.decode('utf_8') if out else '' + err = err.decode('utf_8') if err else '' + + # Execute hook if it is installed + if getattr(processResult, '__hook', None): + res, out, err = getattr(processResult, '__hook')(res, out, err) + + # Print standard output if out: - print(out.decode('utf_8')) - pass + print(out) + + # Print standard error if err: print(" ** Detected error **") print("Error code: ", res) - print(err.decode('utf_8'), end=' \n') + print(err, end=' \n') print(" ** end of message **") - pass + return res # +def installHook(hook=None): + """Install custome hook to process test result.""" + with suppress(AttributeError, IndexError): + hook = hook.split(',') + hook_path = hook.pop(0) + hook_func = hook.pop(0) + if os.path.exists(hook_path) and hook_func: + with open(hook_path, 'rb') as hook_script: + dic = {} + exec(hook_script.read(), dic) + processResult.__hook = dic.get(hook_func) + print("Custom hook has been installed") +# + # Timeout management class TimeoutException(Exception): """Exception raised when test timeout is reached.""" @@ -65,6 +90,13 @@ if __name__ == "__main__": timeout_delay = sys.argv[1] args = sys.argv[2:] + # Install hook if supplied via command line + with suppress(IndexError, ValueError): + index = args.index('--hook') + args.pop(index) + hook = args.pop(index) + installHook(hook) + # Add explicit call to python executable if a Python script is passed as # first argument if not args: