-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enh/ ImageSeries
: add checks when external_file
is used
#1516
Enh/ ImageSeries
: add checks when external_file
is used
#1516
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #1516 +/- ##
==========================================
+ Coverage 90.52% 90.65% +0.12%
==========================================
Files 25 25
Lines 2460 2494 +34
Branches 456 466 +10
==========================================
+ Hits 2227 2261 +34
Misses 148 148
Partials 85 85
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There are tests in pynwb/tests/unit/test_ophys.py Lines 46 to 55 in b11bffc
@oruebel, should I change all of these or what is the best way to proceed? |
Yes, I think updating the tests is the right approach. Looking at those tests, I believe the starting_frame is indeed set incorrectly in those tests. |
Co-authored-by: Oliver Ruebel <[email protected]>
@oruebel Seems like back compatibility tests are failing, how can I resolve them? |
ImageSeries
: check starting_frame
when external_file
is usedImageSeries
: add checks when external_file
is used
src/pynwb/image.py
Outdated
if not self._in_construct_mode: | ||
raise ValueError(error_msg) | ||
warnings.warn(error_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have also a test for Line 136 to check that warning are raised on read. Creating invalid files to test all these options may be too involved just to test this behavior, but I think we could just copy the pattern from the ObjectMapper itself in the test:
I.e., call __new__
explicitly to set in_construct_mode=True
and then call __init__
with the invalid data to check if the warnings are raised as expected. I.e., a test would look something like:
def test_warn_on_bad_starting_frame():
obj = ImageSeries.__new__(ImageSeries, container_source=None, parent=None, object_id="test", in_construct_mode=True)
with self.assertWarnsWith(ValueError, "...message..."):
obj.__init__(........arguments for ImageSeries.....)
obj._in_construct_mode = False
Setting obj._in_construct_mode = False
should only be necessary of you continue to the use the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looking at the tests, it looks like you are already testing this with actual files. Maybe the backward compatibility tests are not counted in codecov? @rly
@weiglszonja so I don't think we need to add more tests, but it would still be interesting to know why codecov indicates that Line 136 ids not covered when it seems like it should be based on the tests you added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backward compatibility tests are currently not counted in codecov, but now that we are including integration tests in codecov, I think it makes sense to include the backward compatibility tests too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rly for the clarification. That makes sense. I added a couple of extra unit-tests anyways to cover this case there as well. I think those tests are useful also because they show how we can write unittests that mimic the use-case were we need to distinguish between construct mode on read and regular user mode.
@weiglszonja overall this PR looks good. Normally, I would have just approved this PR as is, however, since this is the first example where we distinguish between warning on read and error on new, I think it will be useful to spent the extra effort to have the pattern we use for this in the code as clean as possible as others will likely follow the pattern we set here in the future. I think the suggestions I made should only require some minor reshuffling of lines of code, so hopefully the extra effort should not be too much. Thanks a lot for your patience and help! |
Co-authored-by: Oliver Ruebel <[email protected]>
I just added variants of the three relevant unit test cases that you had added to run the same test also in construct mode. I think that should take care of the codecov. codecov is I believe running the different tests suits (unit, integration, back_combat etc.) separately and my guess is that for some reason it is only considering the unit tests here. Adding tests in the unit test suit should, therefore, hopefully fix this. |
Motivation
This PR is a continuation of the issue described in #1510 by raising a
ValueError
whenstarting_frame
does not have the same length asexternal_file
.NWBMixin
that only raises an error when a check is violated on instance creation,otherwise throws a warning when reading from a file.
The new checks is used with this method to ensure that that files with invalid data can be read, but prohibits the user from creating new instances when these checks are violated.
New checks:
starting_frame
must match the length ofexternal_file
whenexternal_file
is specified'external'
whenexternal_file
is specifieddata
must be empty array whenexternal_file
is specifiedValueError
is raised when a check is violated on instance creation,but only warns when file is read from disk.
Default values:
starting_frame
is[0]
whenexternal_file
has a length of 1format
is'external'
when format was originally None andexternal_file
is specified (DeprecationWarning
is raised)Fix #1510
How to test the behavior?
Unittests are added in
tests/unit/test_image.py
Checklist
flake8
from the source directory.