From 25d7b0029d67a61865d4ea2ee6fee0bcd5740e3c Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Fri, 23 Nov 2012 09:43:16 +0000 Subject: [PATCH] Include helper code for Python unit tests... Refs #6219. in an analogous way that it is done with cxxtest_add_test. --- Code/Mantid/Build/CMake/FindPyUnitTest.cmake | 15 +++++++++++++- .../Framework/PythonInterface/CMakeLists.txt | 20 +++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Code/Mantid/Build/CMake/FindPyUnitTest.cmake b/Code/Mantid/Build/CMake/FindPyUnitTest.cmake index 273b9cbf99b..0d14ea8dddc 100644 --- a/Code/Mantid/Build/CMake/FindPyUnitTest.cmake +++ b/Code/Mantid/Build/CMake/FindPyUnitTest.cmake @@ -25,9 +25,22 @@ macro ( PYUNITTEST_ADD_TEST _pyunit_testname_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} + 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} + 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} diff --git a/Code/Mantid/Framework/PythonInterface/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/CMakeLists.txt index c6dc817524d..7e2f6438899 100644 --- a/Code/Mantid/Framework/PythonInterface/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/CMakeLists.txt @@ -55,6 +55,7 @@ add_subdirectory ( mantid ) ########################################################################### # Python algorithms ########################################################################### +clean_orphaned_pyc_files ( ${CMAKE_CURRENT_SOURCE_DIR}/PythonAlgorithms ) add_compile_py_target( PythonAlgorithms ${CMAKE_CURRENT_SOURCE_DIR}/PythonAlgorithms ) add_dependencies( PythonAPIModule PythonAlgorithms ) @@ -146,27 +147,16 @@ set ( TEST_PY_FILES test/python/WorkspaceValidatorsTest.py ) -set ( PYTEST_HELPERS test/python/testhelpers.py ) # python unit tests if (PYUNITTEST_FOUND) + # pyunittest_add_test macro understands the TESTHELPER_PY_FILES variable. It is scoped to this file + # so does not need to be cleared + set ( TESTHELPER_PY_FILES test/python/testhelpers.py ) pyunittest_add_test ( VanillaPythonInterfaceTest.py ${TEST_PY_FILES} ) - # Helpers - set ( VANILLA_TEST_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/VanillaPythonInterfaceTest ) - set ( PYTEST_HELPER_INSTALLS "" ) - foreach( PYTEST_HELPER ${PYTEST_HELPERS} ) - get_filename_component(helper_file ${PYTEST_HELPER} NAME) - add_custom_command ( OUTPUT ${VANILLA_TEST_DIR}/${helper_file} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${PYTEST_HELPER} - COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different - ${CMAKE_CURRENT_SOURCE_DIR}/${PYTEST_HELPER} - ${VANILLA_TEST_DIR}/${helper_file} ) - set ( PYTEST_HELPER_INSTALLS ${PYTEST_HELPER_INSTALLS} ${VANILLA_TEST_DIR}/${helper_file} ) - endforeach( PYTEST_HELPER ${PYTEST_HELPERS} ) - add_custom_target ( PythonTestHelpers DEPENDS ${PYTEST_HELPER_INSTALLS} ) # Test Dependencies - add_dependencies ( VanillaPythonInterfaceTest.py PythonInterface Algorithms PythonTestHelpers ) + add_dependencies ( VanillaPythonInterfaceTest.py PythonInterface Algorithms ) add_dependencies ( FrameworkTests VanillaPythonInterfaceTest.py ) # Add to the 'UnitTests' group in VS set_property ( TARGET VanillaPythonInterfaceTest.py PROPERTY FOLDER "UnitTests" ) -- GitLab