Newer
Older
#
# --> collect test directories/files
# --> create tests (ctest)
#
# For each function 'test_something' in all files of directories
# 'tests' a new test is created.
#
# Those tests will be run after a call to 'make test'
# or a call to ctest.
find_python_module(pytest REQUIRED)
# === Tests options ===
set(pytest_opt "-v" CACHE INTERNAL "extra options for py.test")
# Force create data directory for tests event if no tests needs it
# because this will we the working directory for all tests.
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/dataForTests)
# Add_python_test(name file) with 'name' is the name of the test
macro(add_python_test test_name test_file)
add_test(${test_name} py.test "${pytest_opt}" ${test_file})
set_tests_properties(${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "FAILURE;Exception;[^x]failed;ERROR;Assertion")
set_tests_properties(${test_name} PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/dataForTests)
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "PYTHONPATH=$ENV{PYTHONPATH}:${HYSOP_BUILD_PYTHONPATH}")
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "PYTHONPATH=$ENV{PYTHONPATH}:${HYSOP_BUILD_PYTHONPATH},LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${HYSOP_BUILD_PYTHONPATH}")
set_tests_properties(${test_name} PROPERTIES TIMEOUT ${TEST_TIMEOUT})
if(WITH_MPI_TESTS)
# Run the same test using mpi multi process run.
# The number of processes used is set with NBPROCS_FOR_TESTS variable (user option for cmake, default=8)
add_test(${test_name}_mpi ${MPIEXEC} -np ${NBPROCS_FOR_TESTS} ${PYTHON_EXECUTABLE} -m pytest "${pytest_opt}" ${test_file})
#mpirun -np 1 python -m pytest -v
set_tests_properties(${test_name}_mpi PROPERTIES FAIL_REGULAR_EXPRESSION "FAILURE;Exception;[^x]failed;ERROR;Assertion")
set_tests_properties(${test_name}_mpi PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/dataForTests)
set_tests_properties(${test_name}_mpi PROPERTIES ENVIRONMENT "PYTHONPATH=$ENV{PYTHONPATH}:${HYSOP_BUILD_PYTHONPATH},LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${HYSOP_BUILD_PYTHONPATH}")
set_tests_properties(${test_name}_mpi PROPERTIES TIMEOUT ${TEST_TIMEOUT})
endif()
# Choose python build dir as directory where tests will be run.
set(testDir ${HYSOP_BUILD_PYTHONPATH})
# === Set the list of all directories which may contain tests ===
set(py_src_dirs core/arrays core/graph core/memory fields operator numerics numerics/splitting)
Jean-Matthieu Etancelin
committed
# === Create the files list from all directories in py_src_dirs ===
# Build a list of test_*.py files for each directory of hysop/${py_src_dirs}
set(py_test_files)
foreach(testdir ${py_src_dirs})
file(GLOB testfiles RELATIVE ${CMAKE_SOURCE_DIR} hysop/${testdir}/tests/test_*.py)
set(py_test_files ${py_test_files} ${testfiles})
file(COPY ${reffiles} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/dataForTests)
# Handling doctest in *.py files recursively for each directory of hysop/${py_src_dirs}
Franck Pérignon
committed
foreach(testdir ${py_src_dirs})
file(GLOB testfiles RELATIVE ${CMAKE_SOURCE_DIR} hysop/${testdir}/[a-zA-Z]*.py)
file(STRINGS ${testfile} test_doctest REGEX ">>>")
if(NOT "${test_doctest}" STREQUAL "")
set(py_doctest_files ${py_doctest_files} ${testfile})
Franck Pérignon
committed
endforeach()
Franck Pérignon
committed
foreach(testfile ${py_test_files})
Franck Pérignon
committed
get_filename_component(testName ${testfile} NAME_WE)
message(STATUS "Add test ${execname} ...")
add_python_test(${testName} ${execname})
Franck Pérignon
committed
endforeach()
foreach(testfile ${py_doctest_files})
get_filename_component(testName ${testfile} NAME_WE)
set(exename ${testDir}/${testfile})
add_test("doctest_${testName}" py.test -v --doctest-modules ${exename})
# Setup extra timeout for some specific test (used with ctest, not in CI)
set_tests_properties("test_poisson" PROPERTIES TIMEOUT 600)
set_tests_properties("test_poisson_curl" PROPERTIES TIMEOUT 600)
set_tests_properties("test_solenoidal_projection" PROPERTIES TIMEOUT 600)
set_tests_properties("test_spectral_derivative" PROPERTIES TIMEOUT 600)
# Add custom target to launch continuous integration tests
add_custom_target(ci COMMAND ${CMAKE_SOURCE_DIR}/ci/scripts/test.sh ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/hysop)