Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1521 +/- ##
==========================================
- Coverage 93.22% 93.14% -0.08%
==========================================
Files 41 41
Lines 10168 10186 +18
Branches 2100 2104 +4
==========================================
+ Hits 9479 9488 +9
- Misses 413 421 +8
- Partials 276 277 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
for more information, see https://pre-commit.ci
|
Added validate quantity and tests for validate_quantity, updated change log, and converted to private static method. Added name as parameter as outside scope for validate_quantity. |
| 'doc': 'The default name of this base storage container, used only if name is None', 'default': None}, | ||
| {'name': 'attributes', 'type': list, 'doc': 'the attributes on this group', 'default': list()}, | ||
| {'name': 'linkable', 'type': bool, 'doc': 'whether or not this group can be linked', 'default': True}, | ||
| {'name': 'quantity', 'type': (str, int), 'doc': 'the required number of allowed instance', 'default': 1}, |
There was a problem hiding this comment.
Since the behavior for quantity has changed, it may be useful to clarify this also here in the doc for the parameter
There was a problem hiding this comment.
This still seems correct as we simply expanded the handling inputs and not the required values.
There was a problem hiding this comment.
Since we're updating how "quantity" is handled, this is a good time to make this docstring more informative. Could you update it to say something like f"the required number of instances. Must be a positive integer, a string representation of a positive integer, or one of the flag keys {list(FLAGS.keys())} or values {list(FLAGS.values())}."
There was a problem hiding this comment.
Pull request overview
This PR addresses Issue #531 by adding validation/normalization for spec quantity values so that numeric strings can be handled consistently (instead of being treated as wildcard/many quantities).
Changes:
- Added centralized quantity validation in
BaseStorageSpec(including numeric-string handling). - Added unit tests for invalid
quantityinputs onGroupSpec. - Added a changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/hdmf/spec/spec.py |
Introduces __validate_quantity and applies it during BaseStorageSpec initialization. |
tests/unit/spec_tests/test_group_spec.py |
Adds regression tests for invalid quantity inputs. |
CHANGELOG.md |
Adds a release note entry for Issue #531. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Returns: | ||
| A validated quantity string. | ||
|
|
||
| Raises: | ||
| ValueError: If quantity is not in FLAGS or is not >=1. | ||
| TypeError: If quantity is not an integer. | ||
| """ |
There was a problem hiding this comment.
The new docstring still says TypeError
| def test_quantity_with_string_float(self): | ||
| msg = ("Invalid quantity '3.5': must be greater than or equal to 1 or in '[?, *, +]'") | ||
| with self.assertRaisesWith(ValueError, msg): | ||
| GroupSpec(doc='A test group', name='MyGroup', quantity='3.5') | ||
|
|
There was a problem hiding this comment.
Agreed, no valid testing code section for quantity
There was a problem hiding this comment.
A positive test like what is described would be good to add.
There was a problem hiding this comment.
You can add it to test_dataset_spec.py where the other positive tests live currently
|
The code looks overall good to me. I added a few suggestions mostly related to documentation and asked Copilot to review. I'll let @rly do final review and approvals. |
|
@oruebel Thanks, I updated everything and will push again based on the suggestions. Except I ddint see positive tests. copilot: "These tests cover invalid quantity strings, but they don't assert the new intended behavior from #531: numeric strings like '2' should be accepted and treated as integers (so '1' does not imply 'many'). Adding a positive-case regression test would prevent the original bug from reappearing." |
| - Hardened the GitHub Actions CI: added least-privilege `permissions` blocks, pinned actions to commit SHAs (or immutable release tags), deduplicated the test setup into a composite action, passed untrusted inputs through environment variables, and added a zizmor security audit of the workflows. @rly [#1518](https://github.com/hdmf-dev/hdmf/pull/1518) | ||
|
|
||
| ### Fixed | ||
| - Fix #531 Validate quantity specified with an integor or numeric string @jwbear [#1521] |
There was a problem hiding this comment.
Please add the URL to the end of this line so that #1521 renders as a Markdown link in the changelog
There was a problem hiding this comment.
Also please make this past tense, and correct spelling of "integer". "Quantity" should be clarified to be GroupSpec and DatasetSpec quantity. We typically don't mention the issue number since the PR links back to the issue. Either way is fine. So something like:
- Fixed issue #531 where invalid values were accepted for `GroupSpec.quantity` and `DatasetSpec.quantity`. Now only positive integers, string representations of positive integers, and '?', '*', and '+' are allowed. @jwbear [#1521](https://github.com/hdmf-dev/hdmf/pull/1521)
There was a problem hiding this comment.
Please update text to be more descriptive of the change to users. Something like the above
ISSUE #531
Motivation
What was the reasoning behind this change? Please explain the changes briefly.
Fix #531
How to test the behavior?
Test FLAGS not in dictionary, integers, strings, and integers entered as strings eg "2"
Checklist
CHANGELOG.mdwith your changes?