Skip to content
Snippets Groups Projects

Bugfix/overhaul dune python add test

Merged Samuel Burbulla requested to merge bugfix/overhaul-dune-python-add-test into master
Compare and
9 files
+ 119
66
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -2,6 +2,18 @@
#
# .. cmake_function:: dune_python_add_test
#
# .. cmake_brief::
#
# Integrates a python testing framework command into the Dune
# build system. Added commands are run, when the target
# :code:`test_python` is built and during :code:`ctest`.
#
# .. cmake_param:: NAME
# :single:
#
# A name to identify this test in ctest. Names must be unique throughout
# the project. If omitted, defaults to mangling of the command.
#
# .. cmake_param:: SCRIPT
# :multi:
#
@@ -16,14 +28,21 @@
# .. cmake_param:: MODULE
# :multi:
#
# The Python module to be executed. It will be executed during :code:`make test_python`
# and during `ctest`. You are required to either pass SCRIPT or MODULE.
# The Python module to be executed. It will be executed during :code:`make test_python`
# and during `ctest`.
#
# You are required to either pass SCRIPT or MODULE.
#
# .. note::
#
# The script will be executed using :code:`${Python3_EXECUTABLE} -m MODULE`. If the INTERPRETER
# option is given, that interpreter is used instead.
#
# .. cmake_param:: INTERPRETER
# :single:
#
# The Python interpreter to be used. Defaults to :code:`${DUNE_PYTHON_VIRTUALENV_EXECUTABLE}`.
#
# .. cmake_param:: WORKING_DIRECTORY
# :single:
# :argname: dir
@@ -31,23 +50,52 @@
# The working directory of the command. Defaults to
# the current build directory.
#
# .. cmake_param:: NAME
# :single:
# .. cmake_param:: LABELS
# :multi:
#
# A name to identify this test in ctest. Names must be unique throughout
# the project. If omitted, defaults to mangling of the command.
# A list of labels to add to the test.
#
# .. cmake_param:: CMAKE_GUARD
# :multi:
# :argname: condition
#
# A number of conditions that CMake should evaluate before adding this
# test. If one of the conditions fails, the test should be shown
# as skipped in the test summary. Use this feature instead of guarding
# the call to :code:`dune_add_test` with an :code:`if` clause.
#
# The passed condition can be a complex expression like
# `( A OR B ) AND ( C OR D )`. Mind the spaces around the parentheses.
#
# Example: Write CMAKE_GUARD dune-foo_FOUND if you want your test to only
# build and run when the dune-foo module is present.
#
# .. cmake_param:: MPI_RANKS
# :multi:
# :argname: ranks
#
# The numbers of cores that this test should be executed with.
# Note that one test (in the ctest sense) is created for each number
# given here. Any number exceeding the user-specified processor maximum
# :ref:`DUNE_MAX_TEST_CORES` will be ignored. Tests with a
# processor number :code:`n` higher than one will have the suffix
# :code:`-mpi-n` appended to their name. You need to specify the
# TIMEOUT option when specifying the MPI_RANKS option.
#
# .. cmake_param:: TIMEOUT
# :single:
#
# Integrates a python testing framework command into the Dune
# build system. Added commands are run, when the target
# :code:`test_python` is built and during :code:`ctest`.
# If set, the test will time out after the given number of seconds. This supersedes
# any timeout setting in ctest (see `cmake --help-property TIMEOUT`). If you
# specify the MPI_RANKS option, you need to specify a TIMEOUT.
#
include_guard(GLOBAL)
function(dune_python_add_test)
# Parse Arguments
set(OPTION)
set(SINGLE WORKING_DIRECTORY NAME)
set(MULTI SCRIPT COMMAND LABELS MODULE)
set(SINGLE NAME WORKING_DIRECTORY INTERPRETER)
set(MULTI SCRIPT MODULE COMMAND LABELS CMAKE_GUARD MPI_RANKS TIMEOUT)
cmake_parse_arguments(PYTEST "" "${SINGLE}" "${MULTI}" ${ARGN})
if(PYTEST_COMMAND)
message(FATAL_ERROR "dune_python_add_test: COMMAND argument should not be used, use SCRIPT instead providing only the Python script and not the Python interpreter")
@@ -77,33 +125,23 @@ function(dune_python_add_test)
set(commandstr "${commandstr}_${PYTEST_WORKING_DIRECTORY}")
string(REPLACE "/" "_" PYTEST_NAME ${commandstr})
endif()
if(DUNE_PYTHON_VENVSETUP)
# Actually run the command
add_custom_target(target_${PYTEST_NAME}
COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env python ${PYTEST_SCRIPT}
WORKING_DIRECTORY ${PYTEST_WORKING_DIRECTORY})
else()
# message(FATAL_ERROR "SHOULDN'T BE HERE")
# add_custom_target(target_${PYTEST_NAME}
# COMMAND ${CMAKE_COMMAND} -E echo \"Test not run: python setup failed\")
add_custom_target(target_${PYTEST_NAME}
COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env python ${PYTEST_SCRIPT}
WORKING_DIRECTORY ${PYTEST_WORKING_DIRECTORY})
+2
if(NOT PYTEST_INTERPRETER)
set(PYTEST_INTERPRETER ${DUNE_PYTHON_VIRTUALENV_EXECUTABLE})
endif()
add_custom_target(target_${PYTEST_NAME})
dune_add_test(NAME ${PYTEST_NAME}
TARGET target_${PYTEST_NAME}
COMMAND ${PYTEST_INTERPRETER}
CMD_ARGS ${PYTEST_SCRIPT}
PYTHON_TEST
WORKING_DIRECTORY ${PYTEST_WORKING_DIRECTORY}
LABELS ${PYTEST_LABELS}
CMAKE_GUARD ${PYTEST_CMAKE_GUARD}
MPI_RANKS ${PYTEST_MPI_RANKS}
TIMEOUT ${PYTEST_TIMEOUT}
)
# Build this during make test_python
add_dependencies(test_python target_${PYTEST_NAME})
# make sure each label exists and its name is acceptable
dune_declare_test_label(LABELS ${PYTEST_LABELS})
# Also build this during ctest
_add_test(NAME ${PYTEST_NAME}
COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env python ${PYTEST_SCRIPT}
WORKING_DIRECTORY ${PYTEST_WORKING_DIRECTORY}
)
set_tests_properties(${PYTEST_NAME} PROPERTIES SKIP_RETURN_CODE 77)
# Set the labels on the test
set_tests_properties(${PYTEST_NAME} PROPERTIES LABELS "${PYTEST_LABELS}")
endfunction()
Loading