Add sample_restraint Python tests to `check` target.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Tue, 13 Aug 2019 12:06:59 +0000 (15:06 +0300)
committerEric Irrgang <ericirrgang@gmail.com>
Tue, 27 Aug 2019 17:28:19 +0000 (19:28 +0200)
When building as part of the GROMACS project (not as a standalone
project), add a CMake testing target to invoke pytest for the
sample_restraint package. Include this target in the GROMACS project
`check` target. Make some minor CMake infrastructure changes to help
the sample_restraint tests find the gmxapi Python package.

Change-Id: I753951c1bb5f5a9c6caa20d4d632eba214895a1f

python_packaging/sample_restraint/CMakeLists.txt
python_packaging/sample_restraint/tests/CMakeGROMACS.txt [new file with mode: 0644]
python_packaging/sample_restraint/tests/CMakeLists.txt
python_packaging/src/CMakeLists.txt

index 8274a1ebe2eebc3f931c1e38bdb5fd18e48305ea..338d729f31c525a77c2456f0723a2a5e1d46ac00 100644 (file)
@@ -196,6 +196,7 @@ add_subdirectory(src)
 add_subdirectory(docs)
 
 # Process CMake configuration for Python and C++ tests.
+include(CTest)
 if(BUILD_TESTING)
     include(GoogleTest)
     add_subdirectory(tests)
diff --git a/python_packaging/sample_restraint/tests/CMakeGROMACS.txt b/python_packaging/sample_restraint/tests/CMakeGROMACS.txt
new file mode 100644 (file)
index 0000000..92ffe7e
--- /dev/null
@@ -0,0 +1,32 @@
+# This file holds some additional scripting that is used for the automated
+# testing of the GROMACS project. The file is only processed when building as
+# part of the full GROMACS build.
+
+
+# Make sure pytest is found or produce a fatal error
+if(NOT GMXAPI_PYTEST_FOUND)
+    execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pytest; print(pytest.__version__)"
+                    RESULT_VARIABLE pytest_not_found OUTPUT_VARIABLE pytest_version ERROR_QUIET)
+    if(pytest_not_found)
+        message(FATAL_ERROR "Running the tests requires pytest. Please install it manually"
+                " (try: ${PYTHON_EXECUTABLE} -m pip install pytest)")
+    elseif(pytest_version VERSION_LESS 3.0)
+        message(FATAL_ERROR "Running the tests requires pytest >= 3.0. Found: ${pytest_version}"
+                "Please update it (try: ${PYTHON_EXECUTABLE} -m pip install -U pytest)")
+    endif()
+    set(GMXAPI_PYTEST_FOUND TRUE CACHE INTERNAL "Suppress checking for Python pytest module.")
+endif()
+
+# TODO: (#2961) Let the Python package discover required resources instead of passing GMXBIN
+get_target_property(GMXBIN gmx RUNTIME_OUTPUT_DIRECTORY)
+get_target_property(GMXAPI_PYTHON_STAGING_DIR _gmxapi staging_dir)
+get_target_property(PLUGINPATH sampleplugin LIBRARY_OUTPUT_DIRECTORY)
+add_custom_target(gmxapi_extension_pytest
+                  COMMAND ${CMAKE_COMMAND} -E env GMXBIN=${GMXBIN} PYTHONPATH=${GMXAPI_PYTHON_STAGING_DIR}
+                  ${PYTHON_EXECUTABLE} -m pytest --log-cli-level ERROR ${CMAKE_CURRENT_SOURCE_DIR}
+                  DEPENDS sampleplugin _gmxapi
+                  WORKING_DIRECTORY ${PLUGINPATH})
+# The current test fixtures require the `gmx` tool-wrapper executable.
+add_dependencies(gmxapi_extension_pytest gmx)
+
+add_dependencies(check gmxapi_extension_pytest)
index 90157decdc0c00941260ad0ad243531ed0ca21c3..d19bd3570ab3e9a45d18d232341ce145bf3b3a50 100644 (file)
@@ -89,3 +89,7 @@ target_link_libraries(bounding-test ensemblepotential Gromacs::gmxapi
                       GTest::Main)
 gtest_add_tests(TARGET bounding-test
                 TEST_LIST EnsembleBoundingPotentialPlugin)
+
+if (NOT GMXAPI_EXTENSION_MASTER_PROJECT)
+    include(CMakeGROMACS.txt)
+endif ()
index e81d36ef2467865271f9d78b6f0f7bd75b48f11c..79e5e0cb2b28b659b884d5714156a52c90902c87 100644 (file)
@@ -176,12 +176,12 @@ else()
         file(RELATIVE_PATH _relative_dir ${CMAKE_CURRENT_SOURCE_DIR} ${_absolute_dir})
         file(COPY ${_package_file} DESTINATION gmxapi_staging/${_relative_dir})
     endforeach()
-    file(COPY setup.py CMakeLists.txt DESTINATION gmxapi_staging)
+    file(COPY setup.py CMakeLists.txt DESTINATION ${GMXAPI_PYTHON_STAGING_DIR})
     # Set CMake variable pybind11_DIR to ${CMAKE_CURRENT_SOURCE_DIR}/external/pybind/tools
     # if re-invoking CMake (including via Python setuptools) for the files in gmxapi_staging.
 
-    # Unit test and build docs using PYTHONPATH=$CMAKE_CURRENT_BINARY_DIR/gmxapi_staging/gmxapi
-
+    # Unit test and build docs using PYTHONPATH=$CMAKE_CURRENT_BINARY_DIR/gmxapi_staging
+    set_target_properties(_gmxapi PROPERTIES staging_dir ${GMXAPI_PYTHON_STAGING_DIR})
     # Note: Integration testing for multiple Python versions and/or CMake-driven
     # sdist preparation could be performed with CMake custom_commands and custom_targets.
 endif()