This document describes the comprehensive test suite for the PYNUCDET (PYNUCastro Detonation Estimation Tool) codebase.
The test suite includes:
- Unit Tests - Testing individual functions and modules
- Integration Tests - Testing complete workflows and interactions
- Regression Tests - Ensuring outputs match expected values
Tests for the aux.py auxiliary module:
TestHelmholtzCall: Tests for Helmholtz EOS wrapper- Forward calls (isochoric)
- Inverse calls (isobaric)
- Different compositions
- Temperature variations
- Error handling
TestFloatToLatexScientific: Tests for LaTeX formatting utility- Zero values
- Scientific notation
- Plain numbers
- Precision control
- Edge cases
TestHelmholtzWithTestData: Regression tests against known test data
Tests for the cleanup.py module:
- File cleanup functionality
- Pattern matching for reaction flow files
- Preservation of non-target files
- Error handling for missing files
Tests for Helmholtz EOS integration:
- Basic forward and inverse calls
- Numerical accuracy tests
- Test data validation
Integration tests for complete workflows:
TestSelfHeatIntegration: End-to-end workflow tests- Isochoric runs
- Isobaric runs
- Custom parameters
- Output file generation
- Invalid input handling
TestSelfHeatNumerics: Numerical behavior tests- Low/high temperature regimes
- Low/high density regimes
- Adaptive timestepping
TestSelfHeatPureCompositions: Tests with various compositions- Pure helium
- Carbon-oxygen mixtures
- Custom abundance ratios
Shared pytest fixtures:
helmholtz_executable: Verifies Helmholtz executable existstest_data_files: Verifies test data files existclean_test_outputs: Cleans up output files after teststemp_working_directory: Provides isolated temporary directory
Pytest configuration:
- Test discovery patterns
- Custom markers
- Coverage options
- Output formatting
pytestpytest test_aux.pypytest test_aux.py::TestHelmholtzCallpytest test_aux.py::TestHelmholtzCall::test_helmholtz_forward_callpytest -vpytest --cov=. --cov-report=htmlpytest -m "not slow"pytest -m unitpytest -m integrationpytest -n autoTests are marked with the following categories:
@pytest.mark.unit- Unit tests@pytest.mark.integration- Integration tests@pytest.mark.slow- Slow-running tests@pytest.mark.helmholtz- Tests requiring Helmholtz executable
The test suite runs automatically via GitHub Actions on:
- Every push to main branch
- Every pull request to main
- Daily scheduled runs (00:00 UTC)
- Manual workflow dispatch
Tests run on multiple Python versions:
- Python 3.8
- Python 3.9
- Python 3.10
- Python 3.11
To generate and view coverage report:
pytest --cov=. --cov-report=html
open htmlcov/index.htmlCoverage reports are automatically uploaded to Codecov in CI.
Before running tests, ensure:
-
Helmholtz Fortran code is compiled:
cd _helmholtz make cd ..
-
Python dependencies are installed:
pip install -r requirements.txt pip install pytest pytest-cov pytest-timeout pytest-xdist
-
Test data files exist:
helm_input_test_data.txthelm_output_test_data.txthelm_table.dat
When adding new tests:
- Use descriptive names: Test function names should clearly describe what they test
- Add docstrings: Include brief descriptions of what each test validates
- Use fixtures: Utilize shared fixtures from conftest.py
- Add markers: Mark tests appropriately (unit/integration/slow)
- Test edge cases: Include boundary conditions and error cases
- Keep tests isolated: Tests should not depend on each other
import pytest
class TestNewFeature:
"""Test suite for new feature"""
@pytest.mark.unit
def test_basic_functionality(self):
"""Test basic functionality of new feature"""
# Arrange
input_data = setup_test_data()
# Act
result = new_feature(input_data)
# Assert
assert result == expected_value
@pytest.mark.integration
@pytest.mark.slow
def test_full_workflow(self):
"""Test complete workflow with new feature"""
# Test implementation
passCompile the Helmholtz code:
cd _helmholtz && make && cd ..Install required dependencies:
pip install -r requirements.txtIncrease timeout or skip slow tests:
pytest -m "not slow"Install pytest-cov:
pip install pytest-covWhen contributing code:
- Write tests for new features
- Ensure all tests pass locally before submitting PR
- Maintain or improve code coverage
- Update this documentation if adding new test categories