Skip to content

Commit 5d0e98d

Browse files
authored
Fix validation in NWB testing util classes (#1782)
1 parent dd6baaa commit 5d0e98d

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- For `NWBHDF5IO()`, change the default of arg `load_namespaces` from `False` to `True`. @bendichter [#1748](https://github.com/NeurodataWithoutBorders/pynwb/pull/1748)
77
- Add `NWBHDF5IO.can_read()`. @bendichter [#1703](https://github.com/NeurodataWithoutBorders/pynwb/pull/1703)
88
- Add `pynwb.get_nwbfile_version()`. @bendichter [#1703](https://github.com/NeurodataWithoutBorders/pynwb/pull/1703)
9+
- Fix usage of the `validate` function in the `pynwb.testing.testh5io` classes and cache the spec by default in those classes. @rly [#1782](https://github.com/NeurodataWithoutBorders/pynwb/pull/1782)
910
- Updated timeseries data checks to warn instead of error when reading invalid files. @stephprince [#1793](https://github.com/NeurodataWithoutBorders/pynwb/pull/1793) and [#1809](https://github.com/NeurodataWithoutBorders/pynwb/pull/1809)
1011
- Expose the offset, conversion and channel conversion parameters in `mock_ElectricalSeries`. @h-mayorquin [#1796](https://github.com/NeurodataWithoutBorders/pynwb/pull/1796)
1112
- Expose `starting_time` in `mock_ElectricalSeries`. @h-mayorquin [#1805](https://github.com/NeurodataWithoutBorders/pynwb/pull/1805)

src/pynwb/testing/testh5io.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_roundtrip_export(self):
7979
self.assertIs(self.read_exported_nwbfile.objects[self.container.object_id], self.read_container)
8080
self.assertContainerEqual(self.read_container, self.container, ignore_hdmf_attrs=True)
8181

82-
def roundtripContainer(self, cache_spec=False):
82+
def roundtripContainer(self, cache_spec=True):
8383
"""Add the Container to an NWBFile, write it to file, read the file, and return the Container from the file.
8484
"""
8585
session_description = 'a file to test writing and reading a %s' % self.container_type
@@ -116,7 +116,7 @@ def roundtripContainer(self, cache_spec=False):
116116
self.reader = None
117117
raise e
118118

119-
def roundtripExportContainer(self, cache_spec=False):
119+
def roundtripExportContainer(self, cache_spec=True):
120120
"""
121121
Add the test Container to an NWBFile, write it to file, read the file, export the read NWBFile to another
122122
file, and return the test Container from the file
@@ -163,18 +163,14 @@ def getContainer(self, nwbfile):
163163
def validate(self):
164164
""" Validate the created files """
165165
if os.path.exists(self.filename):
166-
with NWBHDF5IO(self.filename, mode='r') as io:
167-
errors = pynwb_validate(io)
168-
if errors:
169-
for err in errors:
170-
raise Exception(err)
166+
errors, _ = pynwb_validate(paths=[self.filename])
167+
if errors:
168+
raise Exception("\n".join(errors))
171169

172170
if os.path.exists(self.export_filename):
173-
with NWBHDF5IO(self.filename, mode='r') as io:
174-
errors = pynwb_validate(io)
175-
if errors:
176-
for err in errors:
177-
raise Exception(err)
171+
errors, _ = pynwb_validate(paths=[self.export_filename])
172+
if errors:
173+
raise Exception("\n".join(errors))
178174

179175

180176
class AcquisitionH5IOMixin(NWBH5IOMixin):
@@ -294,7 +290,7 @@ def test_roundtrip_export(self):
294290
self.assertIs(self.read_exported_nwbfile.objects[self.container.object_id], self.read_container)
295291
self.assertContainerEqual(self.read_container, self.container, ignore_hdmf_attrs=True)
296292

297-
def roundtripContainer(self, cache_spec=False):
293+
def roundtripContainer(self, cache_spec=True):
298294
"""Write the file, validate the file, read the file, and return the Container from the file.
299295
"""
300296

@@ -325,7 +321,7 @@ def roundtripContainer(self, cache_spec=False):
325321
self.reader = None
326322
raise e
327323

328-
def roundtripExportContainer(self, cache_spec=False):
324+
def roundtripExportContainer(self, cache_spec=True):
329325
"""
330326
Roundtrip the container, then export the read NWBFile to a new file, validate the files, and return the test
331327
Container from the file.
@@ -366,13 +362,11 @@ def roundtripExportContainer(self, cache_spec=False):
366362
def validate(self):
367363
"""Validate the created files."""
368364
if os.path.exists(self.filename):
369-
with NWBHDF5IO(self.filename, mode='r') as io:
370-
errors = pynwb_validate(io)
371-
if errors:
372-
raise Exception("\n".join(errors))
365+
errors, _ = pynwb_validate(paths=[self.filename])
366+
if errors:
367+
raise Exception("\n".join(errors))
373368

374369
if os.path.exists(self.export_filename):
375-
with NWBHDF5IO(self.filename, mode='r') as io:
376-
errors = pynwb_validate(io)
377-
if errors:
378-
raise Exception("\n".join(errors))
370+
errors, _ = pynwb_validate(paths=[self.export_filename])
371+
if errors:
372+
raise Exception("\n".join(errors))

0 commit comments

Comments
 (0)