Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port test suite to pytest #321

Merged
merged 8 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ platform:
- x86
- x64
environment:
CTEST_OUTPUT_ON_FAILURE: 1
matrix:
- CONDA: 27
- CONDA: 35
Expand All @@ -16,12 +15,12 @@ install:
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
pip install --disable-pip-version-check --user --upgrade pip wheel
pip install numpy scipy
pip install pytest numpy scipy
} elseif ($env:CONDA) {
if ($env:CONDA -eq "27") { $env:CONDA = "" }
if ($env:PLATFORM -eq "x64") { $env:CONDA = "$env:CONDA-x64" }
$env:PATH = "C:\Miniconda$env:CONDA\;C:\Miniconda$env:CONDA\Scripts\;$env:PATH"
conda install -y -q numpy scipy
conda install -y -q pytest numpy scipy
}
- ps: |
Start-FileDownload 'http://bitbucket.org/eigen/eigen/get/3.2.9.zip'
Expand All @@ -30,4 +29,4 @@ install:
build_script:
- cmake -A "%CMAKE_ARCH%" -DPYBIND11_WERROR=ON
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cmake --build . --config Release --target check -- /v:m /logger:%MSBuildLogger%
- cmake --build . --config Release --target pytest -- /v:m /logger:%MSBuildLogger%
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ CMakeFiles
Makefile
cmake_install.cmake
.DS_Store
/example/example*.so
/example/example.cpython*.so
/example/example.pyd
/example/example*.dll
*.so
*.pyd
*.dll
*.sln
*.sdf
*.opensdf
Expand All @@ -32,3 +31,4 @@ MANIFEST
/dist
/build
/cmake/
.cache/
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ matrix:
install:
- >
docker exec --tty "$containerid" apt-get -y --no-install-recommends install
python2.7-dev python-scipy libeigen3-dev
python2.7-dev python-pip python-setuptools python-scipy libeigen3-dev
cmake make g++
- compiler: gcc-6
services: docker
Expand All @@ -48,7 +48,7 @@ matrix:
install:
- >
docker exec --tty "$containerid" apt-get -y --no-install-recommends install
python3.5-dev python3-scipy libeigen3-dev
python3.5-dev python3-pip python3-setuptools python3-scipy libeigen3-dev
cmake make g++
# Documentation build:
- os: linux
Expand Down Expand Up @@ -98,12 +98,12 @@ install:

wget -q -O eigen.tar.gz https://bitbucket.org/eigen/eigen/get/3.2.9.tar.gz
tar xzf eigen.tar.gz
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_INCLUDE_PATH=eigen-eigen-dc6cfdf9bcec"
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_INCLUDE_PATH=$PWD/eigen-eigen-dc6cfdf9bcec"
script:
- $SCRIPT_RUN_PREFIX cmake ${CMAKE_EXTRA_ARGS}
-DPYBIND11_PYTHON_VERSION=$PYTHON
-DPYBIND11_CPP_STANDARD=-std=c++$CPP
-DPYBIND11_WERROR=ON
- $SCRIPT_RUN_PREFIX make CTEST_OUTPUT_ON_FAILURE=TRUE check -j 2
- $SCRIPT_RUN_PREFIX make pytest -j 2
after_script:
- if [ -n "$DOCKER" ]; then docker stop "$containerid"; docker rm "$containerid"; fi
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CMakeLists.txt -- Build system for the pybind11 examples
# CMakeLists.txt -- Build system for the pybind11 modules
#
# Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
#
Expand All @@ -20,7 +20,7 @@ option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJE
option(PYBIND11_WERROR "Report all warnings as errors" OFF)

# Add a CMake parameter for choosing a desired Python version
set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling the example application")
set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling modules")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools")
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7)
Expand Down Expand Up @@ -146,17 +146,15 @@ function(pybind11_enable_warnings target_name)

if(PYBIND11_WERROR)
if(MSVC)
target_compile_options(${target_name} PRIVATE /WX)
target_compile_options(${target_name} PRIVATE /WX)
else()
target_compile_options(${target_name} PRIVATE -Werror)
target_compile_options(${target_name} PRIVATE -Werror)
endif()
endif()
endfunction()

if (PYBIND11_TEST)
enable_testing()
add_subdirectory(example)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> DEPENDS example)
add_subdirectory(tests)
endif()

if (PYBIND11_INSTALL)
Expand Down
36 changes: 18 additions & 18 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ C++ side, or to perform other types of customization.

.. seealso::

The file :file:`example/example-operator-overloading.cpp` contains a
The file :file:`tests/test_operator_overloading.cpp` contains a
complete example that demonstrates how to work with overloaded operators in
more detail.

Expand Down Expand Up @@ -203,14 +203,14 @@ The following interactive session shows how to call them from Python.
is passed as an argument to another C++ function exposed in Python. In this
case, there is no overhead. Pybind11 will extract the underlying C++
function pointer from the wrapped function to sidestep a potential C++ ->
Python -> C++ roundtrip. This is demonstrated in Example 5.
Python -> C++ roundtrip. This is demonstrated in :file:`tests/test_callbacks.cpp`.

.. note::

This functionality is very useful when generating bindings for callbacks in
C++ libraries (e.g. GUI libraries, asynchronous networking libraries, etc.).

The file :file:`example/example-callbacks.cpp` contains a complete example
The file :file:`tests/test_callbacks.cpp` contains a complete example
that demonstrates how to work with callbacks and anonymous functions in
more detail.

Expand Down Expand Up @@ -354,7 +354,7 @@ Please take a look at the :ref:`macro_notes` before using this feature.

.. seealso::

The file :file:`example/example-virtual-functions.cpp` contains a complete
The file :file:`tests/test_virtual_functions.cpp` contains a complete
example that demonstrates how to override virtual functions using pybind11
in more detail.

Expand Down Expand Up @@ -472,7 +472,7 @@ can now create a python class that inherits from ``Dog``:

.. seealso::

See the file :file:`example-virtual-functions.cpp` for complete examples
See the file :file:`tests/test_virtual_functions.cpp` for complete examples
using both the duplication and templated trampoline approaches.

.. _macro_notes:
Expand Down Expand Up @@ -556,7 +556,7 @@ out of the box with just the core :file:`pybind11/pybind11.h` header.

.. seealso::

The file :file:`example/example-python-types.cpp` contains a complete
The file :file:`tests/test_python_types.cpp` contains a complete
example that demonstrates how to pass STL data types in more detail.

Binding sequence data types, iterators, the slicing protocol, etc.
Expand All @@ -566,7 +566,7 @@ Please refer to the supplemental example for details.

.. seealso::

The file :file:`example/example-sequences-and-iterators.cpp` contains a
The file :file:`tests/test_sequences_and_iterators.cpp` contains a
complete example that shows how to bind a sequence data type, including
length queries (``__len__``), iterators (``__iter__``), the slicing
protocol and other kinds of useful operations.
Expand Down Expand Up @@ -690,7 +690,7 @@ container:

.. seealso::

The file :file:`example/example-keep-alive.cpp` contains a complete example
The file :file:`tests/test_keep_alive.cpp` contains a complete example
that demonstrates using :class:`keep_alive` in more detail.

Implicit type conversions
Expand Down Expand Up @@ -892,7 +892,7 @@ Please take a look at the :ref:`macro_notes` before using this feature.

.. seealso::

The file :file:`example/example-smart-ptr.cpp` contains a complete example
The file :file:`tests/test_smart_ptr.cpp` contains a complete example
that demonstrates how to work with custom reference-counting holder types
in more detail.

Expand Down Expand Up @@ -1005,7 +1005,7 @@ a first shot at handling the exception).
Inside the translator, ``std::rethrow_exception`` should be used within
a try block to re-throw the exception. A catch clause can then use
``PyErr_SetString`` to set a Python exception as demonstrated
in :file:`example-custom-exceptions.cpp``.
in :file:`tests/test_exceptions.cpp`.

This example also demonstrates how to create custom exception types
with ``py::exception``.
Expand Down Expand Up @@ -1143,7 +1143,7 @@ Please take a look at the :ref:`macro_notes` before using this feature.

.. seealso::

The file :file:`example/example-opaque-types.cpp` contains a complete
The file :file:`tests/test_opaque_types.cpp` contains a complete
example that demonstrates how to create and expose opaque types using
pybind11 in more detail.

Expand Down Expand Up @@ -1198,7 +1198,7 @@ with NumPy and SciPy.

.. seealso::

The file :file:`example/eigen.cpp` contains a complete example that
The file :file:`tests/test_eigen.cpp` contains a complete example that
shows how to pass Eigen sparse and dense data types in more detail.

Buffer protocol
Expand Down Expand Up @@ -1326,7 +1326,7 @@ limitations), refer to the section on :ref:`eigen`.

.. seealso::

The file :file:`example/example-buffers.cpp` contains a complete example
The file :file:`tests/test_buffers.cpp` contains a complete example
that demonstrates using the buffer protocol with pybind11 in more detail.

.. [#f2] http://docs.python.org/3/c-api/buffer.html
Expand Down Expand Up @@ -1493,7 +1493,7 @@ simply using ``vectorize``).

.. seealso::

The file :file:`example/example-numpy-vectorize.cpp` contains a complete
The file :file:`tests/test_numpy_vectorize.cpp` contains a complete
example that demonstrates using :func:`vectorize` in more detail.

Functions taking Python objects as arguments
Expand Down Expand Up @@ -1557,9 +1557,9 @@ with other parameters.

.. seealso::

The file :file:`example/example-python-types.cpp` contains a complete
The file :file:`tests/test_python_types.cpp` contains a complete
example that demonstrates passing native Python types in more detail. The
file :file:`example/example-arg-keywords-and-defaults.cpp` discusses usage
file :file:`tests/test_kwargs_and_defaults.cpp` discusses usage
of ``args`` and ``kwargs``.

Default arguments revisited
Expand Down Expand Up @@ -1633,7 +1633,7 @@ Such functions can also be created using pybind11:
/// Binding code
m.def("generic", &generic);

(See ``example/example-arg-keywords-and-defaults.cpp``). The class ``py::args``
(See ``tests/test_kwargs_and_defaults.cpp``). The class ``py::args``
derives from ``py::list`` and ``py::kwargs`` derives from ``py::dict`` Note
that the ``kwargs`` argument is invalid if no keyword arguments were actually
provided. Please refer to the other examples for details on how to iterate
Expand Down Expand Up @@ -1783,7 +1783,7 @@ memory corruption and/or segmentation faults.

.. seealso::

The file :file:`example/example-pickling.cpp` contains a complete example
The file :file:`tests/test_pickling.cpp` contains a complete example
that demonstrates how to pickle and unpickle types using pybind11 in more
detail.

Expand Down
48 changes: 23 additions & 25 deletions docs/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ First steps

This sections demonstrates the basic features of pybind11. Before getting
started, make sure that development environment is set up to compile the
included set of examples, which also double as test cases.
included set of test cases.


Compiling the test cases
Expand All @@ -22,44 +22,42 @@ After installing the prerequisites, run

.. code-block:: bash

cmake .
make -j 4
mkdir build
cd build
cmake ..
make pytest -j 4

followed by

.. code-block:: bash

make test
The last line will both compile and run the tests.

Windows
-------

On Windows, use the `CMake GUI`_ to create a Visual Studio project. Note that
only the 2015 release and newer versions are supported since pybind11 relies on
various C++11 language features that break older versions of Visual Studio.
After running CMake, open the created :file:`pybind11.sln` file and perform a
release build, which will will produce a file named
:file:`Release\\example.pyd`. Copy this file to the :file:`example` directory
and run :file:`example\\run_test.py` using the targeted Python version.
On Windows, only **Visual Studio 2015** and newer are supported since pybind11 relies
on various C++11 language features that break older versions of Visual Studio.

.. _`CMake GUI`: https://cmake.org/runningcmake
To compile and run the tests:

.. Note::
.. code-block:: batch

mkdir build
cd build
cmake ..
cmake --build . --config Release --target pytest

When all tests fail, make sure that
This will create a Visual Studio project, compile and run the target, all from the
command line.

1. The Python binary and the testcases are compiled for the same processor
type and bitness (i.e. either **i386** or **x86_64**)
.. Note::

2. The Python binary used to run :file:`example\\run_test.py` matches the
Python version specified in the CMake GUI. This is controlled via
the ``PYTHON_EXECUTABLE`` ``PYTHON_INCLUDE_DIR``, and
``PYTHON_LIBRARY`` variables.
If all tests fail, make sure that the Python binary and the testcases are compiled
for the same processor type and bitness (i.e. either **i386** or **x86_64**). You
can specify **x86_64** as the target architecture for the generated Visual Studio
project using ``cmake -A x64 ..``.

.. seealso::

Advanced users who are already familiar with Boost.Python may want to skip
the tutorial and look at the test cases in the :file:`example` directory,
the tutorial and look at the test cases in the :file:`tests` directory,
which exercise all features of pybind11.

Creating bindings for a simple function
Expand Down
Loading