Skip to content

[tests] Make the test suite able to fail (Fable 5 Phase 1) - #200

Merged
suraj-ranganath merged 1 commit into
fable5/epicfrom
fable5/phase1-test-integrity
Jun 12, 2026
Merged

suraj-ranganath merged 1 commit into
fable5/epicfrom
fable5/phase1-test-integrity

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Remove assertion-swallowing try/except-skipTest wrappers so core clean_rawdata, ICLabel, MNE, ASR and clustering tests assert real behavior instead of skipping on failure; genuine optional-dependency skips stay as explicit skipUnless guards. Also deduplicate create_test_eeg onto the shared fixture, tighten the autocorr cross-check tolerance, add a real unmocked calc_projector test, and replace ASR error-injection log-string tests with degenerate-input checks. One picard random-seed test now xfails honestly, tracked for Phase 2/3.

Fixes #194

Part of the Fable 5 Findings epic (#193); addresses issue #194.

- Remove assertion-swallowing try/except->skipTest wrappers across
  test_clean_artifacts, test_clean_drifts, test_eeg_picard,
  test_ICL_feature_extractor, and test_eeg_mne2eeg so assertions run
  instead of converting failures into skips. Genuine optional-dependency
  skips are kept as explicit @skipUnless guards.
- Deduplicate the per-module create_test_eeg fixtures onto the shared
  tests/fixtures.py fixture.
- Tighten the eeg_autocorr_fftw vs eeg_autocorr cross-check from
  rtol/atol=0.1 to 1e-4/1e-7 (documented: the only divergence is the
  single-precision FFT cast in eeg_autocorr).
- Add a real (unmocked) calc_projector test that runs the actual
  sphericalSplineInterpolate and validates channel mapping/assembly.
- Replace the ASR numpy-error-injection log-string tests with real
  degenerate-input tests asserting finite, sane cleaned output.
- Assert real clustering behavior (shared labels within tight pairs,
  far point isolated) in the study clustering helper test.

test_eeg_picard_different_random_states now xfails honestly: eeg_picard
converges identically regardless of random_state (tracked under the epic
for Phase 2/3); marked xfail rather than re-hidden.
@claude

claude Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 3m 15s —— View job


Code review

  • Overall assessment: Safe to merge. This is a clean, well-targeted test-integrity PR that does what it says.
  • Highest-risk area: Behavioral assertions newly exposed by removing the try/except → skipTest wrappers (ASR degenerate-input tests, picard xfail).
  • Merge recommendation: Safe to merge (pending green CI — see note below).

What I verified statically:

  • Optional-dependency guards preserved. mne and python-picard are both hard deps (pyproject.toml:30, pyproject.toml:39), so dropping the try/except around picard tests cannot turn an env-specific skip into a failure. MNE tests keep @unittest.skipUnless(MNE_AVAILABLE) and MATLAB/Octave keep skipUnless/skipIf. ✅
  • Shared-fixture migration is field-compatible. The old per-file create_test_eeg fixtures set chaninfo={'removedchans': []}; the shared fixture omits removedchans, but clean_rawdata never reads that key (grep clean), so no KeyError. Channel-label rename EEG001 → Ch1 is applied consistently across the clean_artifacts assertions. ✅
  • New calc_projector test is correct, not tautological. It reproduces calc_projector's exact for k in range(num_samples-1, -1, -1) stream-consumption order with RandomState(7), and block[sample,:] == np.real(expected_w).T matches rand_samples[sample,k,:] = np.real(tmp).T in ransac.py:148-151. Good upgrade over the mock-only shape/call-count tests. ✅

Blocking

None.

Important

None.

Nits

  • tests/test_utils_asr.py — test_extreme_artifact_amplitudes_produce_sane_output: assertLess(max(abs(cleaned)), spike_peak) relies on ASR's calibrated state actually flagging the injected burst. With a 1e4× spike this should be robustly attenuated, so the test is sound — just be aware it is the one new assertion whose pass/fail depends on numeric ASR behavior rather than structure, so if it ever flakes this is the line to revisit.
  • tests/test_eeg_picard.py:3251 — @pytest.mark.xfail(..., strict=False) is the right call for the seed-independence product bug; strict=False correctly lets a future fix xpass without breaking the suite. Worth keeping the #193 reference current so it isn't orphaned after Phase 2/3.

Test gaps

  • test_clean_artifacts.py, test_clean_drifts.py, and test_clean_flatlines.py now all route through the single shared create_test_eeg. That's the intended dedup, but it means a future change to the shared fixture's defaults moves all three suites at once — fine, just noting the coupling for whoever edits tests/fixtures.py next.

EEGLAB parity notes

  • None affected. The fixture rename and field set keep EEG-dict semantics (channel-major data, 1-based latencies in _mne_events_to_eeglab_events still asserted as int(t*srate)+1), and the autocorr tolerance tightening (rtol=1e-4, atol=1e-7) is justified by the documented complex64-vs-double precision split between eeg_autocorr and eeg_autocorr_fftw.

Note: I was unable to run pytest locally (sandbox denied the test invocation), so I relied on static analysis of the diff plus the source it touches. The whole point of this PR is to make these assertions able to fail, so the CI run on this branch is the authoritative check that the now-unwrapped assertions actually pass.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Specification (PR >500 LOC; full per-finding detail in #194, epic #193)

Problem. Several core-numeric and parity tests could not fail: assertions were wrapped in try/except Exception -> self.skipTest(...) (and AssertionError is a subclass of Exception, so failures became skips), calc_projector numerics were mocked to shape/call-count checks, the eeg_autocorr_fftw vs eeg_autocorr cross-check used rtol/atol=0.1, ASR tests injected failures into numpy primitives to assert defensive log strings, create_test_eeg was re-implemented per module, and the clustering helper test asserted only shapes. A green CI overstated how well the port was verified.

Approach. Removed the assertion-swallowing wrappers across test_clean_artifacts, test_clean_drifts, test_eeg_picard, test_ICL_feature_extractor, test_eeg_mne2eeg (the large line counts are de-indentation of the unwrapped bodies); kept genuine optional-dependency guards as explicit @skipUnless. Deduplicated create_test_eeg onto tests/fixtures.py. Tightened the autocorr cross-check to rtol=1e-4/atol=1e-7 (documented: the sole divergence is eeg_autocorr's single-precision FFT cast for MATLAB parity; 1e-5 does not pass). Added test_real_interpolation_channel_mapping_and_assembly running the real sphericalSplineInterpolate. Replaced the ASR numpy-error-injection tests with rank-deficient / extreme-amplitude input tests asserting finite, sane output. Added behavioral assertions to the clustering helper test.

Honest xfail. Un-swallowing test_eeg_picard_different_random_states exposed that eeg_picard converges identically regardless of random_state (max diff 0.0). Rather than re-hide it or fix product code out of phase, it is marked @pytest.mark.xfail(reason="...epic #193 (Phase 2/3)", strict=False). Worth triaging in Phase 3 whether random_state is actually plumbed through eeg_picard.

Tests. EEGPREP_SKIP_MATLAB=1 uv run pytest on the 10 affected files plus test_eeg_autocorr: 234 passed, skips MATLAB-gated only, 1 honest xfail, 0 failures. pre-commit.py clean. Test-only change; no product code touched.

@suraj-ranganath
suraj-ranganath changed the base branch from fix/fresh-uv-console to fable5/epic June 12, 2026 04:32
@suraj-ranganath
suraj-ranganath merged commit 691c084 into fable5/epic Jun 12, 2026
1 check passed
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.

1 participant