Skip to content

Commit

Permalink
ADD: testing docu on sphinx docs
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3 committed Aug 16, 2024
1 parent 1697db1 commit 91685c3
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 65 deletions.
22 changes: 11 additions & 11 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
os.add_dll_directory(extra_dll_dir_doc) # For finding DLL dependencies on Windows
sys.path.insert(0, extra_dll_dir_doc)
sys.path.insert(0, extra_dll_dir_pysource)
# try:
# import diffCheck.diffcheck_bindings as dfb
# except ImportError as e:
# print(f"Failed to import diffcheck_bindings: {e}")
# print("Current sys.path directories:")
# for path in sys.path:
# print(path)
# print("Current files in the directory:")
# for file in os.listdir(extra_dll_dir_doc):
# print(file)
# sys.exit(1)
try:
import diffCheck.diffcheck_bindings as dfb
except ImportError as e:
print(f"Failed to import diffcheck_bindings: {e}")
print("Current sys.path directories:")
for path in sys.path:
print(path)
print("Current files in the directory:")
for file in os.listdir(extra_dll_dir_doc):
print(file)
sys.exit(1)

# -- Project information -----------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/documentation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(doc_guide)=
# Documentation guide
# Documentation

/// from CONTRIBUTING how to write documentation
144 changes: 92 additions & 52 deletions doc/testing.rst
Original file line number Diff line number Diff line change
@@ -1,63 +1,103 @@

.. _test_guide:

Testing
=======

In df we use `CTest` as a test framework managed by Cmake in the file `cmake/tests.cmake` to run:
* [c++](cpp_test) tests with `GoogleTest`, and
* [python](py_test) in `PyTest`.

Tests are in the `tests` folder, and here's its structure:

```terminal
F:\DIFFCHECK\TESTS
│ allCppTests.cc
├───integration_tests <-- mainly python interfaces
│ ├───ghcomponents_tests <-- relative to gh components
│ │ .gitkeep
│ │
│ ├───package_tests <-- relative to the pypi package
│ │ .gitkeep
│ │
│ └───pybinds_tests <-- strictly pybinding
│ │ diffCheck.dll
│ │ diffcheck_bindings.cp39-win_amd64.pyd
│ │ Open3D.dll
│ │ test_pybind_pyver.py
│ │ test_pybind_units.py
├───test_data <-- here is where we put some .ply data
│ roof_quarter.ply
└───unit_tests <-- c++ backend, one for each header
DFLog.cc
DFPointCloudTest.cc
```
DFTesting
=========

In df we use `CTest` as a test framework managed by Cmake in the file ``cmake/tests.cmake`` to run:

* `c++ <#cpp_test>`_ tests with `GoogleTest`, and
* `Python <#py_test>`_ in `PyTest`.

Tests are in the ``tests`` folder, and here's its structure:

.. code-block:: console
F:\DIFFCHECK\TESTS
│ allCppTests.cc
├───integration_tests <-- mainly python interfaces
│ ├───ghcomponents_tests <-- relative to gh components
│ │ .gitkeep
│ │
│ ├───package_tests <-- relative to the pypi package
│ │ .gitkeep
│ │
│ └───pybinds_tests <-- strictly pybinding
│ │ diffCheck.dll
│ │ diffcheck_bindings.cp39-win_amd64.pyd
│ │ Open3D.dll
│ │ test_pybind_pyver.py
│ │ test_pybind_units.py
├───test_data <-- here is where we put some .ply data
│ roof_quarter.ply
└───unit_tests <-- c++ backend, one for each header
DFLog.cc
DFPointCloudTest.cc
To run the tests, you can use the following commands:
```terminal
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=ON -DBUILD_TESTS=ON -DRUN_TESTS=ON
cmake --build build --config Release
```

(py_test)=
## Write Python tests

To write a test, you need to create a new file in the `tests/integration_tests` folder. Write a new `.py` test file if you are not contributing to an already existing test, and add it in the `cmake/tests.cmake` in the `add_test` function.
e.g.:
```cmake
add_test(NAME PYBIND_UNIT_TEST

.. code-block:: console
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=ON -DBUILD_TESTS=ON -DRUN_TESTS=ON
cmake --build build --config Release
.. _py_test:

Write DF Python tests
---------------------

To write a test, you need to create a new file in the ``tests/integration_tests`` folder. Write a new ``.py`` test file if you are not contributing to an already existing test, and add it in the ``cmake/tests.cmake`` in the ``add_test()`` function:

.. code-block:: cmake
add_test(NAME PYBIND_UNIT_TEST
COMMAND ${PYTHON_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/tests/integration_tests/pybinds_tests/test_pybind_units.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
Use a fixture to your needs, and write your test. Here is an example of a fixture that always load a point cloud from the ``test_data`` folder:

.. literalinclude:: ../tests/integration_tests/pybinds_tests/test_pybind_units.py
:language: python
:pyobject: create_DFPointCloudSampleRoof
:caption: `test_pybind_units.py <../tests/integration_tests/pybinds_tests/test_pybind_units.py>`_

Than you can use it in your test:

.. literalinclude:: ../tests/integration_tests/pybinds_tests/test_pybind_units.py
:language: python
:pyobject: test_DFPointCloud_apply_color


.. _cpp_test:

Write DF C++ tests
------------------

To write a test, you need to create a new file in the ``tests/unit_tests`` folder. Next add your file in the executable ``${CPP_UNIT_TESTS}`` in the ``cmake/tests.cmake``:

.. code-block:: cmake
add_test(NAME PYBIND_UNIT_TEST
COMMAND ${PYTHON_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/tests/integration_tests/pybinds_tests/test_pybind_units.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
```
Use a fixture to your needs, and write your test. Here is an example of a fixture that always load a point cloud from the ``test_data`` folder:

.. literalinclude:: ../tests/unit_tests/DFPointCloudTest.cc
:language: cpp
:lines: 1-27
:caption: `DFPointCloudTest.cc <../tests/unit_tests/DFPointCloudTest.cc>`_

and you can use it in your test:

(cpp_test)=
## Write C++ tests
.. code-block:: cpp
To write a test, you need to create a new file in the `tests/unit_tests` folder. Next add your file in the executable `${CPP_UNIT_TESTS}` in the `cmake/tests.cmake`.
e.g.:
https://github.com/diffCheckOrg/diffCheck/blob/e080a93cdd73d96efb0686f80bf13730e0b8efa3/cmake/tests.cmake#L13-L17
TEST_F(DFPointCloudTestFixture, HasColors) {
EXPECT_TRUE(dfPointCloud.HasColors());
}
7 changes: 6 additions & 1 deletion tests/unit_tests/DFPointCloudTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "diffCheck.hh"
#include "diffCheck/IOManager.hh"

//-------------------------------------------------------------------------
// fixtures
//-------------------------------------------------------------------------

class DFPointCloudTestFixture : public ::testing::Test {
protected:
std::vector<Eigen::Vector3d> points;
Expand All @@ -22,6 +26,8 @@ class DFPointCloudTestFixture : public ::testing::Test {
}
};

// add your fixtures here..

//-------------------------------------------------------------------------
// basic constructors
//-------------------------------------------------------------------------
Expand Down Expand Up @@ -51,7 +57,6 @@ TEST_F(DFPointCloudTestFixture, LoadFromPLY) {
EXPECT_EQ(dfPointCloud.GetNumPoints(), 7379);
EXPECT_EQ(dfPointCloud.GetNumColors(), 7379);
EXPECT_EQ(dfPointCloud.GetNumNormals(), 7379);

}

//-------------------------------------------------------------------------
Expand Down

0 comments on commit 91685c3

Please sign in to comment.