diff --git a/Tests/Examples/CMakeLists.txt b/Tests/Examples/CMakeLists.txt index f765127b7578869119b0a11c1179b3f7d3eba7eb..a1848a421f30e2fc30b1308bf93910eec5d2ad38 100644 --- a/Tests/Examples/CMakeLists.txt +++ b/Tests/Examples/CMakeLists.txt @@ -9,18 +9,21 @@ file(MAKE_DIRECTORY ${TEST_OUTPUT_DIR_PY_PERSIST}) # Test scripts #################################################################################################### +macro(parse_example example) + cmake_path(SET EXAMPLE_SCRIPT NORMALIZE ${EXAMPLES_DIR}/${example}.py) + get_filename_component(EXAMPLE_NAME ${EXAMPLE_SCRIPT} NAME_WE) + get_filename_component(EXAMPLE_SUBDIR ${example} DIRECTORY) +endmacro() + # Run one Python example. # Check whether the example executes, don't check results. # If there are matplotlib commands, skip plt.show(). function(run_example example label) - set(script_path ${EXAMPLES_DIR}/${example}.py) - get_filename_component(EXAMPLE_NAME ${script_path} NAME_WE) - + parse_example(${example}) set(test_name Example.run.${EXAMPLE_NAME}) add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND} -E env BA_EXAMPLE_DATA_DIR=${EXAMPLES_DIR}/data - NOSHOW=TRUE ${Python3_EXECUTABLE} ${TOOL_DIR}/code/batch-plot.py -s ${script_path} ${TEST_OUTPUT_DIR_PY_EXAMPLES}) if(NOT label STREQUAL "") @@ -30,9 +33,7 @@ endfunction() # Run examples that don't plot. function(run_noplot example) - cmake_path(SET EXAMPLE_SCRIPT NORMALIZE ${EXAMPLES_DIR}/${example}.py) - get_filename_component(EXAMPLE_NAME ${EXAMPLE_SCRIPT} NAME_WE) - + parse_example(${example}) set(test_name Example.exec.${EXAMPLE_NAME}) add_test(NAME ${test_name} COMMAND ${Python3_EXECUTABLE} -B ${EXAMPLE_SCRIPT} @@ -41,10 +42,7 @@ endfunction() # Python equality test: run modified example, and compare with reference data of another example function(test_equality example reference tolerance) - cmake_path(SET EXAMPLE_SCRIPT NORMALIZE ${EXAMPLES_DIR}/${example}.py) - get_filename_component(EXAMPLE_NAME ${EXAMPLE_SCRIPT} NAME_WE) - get_filename_component(EXAMPLE_SUBDIR ${example} DIRECTORY) - + parse_example(${example}) set(test_name Example.persist.${EXAMPLE_NAME}) add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND}