Testing the package#

In-development tests#

While developing a new feature or fixing a bug, it is handy to run a test script against the code you are working on. To ensure that the imported package biotite points to the code you are working on, you may want to install the local repository clone in editable mode:

$ pip install -e .

If you are writing or using an extension module in Cython, consider using pyximport at the beginning of the script you use for testing.

import numpy as np
import pyximport
pyximport.install(
    build_in_temp=False,
    setup_args={"include_dirs":np.get_include()},
    language_level=3
)

To enforce the recompilation of the changed Cython module, delete the respective compiled module (.dll or .so) from the src/ directory, if already existing.

Unit tests#

The backbone of testing Biotite are the unit tests in the tests directory. Pytest is used as the testing framework. To run the tests, install the local repository clone (in editable mode) and run the tests:

$ pip install -e .
$ pytest

Doctests#

For simple tests checking that some code simply does not raise an exception and produces some predefined output, doctests are suitable. They are part of the docstrings of the corresponding functions and classes. The doctests fulfill two purposes: They are automatically executed by pytest via the tests/test_doctests.py module and give users reading the API reference easily understandable examples how a function/class works.

Testing visualizations#

Testing visualization functions (e.g. in biotite.sequence.graphics) is difficult, because the output can hardly be checked against some reference value. To still have at least some confirmation that these functions produce the expected output, it is mandatory to have at least one example using that function in the gallery.