fix imread bug and allow AICSImage class to close its reader#44
Conversation
| with pytest.raises(IOError): | ||
| img = AICSImage(tempfilename) | ||
| img.metadata | ||
| os.remove(tempfilename) |
There was a problem hiding this comment.
I looked this up. It won't ever raise on Unix.
If a Filepointer is open on *nix it has translated the name to a pointer.
if you remove the file after this step it will nuke the file name but it the on-disk space pointed to by the pointer isn't closed until there are no pointer references into the file.
Windows is fundamentally different.
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
==========================================
+ Coverage 87.96% 88.12% +0.16%
==========================================
Files 27 27
Lines 1113 1128 +15
==========================================
+ Hits 979 994 +15
Misses 134 134
Continue to review full report at Codecov.
|
heeler
left a comment
There was a problem hiding this comment.
Nice, clever solution using _bytes rather than querying the filesystem
evamaxfield
left a comment
There was a problem hiding this comment.
As a part of this can you update the quick start in the README as well?
| ) | ||
| def test_aicsimage_close(resources_dir, filename): | ||
| img = AICSImage(resources_dir / filename) | ||
| assert img.reader._bytes.closed is False |
There was a problem hiding this comment.
The """pythonic""" way to do this is assert not img.reader._bytes.closed 🙃
There was a problem hiding this comment.
But I like this better tbh
|
|
||
| with AICSImage(resources_dir / filename) as img: | ||
| img.metadata | ||
| assert img.reader._bytes.closed is True |
There was a problem hiding this comment.
This one should definitely just be assert img.reader._bytes.closed
The fixes a bug with
imreadwhich was leaving the file handle open. It also allows thewith AICSImage as varnamesyntax, and adds a public method to close the reader.