Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation in NWB testing util classes #1782

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- For `NWBHDF5IO()`, change the default of arg `load_namespaces` from `False` to `True`. @bendichter [#1748](https://github.com/NeurodataWithoutBorders/pynwb/pull/1748)
- Add `NWBHDF5IO.can_read()`. @bendichter [#1703](https://github.com/NeurodataWithoutBorders/pynwb/pull/1703)
- Add `pynwb.get_nwbfile_version()`. @bendichter [#1703](https://github.com/NeurodataWithoutBorders/pynwb/pull/1703)
- 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)
- 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)
- Expose the offset, conversion and channel conversion parameters in `mock_ElectricalSeries`. @h-mayorquin [#1796](https://github.com/NeurodataWithoutBorders/pynwb/pull/1796)
- Expose `starting_time` in `mock_ElectricalSeries`. @h-mayorquin [#1805](https://github.com/NeurodataWithoutBorders/pynwb/pull/1805)
Expand Down
38 changes: 16 additions & 22 deletions src/pynwb/testing/testh5io.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_roundtrip_export(self):
self.assertIs(self.read_exported_nwbfile.objects[self.container.object_id], self.read_container)
self.assertContainerEqual(self.read_container, self.container, ignore_hdmf_attrs=True)

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

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

if os.path.exists(self.export_filename):
with NWBHDF5IO(self.filename, mode='r') as io:
errors = pynwb_validate(io)
if errors:
for err in errors:
raise Exception(err)
errors, _ = pynwb_validate(paths=[self.export_filename])
if errors:
raise Exception("\n".join(errors))


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

def roundtripContainer(self, cache_spec=False):
def roundtripContainer(self, cache_spec=True):
"""Write the file, validate the file, read the file, and return the Container from the file.
"""

Expand Down Expand Up @@ -325,7 +321,7 @@ def roundtripContainer(self, cache_spec=False):
self.reader = None
raise e

def roundtripExportContainer(self, cache_spec=False):
def roundtripExportContainer(self, cache_spec=True):
"""
Roundtrip the container, then export the read NWBFile to a new file, validate the files, and return the test
Container from the file.
Expand Down Expand Up @@ -366,13 +362,11 @@ def roundtripExportContainer(self, cache_spec=False):
def validate(self):
"""Validate the created files."""
if os.path.exists(self.filename):
with NWBHDF5IO(self.filename, mode='r') as io:
errors = pynwb_validate(io)
if errors:
raise Exception("\n".join(errors))
errors, _ = pynwb_validate(paths=[self.filename])
if errors:
raise Exception("\n".join(errors))

if os.path.exists(self.export_filename):
with NWBHDF5IO(self.filename, mode='r') as io:
errors = pynwb_validate(io)
if errors:
raise Exception("\n".join(errors))
errors, _ = pynwb_validate(paths=[self.export_filename])
if errors:
raise Exception("\n".join(errors))
Loading