-
Notifications
You must be signed in to change notification settings - Fork 0
Testing Code
This part of the wiki deals with the unit and integration tests for the SPARKX
package. For this we use the package pytest
as a testing framework.
Information on this package can be found here:
If you want to run the tests for the SPARKX package, then go to the base
directory and execute pytest tests/
or for more output with the --verbose
option.
This will generate terminal output similar to this one:
=========================================================== test session starts ============================================================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /path_to_sparkx/sparkx
collected 28 items
tests/test_Particle.py ............................ [100%]
============================================================ 28 passed in 0.50s ============================================================
Or with the verbose output you can get a more detailed overview over the test functions:
=========================================================== test session starts ============================================================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /path_to_sparkx/sparkx
collected 28 items
tests/test_Particle.py::test_t PASSED [ 3%]
tests/test_Particle.py::test_x PASSED [ 7%]
tests/test_Particle.py::test_y PASSED [ 10%]
tests/test_Particle.py::test_z PASSED [ 14%]
tests/test_Particle.py::test_mass PASSED [ 17%]
tests/test_Particle.py::test_E PASSED [ 21%]
tests/test_Particle.py::test_px PASSED [ 25%]
tests/test_Particle.py::test_py PASSED [ 28%]
tests/test_Particle.py::test_pz PASSED [ 32%]
tests/test_Particle.py::test_pdg PASSED [ 35%]
tests/test_Particle.py::test_ID PASSED [ 39%]
tests/test_Particle.py::test_charge PASSED [ 42%]
tests/test_Particle.py::test_ncoll PASSED [ 46%]
tests/test_Particle.py::test_form_time PASSED [ 50%]
tests/test_Particle.py::test_xsecfac PASSED [ 53%]
tests/test_Particle.py::test_proc_id_origin PASSED [ 57%]
tests/test_Particle.py::test_proc_type_origin PASSED [ 60%]
tests/test_Particle.py::test_t_last_coll PASSED [ 64%]
tests/test_Particle.py::test_pdg_mother1 PASSED [ 67%]
tests/test_Particle.py::test_pdg_mother2 PASSED [ 71%]
tests/test_Particle.py::test_baryon_number PASSED [ 75%]
tests/test_Particle.py::test_strangeness PASSED [ 78%]
tests/test_Particle.py::test_weight PASSED [ 82%]
tests/test_Particle.py::test_status PASSED [ 85%]
tests/test_Particle.py::test_initialize_from_array_valid_formats PASSED [ 89%]
tests/test_Particle.py::test_initialize_from_array_invalid_format PASSED [ 92%]
tests/test_Particle.py::test_initialize_from_array_corrupted_data PASSED [ 96%]
tests/test_Particle.py::test_initialize_from_array_warning_invalid_pdg PASSED [100%]
============================================================ 28 passed in 0.51s ============================================================
To check which parts of SPARKX are not covered by our unit tests, you can install
the pytest-cov
package and run:
pytest --cov=./ --cov-report=html
from the sparkx
directory. This generates a directory called htmlcov
.
Open the index.html
file in your browser and check the coverage of each file.
You can click on the different code parts and see the uncovered regions.
For PRs to the main
or sparkx_devel
branch we require a specific code
formatting using the black
package. The minimum version can be found in the
requirements.txt
file.
To apply the code formatting to the codebase, you can run
black tests/ src/sparkx/
from the base directory. The line length (80 characters) is specified in pyproject.toml
in the [tool.black]
section.
Further documentation of the package can be found here: black
SPARKX - Software Package for Analyzing Relativistic Kinematics in Collision eXperiments
For the full documentation of the classes and functions visit: https://smash-transport.github.io/sparkx/