Add unit test suite and fix bugs uncovered during testing#26
Open
thellert wants to merge 11 commits intokparasch:developfrom
Open
Add unit test suite and fix bugs uncovered during testing#26thellert wants to merge 11 commits intokparasch:developfrom
thellert wants to merge 11 commits intokparasch:developfrom
Conversation
Check for 'name' key in level_conf dict instead of in level_conf['name'] string, which was always checking if the substring 'name' existed in the value.
Replace at.load_mat with at.load_lattice, which dispatches to the correct loader based on file extension (.mat, .m, .seq, .lte, etc.). Add loader_kwargs field for passing format-specific options through the config.
- Add gain_corrections_x/y fields (initialized to ones) as multiplicative corrections applied in capture_orbit, capture_injection, and capture_kick - Parse n_particles as int from injection config - Allow capture_injection to optionally return transmission array
Add extra="forbid" to the 14 remaining models that used the default extra="ignore", which silently discards unknown kwargs. This fixes a real bug where BBAAnalysis(total_rejections=...) silently lost data. - Add total_rejections field to BBAAnalysis (was passed but discarded) - Update deprecated outputs_plane -> output_planes in c_minus.py - AbstractInterface intentionally excluded (subclassed externally)
…feature/test-suite
- codes.py: Fix DispersionCode.DONE value collision with HORIZONTAL - response.py: Replace np.concat with np.concatenate - response_matrix.py: Fix disable_all_outputs_but copy-paste bug, fix MICADO UnboundLocalError - bpm_system.py: Fix reconstruct_true_orbit gain inversion - tune.py: Store tune_response_matrix on self - tuning_core.py: Guard wiggle_last_corrector against UnboundLocalError
- bba.py: Fix reject_bpm_outlier np.abs usage, add total_rejections field - bpm_system_conf.py: Fix config pattern matching - general.py: Prevent scale_error_table from mutating input arrays - rf_conf.py: Fix 'frequncy' typo - injection.py: Fix injection tracking - magnetsettings.py: Fix add_individually_powered indentation logic - rdt.py: Fix fjklm phase wrapping
Tests cover all core modules (configuration, core, tuning, apps, utils) with 53 test files providing structural and behavioral coverage.
kparasch
approved these changes
Mar 23, 2026
|
|
||
|
|
||
| # linear_normal_form has a numpy dtype bug: in-place multiply of real | ||
| # eigenvector array by complex scalar fails on numpy >= 2.0. |
Owner
There was a problem hiding this comment.
This suprises me, I will check it out
Fix rf_conf.py using rf_conf (top-level dict) instead of rf_category_conf
(per-category dict) for error key lookups — this silently skipped all
cavity error application since 'voltage'/'phase'/'frequency' keys only
exist in the category dict, not the top-level dict keyed by category names.
Replace the inspect.getsource() regression test with behavioral tests that
actually configure errors and verify they are applied to cavities.
Strengthen weak assertions across the test suite:
- BPM rot_matrices: check shape and identity values, not just not-None
- BPM calibration errors: verify scale consistent with configured sigma
- BPM multi-category: guard against vacuous regex matches
- Magnets: remove quad_limit from error_table to catch wrong-dict lookups
- Supports: check both start and end endpoint misalignments
- RF settings mocks: verify call arguments, not just call count
- Tuning regression test: actually exercise the no-upstream-corrector path
- Measurements: assert non-empty finite trims with non-zero orbit input
Downgrade stale logger.fatal('Not tested!') in bpm_system_conf.py since
multi-category BPMs now have regression test coverage.
Author
Test suite audit: fixed inconsistenciesAudited the test suite for tests that assert buggy behavior rather than correct behavior. Found and fixed: Bug fix (rf_conf.py): Test fixes:
All 62 tests pass (+ 1 expected xfail). |
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
While writing a comprehensive unit test suite for pySC, we uncovered several bugs across the codebase. This PR includes both the fixes and the tests that exposed them.
Bug fixes found during test audit (Commit 1):
codes.py:DispersionCode.DONEvalue collided withHORIZONTALresponse.py:np.concat→np.concatenate(no such function)response_matrix.py: copy-paste bug indisable_all_outputs_but;UnboundLocalErrorin MICADO pathbpm_system.py: gain inversion inreconstruct_true_orbittune.py:tune_response_matrixnot stored onselftuning_core.py:UnboundLocalErrorguard forwiggle_last_correctorPreviously identified bug fixes (Commit 2):
bba.py:np.absusage inreject_bpm_outlier, missingtotal_rejectionsfieldbpm_system_conf.py: config pattern matching fixgeneral.py:scale_error_tableno longer mutates input arraysrf_conf.py:frequncy→frequencytypoinjection.py: injection tracking fixmagnetsettings.py:add_individually_poweredindentation logic fixrdt.py:fjklmphase wrapping fixTest suite (Commit 3):
pyproject.tomlDependencies
This branch is based on top of three open PRs that must be merged into
developfirst:feature/bpm-gains-and-fixes(BPM gain corrections, generic lattice loader)feature/pydantic-extra-forbid(enforceextra="forbid"on Pydantic models)feature/tuning-scan-and-energy-correction(tune_scan and synch_energy_correction)Merge order: #22 → #24 → #25 → this PR.
Test plan
developfirstpython -m pytest tests/ -xpasses on this branchloco,multipoles,dynamic_aperture)