From ec4ed45c2d97398d7c6c9e183710354c977f1240 Mon Sep 17 00:00:00 2001 From: Jean-Matthieu Etancelin <jean-matthieu.etancelin@imag.fr> Date: Fri, 15 Mar 2013 15:48:33 +0000 Subject: [PATCH] Fix python test discovering --- HySoP/CMake/ParmesTests.cmake | 52 ++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/HySoP/CMake/ParmesTests.cmake b/HySoP/CMake/ParmesTests.cmake index 4c34c8fb6..5f1bd5539 100644 --- a/HySoP/CMake/ParmesTests.cmake +++ b/HySoP/CMake/ParmesTests.cmake @@ -7,14 +7,11 @@ find_python_module(pytest REQUIRED) set(py_src_dirs fields - particular_solvers domain - integrator - obstacle operator - physics problem tools + numerics ) if(USE_MPI) @@ -22,15 +19,57 @@ if(USE_MPI) ${py_src_dirs} mpi) endif() +### JM : Bub, GLOB_RECURSE utilse les chemins relatifs avec ../ +# foreach(testdir ${py_src_dirs}) +# file(GLOB_RECURSE py_test_files "${test_dir}" RELATIVE_PATH parmepy/*/test_*.py) +# endforeach() + +## Build a list of test_*.py files recursively for each directory of parmepy/${py_src_dirs} +set(py_test_files) +foreach(testdir ${py_src_dirs}) + file(GLOB_RECURSE testfiles + RELATIVE ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/parmepy/${testdir}/test_*.py) + set(py_test_files + ${py_test_files} ${testfiles}) +endforeach() + + +## Handling doctest in *.py files recursively for each directory of parmepy/${py_src_dirs} +## that names are not __init__ or test_ and that contains '>>>' +set(py_doctest_files) foreach(testdir ${py_src_dirs}) - file(GLOB_RECURSE py_test_files "${test_dir}" RELATIVE_PATH parmepy/*/test_*.py) + file(GLOB_RECURSE testfiles + RELATIVE ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/parmepy/${testdir}/*.py) + foreach(testfile ${testfiles}) + if(NOT ${testfile} MATCHES "__init__|test_") + file(STRINGS ${testfile} test_doctest + REGEX ">>>") + if(NOT "${test_doctest}" STREQUAL "") + set(py_doctest_files + ${py_doctest_files} ${testfile}) + endif() + endif() + endforeach() endforeach() +## Adding tests +message(STATUS "=== TESTS === ") +## Add test_*.py files foreach(testfile ${py_test_files}) get_filename_component(testName ${testfile} NAME_WE) - message(STATUS "Add test ${testName} ...") + message(STATUS "Add test ${testfile} ...") add_test(${testName} py.test -v ${testfile}) endforeach() +## Add files containing doctests +foreach(testfile ${py_doctest_files}) + get_filename_component(testName ${testfile} NAME_WE) + message(STATUS "Add test from doc doctest_${testName} ...") + add_test("doctest_${testName}" py.test -v ${testfile}) +endforeach() +message(STATUS "===") + #add_test(NAME topology COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 py.test -v ${CMAKE_SOURCE_DIR}/parmepy/mpi/tests/test_topology.py) # add_test(NAME topology COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 py.test -v ${CMAKE_SOURCE_DIR}/parmepy/mpi/tests/test_topology.py) @@ -38,4 +77,3 @@ endforeach() - \ No newline at end of file -- GitLab