feat(tests) Add comprehensive pytest suite for algorithms and utilities#111
Open
ZyntZ wants to merge 2 commits into
Open
feat(tests) Add comprehensive pytest suite for algorithms and utilities#111ZyntZ wants to merge 2 commits into
ZyntZ wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a comprehensive pytest test suite for MetaBCI, replacing
the placeholder tests (
test_add,test_minus) with real unit testscovering the project's core algorithms and utilities.
What's included
Test modules added (13 new files, ~1200 lines of test code):
test_covariance.pyisPD,nearestPD,covariances,sqrtm/logm/expm/invsqrtm/powmtest_csp.pycsp_kernel,CSP,MultiCSP(2-class & multi-class)test_cca.pySCCA,ItCCA,MsCCA,ECCA+ FB variants,generate_cca_referencestest_dsp.pyxiang_dsp_kernel,DSP,FBDSPtest_sscor.pysscor_kernel,SSCOR,FBSSCORtest_riemann.pylogmap/expmap,geodesic,distance_riemann,mean_riemann,MDRM,FGDAtest_performance.pytest_model_selection.pyEnhancedStratifiedKFold,generate_kfold_indices,match_kfold_indicestest_deep_learning.pyEEGNet,ShallowNet,Deep4Net(shape, forward pass, skorch)test_transfer_learning.pylst_kernel,LSTtransformertest_dynamic_stopping.pyDummyKDE,Bayestest_sklda_stda.pySKLDA,STDAclassifierstest_sklearn_compat.pySupporting files:
conftest.py: Shared fixtures with synthetic EEG data generators(Motor Imagery, SSVEP, P300, SPD matrices)
pytest.ini: Pytest configurationKey design decisions
EEG data using fixed random seeds. No internet connection needed.
test session for performance.
test_demo.py,test_download.py,and
base_tmpl.pyare preserved untouched.How to run
pip install -e ".[brainda,dev]" pytest tests/ -vRelated issues
This addresses the loooong-standing need for real tests in MetaBCI
(the existing test suite only contains
test_add()andtest_minus():( ).