Repository navigation
[TEST] Tests for the OpenSWATH MSExperiment spectrum-access wrappers - #9578
Conversation
Batches tests for two untested OpenSWATH data-access wrappers that adapt an MSExperiment to the OpenSwath::ISpectrumAccess interface. Both build a small 2-spectrum / 1-chromatogram experiment and verify the interface: - SpectrumAccessOpenMS (wraps a shared_ptr<MSExperiment>): getNrSpectra / getNrChromatograms, getSpectrumById (m/z + intensity arrays), getSpectrumMetaById (RT, MS level), getSpectraByRT (RT-window lookup), getChromatogramById (time + intensity arrays), getChromatogramNativeID, and lightClone. - SpectrumAccessOpenMSInMemory (pre-loads from an ISpectrumAccess): the same spectrum/chromatogram counts and per-array values are reproduced from the in-memory copy, plus getSpectrumMetaById and lightClone. Registered both in executables.cmake (format_executables_list, DATAACCESS section). Part of the OpenMS 3.6.0 pre-release testing plan (OpenMS#9460). Tests only; no production code changes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-06-16 05:29:35.879490665 +0000
+++ AUTHORS.new 2026-06-16 05:29:41.058251812 +0000
@@ -23,8 +23,8 @@
- Chirag Dave
- Chris Bauer
- Chris Bielow
- - Christie Mathews
- Christian Ehrlich
+ - Christie Mathews
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
📝 WalkthroughWalkthroughTwo new C++ unit test files are added for ChangesSpectrumAccess Unit Tests
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp (1)
24-39: 💤 Low valueConsider extracting the shared
mkExp()fixture.The
mkExp()function on lines 24-39 is identical to the one inSpectrumAccessOpenMS_test.cpp(lines 23-38). Since both test files exercise related SpectrumAccess functionality, consider extracting this fixture into a shared test helper to reduce duplication and ensure consistency.♻️ Possible refactoring approach
Create a shared test fixture header (e.g.,
SpectrumAccessTestFixtures.h) in the test directory with themkExp()function, then include it in both test files. This would ensure that any future changes to the fixture are automatically consistent across both tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp` around lines 24 - 39, The mkExp() function is duplicated identically in both SpectrumAccessOpenMSInMemory_test.cpp and SpectrumAccessOpenMS_test.cpp. Extract this function into a shared test fixture header file (e.g., SpectrumAccessTestFixtures.h) in the test directory, then include this header in both test files and remove the duplicate mkExp() function definitions from each file. This will ensure consistency and reduce code duplication across the related test files.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`:
- Around line 78-85: The test for getSpectrumMetaById in the START_SECTION block
is incomplete and only validates the RT field of the returned SpectrumMeta
object m. Add an additional assertion to validate the ms_level field of the
metadata object to ensure complete coverage, matching the validation pattern
used in the corresponding test in SpectrumAccessOpenMS_test.cpp.
- Around line 66-76: The intensity array validation in the getSpectrumById test
is incomplete. Currently, only data[1] is checked with TEST_REAL_SIMILAR for
s->getIntensityArray(), while data[0] is not validated. Add a TEST_REAL_SIMILAR
assertion for s->getIntensityArray()->data[0] before the existing data[1] check
to ensure consistent test coverage with the corresponding assertions for the mz
array and to match the validation pattern in SpectrumAccessOpenMS_test.cpp.
- Around line 98-106: The lightClone test section is missing an assertion for
chromatogram count validation. Add a TEST_EQUAL assertion for
clone->getNrChromatograms() immediately after the existing TEST_EQUAL for
clone->getNrSpectra() to ensure the cloned object fully preserves the in-memory
state, matching the assertion pattern used in the corresponding
SpectrumAccessOpenMS_test.cpp test. Determine the expected chromatogram count by
examining what the origin object contains or by checking the referenced test
file for the expected value.
---
Nitpick comments:
In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`:
- Around line 24-39: The mkExp() function is duplicated identically in both
SpectrumAccessOpenMSInMemory_test.cpp and SpectrumAccessOpenMS_test.cpp. Extract
this function into a shared test fixture header file (e.g.,
SpectrumAccessTestFixtures.h) in the test directory, then include this header in
both test files and remove the duplicate mkExp() function definitions from each
file. This will ensure consistency and reduce code duplication across the
related test files.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d2f28e3d-2316-4018-83fc-f6aefac6d426
📒 Files selected for processing (3)
src/tests/class_tests/openms/executables.cmakesrc/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cppsrc/tests/class_tests/openms/source/SpectrumAccessOpenMS_test.cpp
| START_SECTION((OpenSwath::SpectrumPtr getSpectrumById(int id))) | ||
| { | ||
| SpectrumAccessOpenMS origin(mkExp()); | ||
| SpectrumAccessOpenMSInMemory sa(origin); | ||
| OpenSwath::SpectrumPtr s = sa.getSpectrumById(0); | ||
| TEST_EQUAL(s->getMZArray()->data.size(), 2) | ||
| TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0) | ||
| TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0) | ||
| TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0) | ||
| } | ||
| END_SECTION |
There was a problem hiding this comment.
Incomplete assertion coverage for intensity array.
Line 74 only validates data[1] for the intensity array but omits data[0]. The corresponding test in SpectrumAccessOpenMS_test.cpp (lines 83-84) checks both indices. For completeness and consistency, add an assertion for data[0].
🧪 Suggested fix
TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0)
TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0)
+ TEST_REAL_SIMILAR(s->getIntensityArray()->data[0], 500.0)
TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| START_SECTION((OpenSwath::SpectrumPtr getSpectrumById(int id))) | |
| { | |
| SpectrumAccessOpenMS origin(mkExp()); | |
| SpectrumAccessOpenMSInMemory sa(origin); | |
| OpenSwath::SpectrumPtr s = sa.getSpectrumById(0); | |
| TEST_EQUAL(s->getMZArray()->data.size(), 2) | |
| TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0) | |
| TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0) | |
| TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0) | |
| } | |
| END_SECTION | |
| START_SECTION((OpenSwath::SpectrumPtr getSpectrumById(int id))) | |
| { | |
| SpectrumAccessOpenMS origin(mkExp()); | |
| SpectrumAccessOpenMSInMemory sa(origin); | |
| OpenSwath::SpectrumPtr s = sa.getSpectrumById(0); | |
| TEST_EQUAL(s->getMZArray()->data.size(), 2) | |
| TEST_REAL_SIMILAR(s->getMZArray()->data[0], 100.0) | |
| TEST_REAL_SIMILAR(s->getMZArray()->data[1], 200.0) | |
| TEST_REAL_SIMILAR(s->getIntensityArray()->data[0], 500.0) | |
| TEST_REAL_SIMILAR(s->getIntensityArray()->data[1], 800.0) | |
| } | |
| END_SECTION |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 66 - 76, The intensity array validation in the getSpectrumById test
is incomplete. Currently, only data[1] is checked with TEST_REAL_SIMILAR for
s->getIntensityArray(), while data[0] is not validated. Add a TEST_REAL_SIMILAR
assertion for s->getIntensityArray()->data[0] before the existing data[1] check
to ensure consistent test coverage with the corresponding assertions for the mz
array and to match the validation pattern in SpectrumAccessOpenMS_test.cpp.
| START_SECTION((OpenSwath::SpectrumMeta getSpectrumMetaById(int id) const)) | ||
| { | ||
| SpectrumAccessOpenMS origin(mkExp()); | ||
| SpectrumAccessOpenMSInMemory sa(origin); | ||
| OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0); | ||
| TEST_REAL_SIMILAR(m.RT, 10.0) | ||
| } | ||
| END_SECTION |
There was a problem hiding this comment.
Incomplete assertion coverage for spectrum metadata.
Line 83 validates only the RT field but omits the ms_level field. The corresponding test in SpectrumAccessOpenMS_test.cpp (lines 92-93) validates both. Add an assertion for ms_level to ensure metadata is fully preserved by the in-memory copy.
🧪 Suggested fix
OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0);
TEST_REAL_SIMILAR(m.RT, 10.0)
+ TEST_EQUAL(m.ms_level, 1)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| START_SECTION((OpenSwath::SpectrumMeta getSpectrumMetaById(int id) const)) | |
| { | |
| SpectrumAccessOpenMS origin(mkExp()); | |
| SpectrumAccessOpenMSInMemory sa(origin); | |
| OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0); | |
| TEST_REAL_SIMILAR(m.RT, 10.0) | |
| } | |
| END_SECTION | |
| START_SECTION((OpenSwath::SpectrumMeta getSpectrumMetaById(int id) const)) | |
| { | |
| SpectrumAccessOpenMS origin(mkExp()); | |
| SpectrumAccessOpenMSInMemory sa(origin); | |
| OpenSwath::SpectrumMeta m = sa.getSpectrumMetaById(0); | |
| TEST_REAL_SIMILAR(m.RT, 10.0) | |
| TEST_EQUAL(m.ms_level, 1) | |
| } | |
| END_SECTION |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 78 - 85, The test for getSpectrumMetaById in the START_SECTION
block is incomplete and only validates the RT field of the returned SpectrumMeta
object m. Add an additional assertion to validate the ms_level field of the
metadata object to ensure complete coverage, matching the validation pattern
used in the corresponding test in SpectrumAccessOpenMS_test.cpp.
| START_SECTION((std::shared_ptr<OpenSwath::ISpectrumAccess> lightClone() const)) | ||
| { | ||
| SpectrumAccessOpenMS origin(mkExp()); | ||
| SpectrumAccessOpenMSInMemory sa(origin); | ||
| auto clone = sa.lightClone(); | ||
| TEST_NOT_EQUAL(clone.get(), nullptr) | ||
| TEST_EQUAL(clone->getNrSpectra(), 2) | ||
| } | ||
| END_SECTION |
There was a problem hiding this comment.
Incomplete assertion coverage for lightClone.
Line 104 validates only getNrSpectra but omits getNrChromatograms. The corresponding test in SpectrumAccessOpenMS_test.cpp (lines 131-132) validates both counts. Add an assertion for chromatogram count to ensure the clone fully preserves the in-memory state.
🧪 Suggested fix
auto clone = sa.lightClone();
TEST_NOT_EQUAL(clone.get(), nullptr)
TEST_EQUAL(clone->getNrSpectra(), 2)
+ TEST_EQUAL(clone->getNrChromatograms(), 1)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| START_SECTION((std::shared_ptr<OpenSwath::ISpectrumAccess> lightClone() const)) | |
| { | |
| SpectrumAccessOpenMS origin(mkExp()); | |
| SpectrumAccessOpenMSInMemory sa(origin); | |
| auto clone = sa.lightClone(); | |
| TEST_NOT_EQUAL(clone.get(), nullptr) | |
| TEST_EQUAL(clone->getNrSpectra(), 2) | |
| } | |
| END_SECTION | |
| START_SECTION((std::shared_ptr<OpenSwath::ISpectrumAccess> lightClone() const)) | |
| { | |
| SpectrumAccessOpenMS origin(mkExp()); | |
| SpectrumAccessOpenMSInMemory sa(origin); | |
| auto clone = sa.lightClone(); | |
| TEST_NOT_EQUAL(clone.get(), nullptr) | |
| TEST_EQUAL(clone->getNrSpectra(), 2) | |
| TEST_EQUAL(clone->getNrChromatograms(), 1) | |
| } | |
| END_SECTION |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tests/class_tests/openms/source/SpectrumAccessOpenMSInMemory_test.cpp`
around lines 98 - 106, The lightClone test section is missing an assertion for
chromatogram count validation. Add a TEST_EQUAL assertion for
clone->getNrChromatograms() immediately after the existing TEST_EQUAL for
clone->getNrSpectra() to ensure the cloned object fully preserves the in-memory
state, matching the assertion pattern used in the corresponding
SpectrumAccessOpenMS_test.cpp test. Determine the expected chromatogram count by
examining what the origin object contains or by checking the referenced test
file for the expected value.
Context
Part of the OpenMS 3.6.0 pre-release testing plan (#9460), §4 (OpenSwathWorkflow). Batched PR — two related untested data-access wrappers in one change.
SpectrumAccessOpenMSandSpectrumAccessOpenMSInMemoryadapt anMSExperimentto theOpenSwath::ISpectrumAccessinterface used throughout OpenSWATH; neither had a test.Change
Both build a small 2-spectrum / 1-chromatogram experiment and verify the interface:
SpectrumAccessOpenMS(wraps ashared_ptr<MSExperiment>):getNrSpectra/getNrChromatograms,getSpectrumById(m/z + intensity arrays),getSpectrumMetaById(RT, MS level),getSpectraByRT(RT-window lookup),getChromatogramById(time + intensity arrays),getChromatogramNativeID, andlightClone.SpectrumAccessOpenMSInMemory(pre-loads from anISpectrumAccess): the same spectrum/chromatogram counts and per-array values are reproduced from the in-memory copy, plusgetSpectrumMetaByIdandlightClone.Notes
executables.cmake(format_executables_list, DATAACCESS section, next to the existing SpectrumAccess tests).🤖 Generated with Claude Code
Summary by CodeRabbit