Testing#

Running services for testing#

Several tests for the storage plugins requires that you have a service running.

Start all services with

docker compose -f test-services/compose.yaml up -d

or only some of them, e.g.

docker compose -f test-services/compose.yaml up -d postgres redis

and stop them again with

docker compose -f test-services/compose.yaml down

Tests that need a service which is not running are skipped.

The fuseki and graphdb services are configured as expected by the tripper tests, so when developing DLite and tripper together, the same services can be used for testing both projects. Tripper only needs fuseki and graphdb:

docker compose -f test-services/compose.yaml up -d fuseki graphdb

Starting graphdb also starts graphdb-init, which creates the “test_repo” repository.

The credentials below are only meant for local testing. They agree with the defaults in TEST_SERVICES in bindings/python/testutils.py (and storages/python/tests-c/pgtestconf.h). They can be changed by setting the environment variables DLITE_TEST_<SERVICE>_<KEY> both when starting the services and when running the tests, e.g.

export DLITE_TEST_POSTGRESQL_PASSWORD=my-secret

Note that the services publish their ports on localhost. Stop any locally running server that uses the same port first.

Testing Python examples in the documentation#

We can use the Python doctest module for testing examples in the documentation. Run it with

python -m doctest <filename>

on your markdown file.

See documentation contributions for how to write your examples such that they can be tested with doctest.

For instance, assume that you have the following example in your documentation

```python
    >>> 1 + 1  # doctest: +SKIP
    3

```

python -m doctest documentation_testing.md would print the following message:

**********************************************************************
File "documentation_testing.md", line 15, in documentation_testing.md
Failed example:
    1 + 1
Expected:
    3
Got:
    2
**********************************************************************

Now you copy the output following Got:, including the 4 indentation spaces, into your example.

Note that the comment #doctest: +SKIP was added to the above example in order to not trigger a doctest failure when validating the markdown file containing this guideline.

Building Python API documentation#

The Python API reference is generated by Sphinx using AutoAPI. The entry points in the docs are:

  • Python API <autoapi/index> in doc/api.rst

  • Python API <autoapi/index> in doc/index.rst

Build steps from the repository root:

python -m pip install -r requirements_doc.txt
cmake -S . -B build -DWITH_DOC=ON
cmake --build build --target Sphinx

Expected output location:

  • HTML root: build/doc/html/index.html

  • Python API index: build/doc/html/autoapi/index.html

If autoapi.extension cannot be imported, install or re-install the docs dependencies from requirements_doc.txt.

If Python API pages are missing, ensure that the CMake configuration used to build docs has access to either:

  • built Python bindings under the active build directory, or

  • source Python modules under bindings/python and python/dlite-python.