Skip to content

feat(tests) Add comprehensive pytest suite for algorithms and utilities#111

Open
ZyntZ wants to merge 2 commits into
TBC-TJU:masterfrom
ZyntZ:feat/comprehensive-pytest-suite
Open

feat(tests) Add comprehensive pytest suite for algorithms and utilities#111
ZyntZ wants to merge 2 commits into
TBC-TJU:masterfrom
ZyntZ:feat/comprehensive-pytest-suite

Conversation

@ZyntZ

@ZyntZ ZyntZ commented Apr 16, 2026

Copy link
Copy Markdown

Summary

This PR adds a comprehensive pytest test suite for MetaBCI, replacing
the placeholder tests (test_add, test_minus) with real unit tests
covering the project's core algorithms and utilities.

What's included

Test modules added (13 new files, ~1200 lines of test code):

Module What it tests # Tests
test_covariance.py isPD, nearestPD, covariances, sqrtm/logm/expm/invsqrtm/powm ~17
test_csp.py csp_kernel, CSP, MultiCSP (2-class & multi-class) ~14
test_cca.py SCCA, ItCCA, MsCCA, ECCA + FB variants, generate_cca_references ~20
test_dsp.py xiang_dsp_kernel, DSP, FBDSP ~6
test_sscor.py sscor_kernel, SSCOR, FBSSCOR ~5
test_riemann.py logmap/expmap, geodesic, distance_riemann, mean_riemann, MDRM, FGDA ~14
test_performance.py All BCI metrics: Acc, bAcc, tITR, pITR, TPR/FNR/FPR/TNR ~16
test_model_selection.py EnhancedStratifiedKFold, generate_kfold_indices, match_kfold_indices ~10
test_deep_learning.py EEGNet, ShallowNet, Deep4Net (shape, forward pass, skorch) ~10
test_transfer_learning.py lst_kernel, LST transformer ~5
test_dynamic_stopping.py DummyKDE, Bayes ~3
test_sklda_stda.py SKLDA, STDA classifiers ~7
test_sklearn_compat.py sklearn API compliance: clone, Pipeline, get/set_params ~6

Supporting files:

  • conftest.py: Shared fixtures with synthetic EEG data generators
    (Motor Imagery, SSVEP, P300, SPD matrices)
  • pytest.ini: Pytest configuration

Key design decisions

  1. All synthetic data, no downloads: Tests generate deterministic
    EEG data using fixed random seeds. No internet connection needed.
  2. Session-scoped fixtures: Heavy data generation is done once per
    test session for performance.
  3. Backward compatible: Existing test_demo.py, test_download.py,
    and base_tmpl.py are preserved untouched.
  4. Tests verify:
    • Correct output shapes
    • sklearn API compliance (fit/transform/predict)
    • Mathematical properties (PD matrices, eigenvalue ranges, roundtrips)
    • Above-chance accuracy on synthetic data
    • Edge cases and error handling

How to run

pip install -e ".[brainda,dev]"
pytest tests/ -v

Related issues

This addresses the loooong-standing need for real tests in MetaBCI
(the existing test suite only contains test_add() and test_minus() :( ).

MakaEst added 2 commits April 16, 2026 11:57
Add real unit tests for MetaBCIs core components:

- Covariance utilities: isPD, nearestPD, covariances, matrix operations
- CSP algorithms: csp_kernel, CSP, MultiCSP
- CCA algorithms: SCCA, ItCCA, MsCCA, ECCA + filter bank variants
- DSP algorithms: xiang_dsp_kernel, DSP, FBDSP
- SSCOR algorithms: sscor_kernel, SSCOR, FBSSCOR
- Riemannian geometry: logmap, expmap, geodesic, MDRM, FGDA
- Performance metrics: accuracy, ITR, confusion matrix, TPR/FNR/FPR/TNR
- Model selection: EnhancedStratifiedKFold, kfold indices
- Deep learning: EEGNet, ShallowNet, Deep4Net (forward pass + skorch)
- Transfer learning: LST kernel and transformer
- Dynamic stopping: DummyKDE, Bayes
- SKLDA/STDA: Shrinkage LDA and Spatial-Temporal DA
- sklearn compatibility: clone, pipeline, get/set_params
All tests use synthetic data (no downloads required)!! Deterministic random seeds ensure reproducibility
Fixes:
- CSP OVO test: xfail due to sklearn>=1.6 removing _validate_data
- Deep learning: correct input shapes (3D not 4D), dtype consistency,
  Deep4Net n_samples increased to 1000, skorch params via set_params
- DummyKDE: use constant=0 (sklearn>=1.6 validation)
- Riemann: squeeze geodesic output, batch vectorize roundtrip
- STDA: use transform() instead of nonexistent predict()
- SSCOR/FBSSCOR: use transform(), fix expected output shapes
- LST: correct API (fit=target, transform=source+labels), fix P shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants