Skip to content

Commit

Permalink
Remove old pyunittest macro and switch names. Refs #6263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Dec 4, 2012
1 parent b4a522e commit ddb8034
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 96 deletions.
82 changes: 2 additions & 80 deletions Code/Mantid/Build/CMake/FindPyUnitTest.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# PYUNITTEST_ADD_TEST_TWO (public macro to add unit tests)
# PYUNITTEST_ADD_TEST (public macro to add unit tests)
# Adds a set of python tests based upon the unittest module
# Parameters:
# _test_src_dir :: The directory where the src files reside
# _testname_prefix :: A prefix for each test that is added to ctest, the name will be
# ${_testname_prefix}_TestName
# ${ARGN} :: List of test files
macro ( PYUNITTEST_ADD_TEST_TWO _test_src_dir _testname_prefix )
macro ( PYUNITTEST_ADD_TEST _test_src_dir _testname_prefix )
# Property for the module directory
if ( MSVC )
set ( _module_dir ${CMAKE_BINARY_DIR}/bin/Release )
Expand Down Expand Up @@ -57,84 +57,6 @@ macro ( PYUNITTEST_ADD_TEST_TWO _test_src_dir _testname_prefix )
PROPERTY WORKING_DIRECTORY ${_working_dir} )
endif()
endforeach ( part ${ARGN} )
endmacro ( PYUNITTEST_ADD_TEST_TWO )


macro ( PYUNITTEST_ADD_TEST _pyunit_testname_file )
# decide where to copy the unit tests
get_filename_component ( _pyunit_testname ${_pyunit_testname_file} NAME_WE )
set ( _pyunit_outputdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${_pyunit_testname} )

# Add a special target to prepare the output directory. It needs to be run everytime the
# main target is run so we can flush out any tests that may have been removed from the source tree but
# still reside in the build
add_custom_target ( Prepare${_pyunit_testname_file}
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${_pyunit_testname_file}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${_pyunit_outputdir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_pyunit_outputdir}
COMMAND ${CMAKE_COMMAND} -E touch ${_pyunit_outputdir}/__init__.py
)

# Copy the unit test files
set ( _pyunit_testfiles "" )
foreach (part ${ARGN})
get_filename_component(_pyunit_file ${part} NAME)
add_custom_command ( OUTPUT ${_pyunit_outputdir}/${_pyunit_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${part}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/${part}
${_pyunit_outputdir}/${_pyunit_file} )
set ( _pyunit_testfiles ${_pyunit_testfiles} ${_pyunit_outputdir}/${_pyunit_file} )
endforeach (part ${ARGN})

# The TESTHELPER_PY_FILES variable can be used outside of this macro
# to include any helper classes that are not run through the python unittest generator
set ( _testhelper_files "" )
foreach (part ${TESTHELPER_PY_FILES})
get_filename_component(_testhelper_file ${part} NAME)
add_custom_command ( OUTPUT ${_pyunit_outputdir}/${_testhelper_file} ${_pyunit_outputdir}/__init__.py
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${part}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/${part}
${_pyunit_outputdir}/${_testhelper_file} )
set ( _testhelper_files ${_testhelper_files} ${_pyunit_outputdir}/${_testhelper_file} )
endforeach (part ${ARGN})

# Main test target
add_custom_target ( ${_pyunit_testname_file}
DEPENDS ${_pyunit_testfiles} ${_testhelper_files}
COMMAND ${PYTHON_EXECUTABLE} ${PYUNITTEST_GEN_EXEC}
-o ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${_pyunit_testname_file}
-d ${_pyunit_outputdir}
--xmlrunner=${PYUNITTEST_XMLRUNNER}
--python="${PYTHON_EXECUTABLE}" )
# Make sure the directory is flushed each time before it is rebuilt
add_dependencies( ${_pyunit_testname_file} Prepare${_pyunit_testname_file} )
set_source_files_properties( ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${_pyunit_testname_file}
PROPERTIES GENERATED true)

if( MSVC )
# We need to call the debug executable for the debug builds
add_test (NAME ${_pyunit_testname}_py_Debug CONFIGURATIONS Debug
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}/bin/Debug"
${PYTHON_EXECUTABLE_DEBUG} -B $<TARGET_FILE_DIR:PythonAPI>/${_pyunit_testname_file} )
add_test (NAME ${_pyunit_testname}_py CONFIGURATIONS Release
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}/bin/Release"
${PYTHON_EXECUTABLE} -B $<TARGET_FILE_DIR:PythonAPI>/${_pyunit_testname_file} )
else()
add_test (NAME ${_pyunit_testname}_py
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}/bin"
${PYTHON_EXECUTABLE} -B $<TARGET_FILE_DIR:PythonAPI>/${_pyunit_testname_file} )
endif()

# add all of the individual tests - this introduces a race condition
#foreach (part ${ARGN})
# get_filename_component(_suitename ${part} NAME_WE)
# set (_pyunit_separate_name "${_pyunit_testname}_${_suitename}")
# add_test ( NAME ${_pyunit_separate_name}
# COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}/bin"
# ${PYTHON_EXECUTABLE} ${_pyunit_testname_file} ${_suitename} )
#endforeach (part ${ARGN})
endmacro ( PYUNITTEST_ADD_TEST )

#=============================================================
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ endif ()

# python unit tests
if (PYUNITTEST_FOUND)
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} AlgorithmsPythonTest ${TEST_PY_FILES} )
pyunittest_add_test( ${CMAKE_CURRENT_SOURCE_DIR} AlgorithmsPythonTest ${TEST_PY_FILES} )
endif ()

2 changes: 1 addition & 1 deletion Code/Mantid/Framework/PythonAPI/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ endif ()
# Python unit tests
if (PYUNITTEST_FOUND)
# Add test targets
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonAPI ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonAPI ${TEST_PY_FILES} )
endif ()

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Python tests for each subpackage and the PythonAlgorithms
##
if (PYUNITTEST_FOUND)
# pyunittest_add_test_two understands this macro and adds it to the PYTHONPATH for each test
# pyunittest_add_test understands this macro and adds it to the PYTHONPATH for each test
set ( TESTHELPER_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} )

add_subdirectory( mantid )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ set ( TEST_PY_FILES
)

# Prefix for test name=PythonAlgorithms
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonAlgorithms ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonAlgorithms ${TEST_PY_FILES} )
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ set ( TEST_PY_FILES
)

# Prefix for test=PythonInterface
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterface ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterface ${TEST_PY_FILES} )
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ set ( TEST_PY_FILES
)

# Prefix for test=PythonInterfaceAPI
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterfaceAPI ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterfaceAPI ${TEST_PY_FILES} )
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ set ( TEST_PY_FILES
)

# Prefix for test=PythonInterfaceGeometry
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterfaceGeometry ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterfaceGeometry ${TEST_PY_FILES} )
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ set ( TEST_PY_FILES
)

# Prefix for test=PythonInterfaceKernel
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterfaceKernel ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonInterfaceKernel ${TEST_PY_FILES} )
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ endif ()

# python unit tests
if (PYUNITTEST_FOUND)
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR} PythonWorkflowAlgorithmsTest ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR} PythonWorkflowAlgorithmsTest ${TEST_PY_FILES} )
endif ()

8 changes: 2 additions & 6 deletions Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ target_link_libraries ( MantidQtSliceViewer MantidQtAPI MantidWidgets ${QT_LIBRA
###########################################################################

if ( PYUNITTEST_FOUND )
pyunittest_add_test ( SliceViewerMantidPlotTest.py ${TEST_PY_FILES} "" )
add_dependencies ( SliceViewerMantidPlotTest.py MantidQtAPI MantidWidgets CustomDialogs
CustomInterfaces MantidQtSliceViewer Algorithms )
add_dependencies ( GUITests SliceViewerMantidPlotTest.py )
# Add to the 'UnitTests' group in VS
set_property ( TARGET SliceViewerMantidPlotTest.py PROPERTY FOLDER "UnitTests" )

pyunittest_add_test (${CMAKE_CURRENT_SOURCE_DIR}/test SliceViewerMantidPlotTest ${TEST_PY_FILES} )
endif ()

if ( CXXTEST_FOUND )
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set ( TEST_PY_FILES test/ReducerTest.py )

# python unit tests
if (PYUNITTEST_FOUND)
pyunittest_add_test_two ( ${CMAKE_CURRENT_SOURCE_DIR}/test PythonScriptsTest ${TEST_PY_FILES} )
pyunittest_add_test ( ${CMAKE_CURRENT_SOURCE_DIR}/test PythonScriptsTest ${TEST_PY_FILES} )
endif ()

# Ensure we don't get stale pyc files around
Expand Down

0 comments on commit ddb8034

Please sign in to comment.