Skip to content

Commit

Permalink
Fix get_hdf5io (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Sep 14, 2022
1 parent 25807f3 commit 2010de6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HDMF Changelog

## HDMF 3.5.0 (Upcoming)
## HDMF 3.4.3 (September 14, 2022)

### Minor improvements
- Began to deprecate the use of the testing script `test.py` in favor of `pytest` and `test_gallery.py`.
Expand All @@ -10,6 +10,7 @@
### Bug fixes
- Fixed CI and flake8 issues. @rly ([#760](https://github.com/hdmf-dev/hdmf/pull/760))
- Updated uses of pandas.DataFrame.set_index to avoid FutureWarnings for pandas >=1.5.x @oruebel ([#762](https://github.com/hdmf-dev/hdmf/pull/762))
- Fixed broken `hdmf.common.get_hdf5io` function. @rly ([#765](https://github.com/hdmf-dev/hdmf/pull/765))

## HDMF 3.4.2 (August 26, 2022)

Expand Down
4 changes: 2 additions & 2 deletions src/hdmf/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ def validate(**kwargs):
@docval(*get_docval(HDF5IO.__init__), is_method=False)
def get_hdf5io(**kwargs):
"""
A convenience method for getting an HDF5IO object
A convenience method for getting an HDF5IO object using an HDMF-common build manager if none is provided.
"""
manager = getargs('manager', kwargs)
if manager is None:
kwargs['manager'] = get_manager()
return HDF5IO.__init__(**kwargs)
return HDF5IO(**kwargs)


# load the hdmf-common namespace
Expand Down
22 changes: 21 additions & 1 deletion tests/unit/common/test_common_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from h5py import File

from hdmf.backends.hdf5 import HDF5IO
from hdmf.common import Container, get_manager
from hdmf.common import Container, get_manager, get_hdf5io
from hdmf.spec import NamespaceCatalog
from hdmf.testing import TestCase, remove_test_file

Expand Down Expand Up @@ -67,3 +67,23 @@ def _check_spec(self):
self.assertIsNotNone(cached_spec)
with self.subTest('Cached spec matches original spec'):
self.assertDictEqual(original_spec, cached_spec)


class TestGetHdf5IO(TestCase):

def setUp(self):
self.path = get_temp_filepath()

def tearDown(self):
remove_test_file(self.path)

def test_gethdf5io(self):
"""Test the get_hdf5io convenience method with manager=None."""
with get_hdf5io(self.path, "w") as io:
self.assertIsNotNone(io.manager)

def test_gethdf5io_manager(self):
"""Test the get_hdf5io convenience method with manager set."""
manager = get_manager()
with get_hdf5io(self.path, "w", manager=manager) as io:
self.assertIs(io.manager, manager)

0 comments on commit 2010de6

Please sign in to comment.