This document describes the comprehensive test suite and CI/CD infrastructure added to the pyDIWASP project to document existing capabilities and ensure code quality.
The test suite is organized into three main test modules in the tests/ directory:
Tests for low-level utility functions and core calculations:
-
TestWavenumber: Tests for wavenumber calculations
test_wavenumber_basic: Basic scalar input testtest_wavenumber_array: Array input handlingtest_wavenumber_deep_water: Deep water approximation validation
-
TestHsig: Tests for significant wave height calculations
test_hsig_basic: Basic Hsig calculation with synthetic spectrumtest_hsig_zero_spectrum: Edge case with zero energy
-
TestCheckData: Tests for data validation functions
test_check_instrument_data_valid: Valid instrument data structuretest_check_instrument_data_invalid_depth: Invalid depth detectiontest_check_spectral_matrix_valid: Valid spectral matrix structuretest_check_estimation_parameters_defaults: Default parameter settingtest_check_estimation_parameters_invalid_method: Invalid method detection
-
TestTransferFunctions: Tests for wave transfer functions
test_elev_transfer_function: Surface elevation transfer functiontest_pres_transfer_function: Pressure transfer function
Total: 12 tests
Tests for high-level API functions:
-
TestInfospec: Tests for spectrum information extraction
test_infospec_basic: Basic information extraction (Hsig, Tp, DTp, Dp)test_infospec_returns_four_values: Return value validation
-
TestInterpspec: Tests for spectrum interpolation
test_interpspec_basic: Basic interpolation functionalitytest_interpspec_preserves_energy: Energy conservation validationtest_interpspec_no_interpolation_needed: Same-grid handling
-
TestWritespec: Tests for spectrum file output
test_writespec_creates_file: File creation and format validationtest_writespec_handles_complex_spectrum: Complex spectral values handling
Total: 7 tests
Tests for complete workflow scenarios:
-
TestDirspecIntegration: Full directional spectrum analysis
test_dirspec_basic_run: Basic end-to-end analysistest_dirspec_output_structure: Output structure validationtest_dirspec_with_different_methods: Multiple estimation methods (IMLM, EMEP)test_dirspec_file_output: File output functionalitytest_dirspec_detects_peak_frequency: Peak frequency detection
-
TestDataValidationIntegration: Data validation in workflow
test_invalid_instrument_data_rejected: Invalid data rejection
Total: 6 tests
- Total Tests: 25
- Coverage Areas:
- Wave physics calculations (wavenumber, wave height)
- Data validation and error handling
- Transfer functions (elevation, pressure)
- Spectrum operations (interpolation, information extraction)
- File I/O operations
- Complete directional analysis workflow
- Multiple estimation methods
# Install test dependencies
pip install pytest pytest-cov
# Run all tests
pytest tests/ -v
# Run specific test module
pytest tests/test_core.py -v
# Run with coverage
pytest tests/ -v --cov=. --cov-report=term --cov-report=html
# Run specific test
pytest tests/test_core.py::TestWavenumber::test_wavenumber_basic -vTriggers:
- Push to main/master/develop branches
- Pull requests to main/master/develop branches
- Manual trigger (workflow_dispatch)
Jobs:
- Tests on Python 3.8, 3.9, 3.10, 3.11, 3.12 (matrix strategy)
- Code linting with flake8
- Test execution with pytest
- Code coverage generation
- Optional coverage upload to Codecov
Steps:
- Checkout code
- Set up Python environment
- Install dependencies
- Run flake8 linting
- Run pytest test suite
- Upload coverage (Python 3.11 only)
Triggers:
- GitHub release publication
- Manual trigger with Test PyPI option
Jobs:
- Build source distribution and wheel
- Validate distribution with twine
- Publish to Test PyPI (manual, optional)
- Publish to PyPI (on release or manual)
Setup Required:
PYPI_API_TOKEN: PyPI API token (required for production)TEST_PYPI_API_TOKEN: Test PyPI token (optional, for testing)
Steps:
- Checkout code
- Set up Python
- Install build tools
- Build distribution packages
- Check package validity
- Publish to PyPI/Test PyPI
- Defines test discovery patterns
- Configures test output format
- Sets up coverage exclusions
- Package metadata and configuration
- Dependency specifications
- Entry points and classifiers
- Supports Python 3.8+
- Runtime dependencies (numpy, scipy, matplotlib)
- Version constraints for compatibility
- Excludes build artifacts
- Excludes Python cache files
- Excludes virtual environments
- Excludes test artifacts
The CI workflow provides a status badge that can be added to the README:
[](https://github.com/SBFRF/pyDIWASP/actions/workflows/ci.yml)Every pull request will automatically:
- Run the full test suite on all supported Python versions
- Check code quality with flake8
- Report test results in the PR
- Block merge if tests fail (optional)
To publish a new version to PyPI:
- Update version in
setup.py - Create a new release on GitHub with a tag (e.g.,
v0.1.0) - Workflow automatically builds and publishes to PyPI
- Monitor the Actions tab for deployment status
- Tests serve as executable documentation of capabilities
- Clear examples of how to use each function
- Validation of expected behavior
- Catch regressions early
- Ensure compatibility across Python versions
- Validate code quality standards
- Confidence in making changes
- Fast feedback on code modifications
- Automated testing on all contributions
- Streamlined release process
- Consistent package builds
- Easy publishing to PyPI
Potential improvements to the test suite and CI/CD:
-
Test Coverage:
- Add tests for remaining estimation methods (DFTM, EMLM, BDM)
- Add tests for velocity transfer functions (velx, vely)
- Add tests for plotspec function
-
CI Enhancements:
- Add code coverage requirements (e.g., minimum 80%)
- Add documentation generation and deployment
- Add performance benchmarks
- Add security scanning (e.g., bandit, safety)
-
Quality Tools:
- Add type checking with mypy
- Add code formatting with black
- Add import sorting with isort
- Add docstring validation
-
Documentation:
- Generate API documentation with Sphinx
- Add usage examples and tutorials
- Create contribution guidelines
Tests fail locally but pass in CI (or vice versa):
- Ensure you have the same dependency versions
- Check Python version differences
- Verify environment variables
Linting errors:
- Run
flake8 .locally to see all issues - Use
--excludeto ignore directories - Fix critical errors (E9, F63, F7, F82) first
PyPI publishing fails:
- Verify API token is set correctly
- Check package name availability on PyPI
- Ensure version number is incremented
- Validate package with
twine check dist/*
For questions or issues with the test suite or CI/CD setup, please open an issue on GitHub.