Repository navigation
[pyOpenMS][TEST] Pin deep-copy independence (mutate copy, original unchanged) (#9460) - #9525
Conversation
…changed) (OpenMS#9460) test_copy_constructors.py proves copy.copy()/copy.deepcopy()/ClassName(obj) return the right type and compare equal to a default-constructed original, but it never mutates the copy, so it cannot catch the aliasing/object-slicing regression the nanobind rewrite fixed (a "copy" that shares the original's C++ storage; mutating it corrupts the original). Comparing two empty objects for equality passes regardless of shared state. This adds the contract OpenMS OpenMS#9460 §2 asks for: copy -> mutate the copy -> assert the original is unchanged For 17 classes (incl. AASequence, and the MetaInfoInterface containers MSExperiment/FeatureMap/ConsensusMap where shared vectors/maps would hide an aliasing bug) it builds a non-trivial instance, copies it three ways, mutates only the copy, and asserts: the copy starts with the original's value, mutating the copy leaves the original untouched, and the mutation took effect on the copy. 17 classes x 3 copy forms = 51 parametrized cases. Verified against the built nanobind bindings (51 passed). 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-15 14:47:43.112885708 +0000
+++ AUTHORS.new 2026-06-15 14:47:47.455919509 +0000
@@ -23,8 +23,8 @@
- Chirag Dave
- Chris Bauer
- Chris Bielow
- - Christie Mathews
- Christian Ehrlich
+ - Christie Mathews
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
📝 WalkthroughWalkthroughA new pytest module ChangesCopy Independence Test Suite
Possibly related PRs
Poem
🚥 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.
🧹 Nitpick comments (1)
src/pyOpenMS/tests/unittests/test_copy_independence.py (1)
39-39: ⚡ Quick winRefactor builder functions to avoid compound statements.
PEP 8 discourages compound statements (multiple statements on the same line). Split these into separate lines for better readability and compliance.
♻️ Proposed refactor
Example for
_b_peak1d:def _b_peak1d(): - o = pyopenms.Peak1D(); o.setMZ(100.0); return o + o = pyopenms.Peak1D() + o.setMZ(100.0) + return oApply the same pattern to all other builder functions (lines 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 75, 78, 81, 84, 87).
Also applies to: 42-42, 45-45, 48-48, 51-51, 54-54, 57-57, 60-60, 63-63, 66-66, 69-69, 75-75, 78-78, 81-81, 84-84, 87-87
🤖 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/pyOpenMS/tests/unittests/test_copy_independence.py` at line 39, Multiple builder functions in this file use compound statements on single lines, violating PEP 8 conventions. Split each builder function (such as _b_peak1d and all other similar builder functions throughout the file) so that each statement appears on its own line instead of using semicolons to chain multiple statements together. This applies consistently to all builder functions that currently have multiple statements separated by semicolons on the same line.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@src/pyOpenMS/tests/unittests/test_copy_independence.py`:
- Line 39: Multiple builder functions in this file use compound statements on
single lines, violating PEP 8 conventions. Split each builder function (such as
_b_peak1d and all other similar builder functions throughout the file) so that
each statement appears on its own line instead of using semicolons to chain
multiple statements together. This applies consistently to all builder functions
that currently have multiple statements separated by semicolons on the same
line.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8487e240-fdb4-4cdf-9936-1f8c3eeef179
📒 Files selected for processing (1)
src/pyOpenMS/tests/unittests/test_copy_independence.py
What
Adds
test_copy_independence.py: for 17 pyopenms classes it builds a non-trivial instance, copies it three ways (copy.copy,copy.deepcopy,ClassName(obj)), mutates only the copy, and asserts the original is unchanged (and that the mutation took effect on the copy). 17 classes × 3 copy forms = 51 parametrized cases.Why
This closes a real, still-open part of the §2 (pyOpenMS nanobind rewrite)
[AUTO]task in the OpenMS 3.6.0 pre-release testing plan (#9460):The existing
test_copy_constructors.pyparametrizes over every copyable class, but it default-constructs an empty object, copies it, and only checkstype(copy) is type(orig)pluscopy == orig. Two freshly-constructed empty objects compare equal whether or not they share underlying C++ storage, and the copy is never mutated — so that sweep cannot catch the exact aliasing / object-slicing regression the nanobind rewrite fixed (an old binding could return a "copy" that aliases the original, so mutating the copy silently corrupts the original).This test pins that independence contract directly.
Coverage
Scalar setter/getter classes:
Peak1D,Peak2D,Residue,PeptideHit,PeptideIdentification,ProteinIdentification,MSSpectrum,MSChromatogram,Precursor,Feature,ConsensusFeature,Param,DateTime; the named exampleAASequence(mutated viasetNTerminalModification); and theMetaInfoInterfacecontainer typesMSExperiment,FeatureMap,ConsensusMap— where shared internal vectors/maps are exactly where an aliasing bug would hide.Test plan
Tests only — no production code changed. Verified against the built nanobind bindings:
The assertions are non-vacuous: each case checks the copy starts equal to the original, the original is unchanged after mutating the copy, and the mutation actually changed the copy.
Part of #9460. Complements #9524 (Bruker TDF native-ID parser test).
🤖 Generated with Claude Code
Summary by CodeRabbit