Skip to content

Commit

Permalink
Fix error with setting read_io to same obj twice (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Jul 25, 2023
1 parent 06ee477 commit 64a444f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
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

0 comments on commit 64a444f

Please sign in to comment.