Tests

The pyrat/tests subdirectory contains Python unit tests. Most are translations of the original Rat C++ tests defined across the Project-Rat repositories; others check the bindings themselves (type conversions, signatures, the CLI, logging).

Unit tests act as a safeguard to ensure consistent behaviour between Rat C++ and pyRat Python module. They can also serve as examples to use pyRat.

Structure

Unit tests are split by pyrat.rat submodule under tests/rat/<submodule>/test_*.py: cmn, dm, fmm and mdl.

pyrat/tests is structured as a Python module on its own to be used in conjunction with the Python unittest module. In that regard all inner __init__.py files include the same following code for ease of access.

# Allow for unittest discovery
def load_tests(loader, tests, pattern):
    return loader.discover(__name__)

This enables more control over which tests to run from the command line.

Run tests

From the root of the pyRat repository, in an environment where a pyRat wheel is installed (see Install):

  • Run all tests:

python -m unittest
  • Run all tests in verbose mode:

python -m unittest -v

With -v, the tests that run RAT computations also print RAT’s own log.

  • Run specific tests:

python -m unittest tests.rat.cmn                # Run tests for pyrat.rat.cmn module
python -m unittest tests.rat.fmm.test_soleno    # Run the Soleno test for pyrat.rat.fmm module
python -m unittest tests.rat.mdl -v             # Run tests for pyrat.rat.mdl module, verbose

Note

Some tests are more beefy than others to run.

With CTest

Configured with -D PYRAT2_BUILD_TESTING=ON (stand-alone or in a superbuild such as rat-all), each tests/rat/<submodule>/test_*.py module becomes a CTest test named pyrat2_<submodule>_<module> (e.g. pyrat2_fmm_test_soleno), labelled pyrat2. The tests run against the module just built, staged with the Python sources in the build tree, so no wheel is needed:

cmake --build build
ctest --test-dir build -L pyrat2 --output-on-failure

On Windows, the tests find the RAT, vcpkg, CUDA and MKL DLLs through PYRAT_DLL_DIRS, which CTest sets from the directories CMake found (PYRAT2_RUNTIME_DIRS adds more). The interpreter that runs them needs numpy: PYRAT2_TEST_PYTHON names another one if needed (see Manual build).