Skip to content

Commit

Permalink
Fix execution of unit tests
Browse files Browse the repository at this point in the history
- Executables for Python testing tools which are essentially MRtrix3
Python commands (e.g. they are defined by a usage and run function), are
generated using the MakePythonExecutable script.

- Additionally, some renaming of variables has been performed for
consistency.
  • Loading branch information
daljit46 committed Jun 20, 2024
1 parent 6f2948a commit 1f1fb1d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
45 changes: 31 additions & 14 deletions testing/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,48 @@ set(CPP_TOOLS_SRCS
)

set(PYTHON_TOOLS_SRCS
testing_check_npy
testing_gen_npy
testing_python_cli
testing_check_npy.py
testing_gen_npy.py
testing_python_cli.py
)

add_custom_target(testing_tools)
add_custom_target(testing_tools ALL)

function(add_testing_cmd CMD_SRC)
function(add_cpp_tool TOOL_SRC)
# Extract the filename without an extension (NAME_WE)
get_filename_component(CMD_NAME ${CMD} NAME_WE)
add_executable(${CMD_NAME} ${CMD})
target_link_libraries(${CMD_NAME} PRIVATE
get_filename_component(TOOL_NAME ${TOOL_SRC} NAME_WE)
add_executable(${TOOL_NAME} ${TOOL_SRC})
target_link_libraries(${TOOL_NAME} PRIVATE
mrtrix::headless
mrtrix::exec-version-lib
mrtrix::tests-lib
)
set_target_properties(${CMD_NAME} PROPERTIES LINK_DEPENDS_NO_SHARED true)
add_dependencies(testing_tools ${CMD_NAME})
set_target_properties(${TOOL_NAME} PROPERTIES LINK_DEPENDS_NO_SHARED true)
add_dependencies(testing_tools ${TOOL_NAME})
endfunction()

function(add_python_tool TOOL_SRC IS_MRTRIX_CMD)
get_filename_component(TOOL_NAME ${TOOL_SRC} NAME_WE)
# If the tool behaves like a Python MRtrix3 command, then we need to generate its executable using
# the MakePythonExecutable script
if(IS_MRTRIX_CMD)
set(MRTRIX_PYTHON_LIB_PATH "${PROJECT_BINARY_DIR}/lib")
add_custom_command(
TARGET testing_tools PRE_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -DCMDNAME=${TOOL_NAME} -DOUTPUT_DIR="${CMAKE_CURRENT_BINARY_DIR}" -DEXTRA_PATH_DIRS="${MRTRIX_PYTHON_LIB_PATH}" -P ${PROJECT_SOURCE_DIR}/cmake/MakePythonExecutable.cmake
)
# Install "module" file alongside the executable
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TOOL_SRC} ${CMAKE_CURRENT_BINARY_DIR}/${TOOL_SRC} COPYONLY)
else()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TOOL_SRC} ${CMAKE_CURRENT_BINARY_DIR}/${TOOL_NAME} COPYONLY)
endif()
endfunction()

foreach(CMD ${CPP_TOOLS_SRCS})
add_testing_cmd(${CMD})
add_cpp_tool(${CMD})
endforeach(CMD)

foreach(CMD ${PYTHON_TOOLS_SRCS})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${CMD} ${CMAKE_CURRENT_BINARY_DIR}/${CMD} COPYONLY)
endforeach(CMD)
add_python_tool(testing_check_npy.py FALSE)
add_python_tool(testing_gen_npy.py FALSE)
add_python_tool(testing_python_cli.py TRUE)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,3 @@ def execute(): #pylint: disable=unused-variable
value = getattr(app.ARGS, key)
if value is not None:
app.console(f'{key}: {repr(value)}')



# Execute the script
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member

0 comments on commit 1f1fb1d

Please sign in to comment.