From 44c8d76a1872e40721159956521071b067df51f3 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 12 Feb 2021 17:22:13 +0300 Subject: [PATCH] Adapt SALOME non-regression test bases for salome test driver --- .../salome_tester/salome_test_driver.py | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) 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: -- 2.39.2