Skip to content
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

Fix error with setting read_io to same obj twice #915

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# HDMF Changelog

## HDMF 3.8.0 (July 21,2023)
## HDMF 3.8.1 (July 25, 2023)

### Bug fixes
- Fixed error when calling `HDF5IO.read` twice. @rly [#915](https://github.com/hdmf-dev/hdmf/pull/915)

## HDMF 3.8.0 (July 21, 2023)

### New features and minor improvements
- Added the ability to write ExternalResources if the path is provided and the container has a linked instance of ExternalResources. @mavaylon1 [#910](https://github.com/hdmf-dev/hdmf/pull/910)
Expand Down
2 changes: 1 addition & 1 deletion src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def read_io(self, value):
from hdmf.backends.io import HDMFIO
if not isinstance(value, HDMFIO):
raise TypeError("io must be an instance of HDMFIO")
if self.__read_io is not None:
if self.__read_io is not None and self.__read_io is not value:
raise ValueError("io has already been set for this container (name=%s, type=%s)" %
(self.name, str(type(self))))
else:
Expand Down
14 changes: 10 additions & 4 deletions tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ class TestContainer(TestCase):

def setUp(self):
self.path = "test_container.h5"
self.path2 = "test_container2.h5"

def tearDown(self):
if os.path.exists(self.path):
os.remove(self.path)
if os.path.exists(self.path2):
os.remove(self.path2)

def test_new(self):
"""Test that __new__ properly sets parent and other fields.
Expand Down Expand Up @@ -105,12 +108,15 @@ def test_read_io_setter(self):
with self.assertRaises(TypeError):
obj.read_io = "test"
# Set read_io
with HDF5IO(self.path, mode='w') as temp_io:
with HDF5IO(self.path, mode='w') as temp_io:
obj.read_io = temp_io
self.assertIs(obj.read_io, temp_io)
# Check that setting read_io again fails
with self.assertRaises(ValueError):
obj.read_io = temp_io
# test that setting the read_io object to the same io object is OK
obj.read_io = temp_io
# Check that setting read_io to another io object fails
with HDF5IO(self.path2, mode='w') as temp_io2:
with self.assertRaises(ValueError):
obj.read_io = temp_io2

def test_get_read_io_on_self(self):
"""Test that get_read_io works when the container is set on the container"""
Expand Down