Salome HOME
Adapt SALOME non-regression test bases for salome test driver
authorvsr <vsr@opencascade.com>
Fri, 12 Feb 2021 14:22:13 +0000 (17:22 +0300)
committervsr <vsr@opencascade.com>
Fri, 12 Feb 2021 14:22:13 +0000 (17:22 +0300)
bin/appliskel/salome_tester/salome_test_driver.py

index d3d6bb99e55274241d656f6e3b2137ac11458308..4bc37aa4c338d68d244615ae0c3104505a34be65 100755 (executable)
@@ -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: