Skip to content

Commit 64a444f

Browse files
authored
Fix error with setting read_io to same obj twice (#915)
1 parent 06ee477 commit 64a444f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# HDMF Changelog
22

3-
## HDMF 3.8.0 (July 21,2023)
3+
## HDMF 3.8.1 (July 25, 2023)
4+
5+
### Bug fixes
6+
- Fixed error when calling `HDF5IO.read` twice. @rly [#915](https://github.com/hdmf-dev/hdmf/pull/915)
7+
8+
## HDMF 3.8.0 (July 21, 2023)
49

510
### New features and minor improvements
611
- 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)

src/hdmf/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def read_io(self, value):
256256
from hdmf.backends.io import HDMFIO
257257
if not isinstance(value, HDMFIO):
258258
raise TypeError("io must be an instance of HDMFIO")
259-
if self.__read_io is not None:
259+
if self.__read_io is not None and self.__read_io is not value:
260260
raise ValueError("io has already been set for this container (name=%s, type=%s)" %
261261
(self.name, str(type(self))))
262262
else:

tests/unit/test_container.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ class TestContainer(TestCase):
4545

4646
def setUp(self):
4747
self.path = "test_container.h5"
48+
self.path2 = "test_container2.h5"
4849

4950
def tearDown(self):
5051
if os.path.exists(self.path):
5152
os.remove(self.path)
53+
if os.path.exists(self.path2):
54+
os.remove(self.path2)
5255

5356
def test_new(self):
5457
"""Test that __new__ properly sets parent and other fields.
@@ -105,12 +108,15 @@ def test_read_io_setter(self):
105108
with self.assertRaises(TypeError):
106109
obj.read_io = "test"
107110
# Set read_io
108-
with HDF5IO(self.path, mode='w') as temp_io:
111+
with HDF5IO(self.path, mode='w') as temp_io:
109112
obj.read_io = temp_io
110113
self.assertIs(obj.read_io, temp_io)
111-
# Check that setting read_io again fails
112-
with self.assertRaises(ValueError):
113-
obj.read_io = temp_io
114+
# test that setting the read_io object to the same io object is OK
115+
obj.read_io = temp_io
116+
# Check that setting read_io to another io object fails
117+
with HDF5IO(self.path2, mode='w') as temp_io2:
118+
with self.assertRaises(ValueError):
119+
obj.read_io = temp_io2
114120

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

0 commit comments

Comments
 (0)