mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
test installed pybind
This commit is contained in:
parent
545b4dbc19
commit
eb09af5e58
@ -30,3 +30,4 @@ build_script:
|
||||
- cmake -A "%CMAKE_ARCH%" -DPYBIND11_WERROR=ON
|
||||
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||
- cmake --build . --config Release --target pytest -- /v:m /logger:%MSBuildLogger%
|
||||
- cmake --build . --config Release --target test_install -- /v:m /logger:%MSBuildLogger%
|
||||
|
@ -110,5 +110,6 @@ script:
|
||||
-DPYBIND11_CPP_STANDARD=$CPP
|
||||
-DPYBIND11_WERROR=ON
|
||||
- $SCRIPT_RUN_PREFIX make pytest -j 2
|
||||
- $SCRIPT_RUN_PREFIX make test_install
|
||||
after_script:
|
||||
- if [ -n "$DOCKER" ]; then docker stop "$containerid"; docker rm "$containerid"; fi
|
||||
|
@ -105,6 +105,54 @@ if(PYBIND11_TEST_OVERRIDE)
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Note: not all tests run: -DPYBIND11_TEST_OVERRIDE is in effect")
|
||||
endif()
|
||||
|
||||
# test use of installation
|
||||
if(PYBIND11_INSTALL)
|
||||
# 2.8.12 needed for test_installed_module
|
||||
# 3.0 needed for interface library for test_installed_target
|
||||
# 3.1 needed for cmake -E env for testing
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
|
||||
add_custom_target(test_installed_target
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
"-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/test_install"
|
||||
-P "${PROJECT_BINARY_DIR}/cmake_install.cmake"
|
||||
COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test "${CMAKE_CURRENT_SOURCE_DIR}/test_installed_target"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test_installed_target"
|
||||
--build-noclean
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
$<$<BOOL:${CMAKE_GENERATOR_PLATFORM}>:--build-generator-platform> ${CMAKE_GENERATOR_PLATFORM}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-target check
|
||||
--build-options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/test_install"
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
|
||||
"-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}"
|
||||
)
|
||||
add_custom_target(test_installed_module
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
"-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/test_install"
|
||||
-P "${PROJECT_BINARY_DIR}/cmake_install.cmake"
|
||||
COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test "${CMAKE_CURRENT_SOURCE_DIR}/test_installed_module"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test_installed_module"
|
||||
--build-noclean
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
$<$<BOOL:${CMAKE_GENERATOR_PLATFORM}>:--build-generator-platform> ${CMAKE_GENERATOR_PLATFORM}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-target check
|
||||
--build-options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/test_install"
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
|
||||
"-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}"
|
||||
)
|
||||
else()
|
||||
add_custom_target(test_installed_target)
|
||||
add_custom_target(test_installed_module)
|
||||
endif()
|
||||
add_custom_target(test_install)
|
||||
add_dependencies(test_install test_installed_target test_installed_module)
|
||||
endif()
|
||||
|
||||
# And another to show the .so size and, if a previous size, compare it:
|
||||
add_custom_command(TARGET pybind11_tests POST_BUILD
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/libsize.py
|
||||
|
14
tests/test_installed_module/CMakeLists.txt
Normal file
14
tests/test_installed_module/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project(test_installed_module CXX)
|
||||
|
||||
set(CMAKE_MODULE_PATH "")
|
||||
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
|
||||
message(STATUS "Found pybind11: ${pybind11_INCLUDE_DIRS} (found version ${pybind11_VERSION})")
|
||||
message(STATUS "Found Python: ${PYTHON_INCLUDE_DIRS} (found version ${PYTHON_VERSION_STRING})")
|
||||
|
||||
pybind11_add_module(test_installed_module SHARED main.cpp)
|
||||
|
||||
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_installed_module>
|
||||
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test.py)
|
10
tests/test_installed_module/main.cpp
Normal file
10
tests/test_installed_module/main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_PLUGIN(test_installed_module) {
|
||||
py::module m("test_installed_module");
|
||||
|
||||
m.def("add", [](int i, int j) { return i + j; });
|
||||
|
||||
return m.ptr();
|
||||
}
|
3
tests/test_installed_module/test.py
Normal file
3
tests/test_installed_module/test.py
Normal file
@ -0,0 +1,3 @@
|
||||
import test_installed_module
|
||||
assert test_installed_module.add(11, 22) == 33
|
||||
print('test_installed_module imports, runs, and adds: 11 + 22 = 33')
|
20
tests/test_installed_target/CMakeLists.txt
Normal file
20
tests/test_installed_target/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(test_installed_target CXX)
|
||||
|
||||
set(CMAKE_MODULE_PATH "")
|
||||
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
|
||||
message(STATUS "Found pybind11: ${pybind11_INCLUDE_DIRS} (found version ${pybind11_VERSION})")
|
||||
message(STATUS "Found Python: ${PYTHON_INCLUDE_DIRS} (found version ${PYTHON_VERSION_STRING})")
|
||||
|
||||
add_library(test_installed_target MODULE main.cpp)
|
||||
|
||||
target_link_libraries(test_installed_target PRIVATE pybind11::pybind11)
|
||||
|
||||
# make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib
|
||||
set_target_properties(test_installed_target PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
|
||||
SUFFIX "${PYTHON_MODULE_EXTENSION}")
|
||||
|
||||
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_installed_target>
|
||||
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test.py)
|
10
tests/test_installed_target/main.cpp
Normal file
10
tests/test_installed_target/main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_PLUGIN(test_installed_target) {
|
||||
py::module m("test_installed_target");
|
||||
|
||||
m.def("add", [](int i, int j) { return i + j; });
|
||||
|
||||
return m.ptr();
|
||||
}
|
3
tests/test_installed_target/test.py
Normal file
3
tests/test_installed_target/test.py
Normal file
@ -0,0 +1,3 @@
|
||||
import test_installed_target
|
||||
assert test_installed_target.add(1, 2) == 3
|
||||
print('test_installed_target imports, runs, and adds: 1 + 2 = 3')
|
Loading…
Reference in New Issue
Block a user