#
import os
-import sys
-import select
+from pathlib import Path
+import re
+import shutil
import subprocess
+import sys
+import tempfile
+
def __configureTests(args=None, exe=None):
- if args is None:
- args = []
- if exe:
- usage = "Usage: %s [options]"%exe
- else:
- usage = "Usage: %prog [options]"
- epilog = """\n
+ if args is None:
+ args = []
+ if exe:
+ usage = "Usage: %s [options]" % exe
+ else:
+ usage = "Usage: %prog [options]"
+ epilog = """\n
Run tests of SALOME components provided with application.\n
Principal options are:
-h,--help
For complete description of available options, pleaser refer to ctest documentation.\n
"""
- if not args:
- return []
+ if not args:
+ return []
+
+ if args[0] in ["-h", "--help"]:
+ print(usage + epilog)
+ sys.exit(0)
+
+ return args
- if args[0] in ["-h", "--help"]:
- print(usage + epilog)
- sys.exit(0)
- return args
#
# tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
__testSubDir = "bin/salome/test"
-def runTests(args, exe=None):
- args = __configureTests(args, exe)
- appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
- if not appliPath:
- raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.")
+def runTests(args, exe=None):
+ args = __configureTests(args, exe)
+ test_path_list = []
+ salome_tests_path = os.getenv("SALOME_TESTS_PATH")
+ if salome_tests_path:
+ salome_tests_path_list = re.split("[:;]", salome_tests_path)
+ test_path_list += [
+ Path(p) for p in salome_tests_path_list if Path(p) not in test_path_list
+ ]
+ salome_tests_path = (
+ os.getenv("SALOME_TESTS_DIRECTORY") or tempfile.NamedTemporaryFile().name
+ )
+ ctest_directory = Path(salome_tests_path)
+ ctest_directory.mkdir(exist_ok=True)
+ ctest_test_file = ctest_directory / "CTestTestfile.cmake"
+ content = ""
+ for test_path in test_path_list:
+ content += f'SUBDIRS("{test_path}")\n'
+ ctest_test_file.write_text(content)
+ command = ["ctest"] + args
+ ret = subprocess.check_call(command, cwd=ctest_directory)
+ if not os.getenv("SALOME_TESTS_DIRECTORY"):
+ shutil.rmtree(ctest_directory)
+ return ret
+ else:
+ appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
+ if not appliPath:
+ from salomeContext import SalomeContextException
- testPath = os.path.join(appliPath, __testSubDir)
+ raise SalomeContextException(
+ "Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set."
+ )
+ testPath = os.path.join(appliPath, __testSubDir)
- command = ["ctest"] + args
- p = subprocess.Popen(command, cwd=testPath)
- p.communicate()
- return p.returncode
-#
+ command = ["ctest"] + args
+ p = subprocess.Popen(command, cwd=testPath)
+ p.communicate()
+ return p.returncode
"""Unset environment variable"""
def unsetVariable(self, name):
if name in os.environ:
+ self.getLogger().debug("Unset environment variable: %s", name)
del os.environ[name]
#
value = os.path.expandvars(value) # expand environment variables
self.getLogger().debug("Add to %s: %s", name, value)
env = os.getenv(name, None)
+ self.getLogger().debug("Prepend to environment variable: %s : %s", name, value)
if env is None:
os.environ[name] = value
else:
value = os.path.expandvars(value) # expand environment variables
env = os.getenv(name, None)
+ self.getLogger().debug("Append to environment variable: %s : %s", name, value)
if env is None:
os.environ[name] = value
else: