From 45d505721fac004d937a3303e9f2b02e880748af Mon Sep 17 00:00:00 2001 From: rly Date: Mon, 24 Jul 2023 21:53:23 -0400 Subject: [PATCH 1/2] Fix error with setting read_io to same obj twice --- src/hdmf/container.py | 2 +- tests/unit/test_container.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hdmf/container.py b/src/hdmf/container.py index dc93ff95d..0b285e8df 100644 --- a/src/hdmf/container.py +++ b/src/hdmf/container.py @@ -253,7 +253,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: diff --git a/tests/unit/test_container.py b/tests/unit/test_container.py index 4027ecb4e..420852e5f 100644 --- a/tests/unit/test_container.py +++ b/tests/unit/test_container.py @@ -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. @@ -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""" From df0bf08c87bf12bdf725578080940a4ae2c65ffd Mon Sep 17 00:00:00 2001 From: rly Date: Mon, 24 Jul 2023 21:55:25 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 490d08c48..faa2a2a31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)