From f23ed5c6772d6fc56fe27bd847d1f24e360dc692 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sat, 21 Oct 2023 13:58:14 -0700 Subject: [PATCH 1/4] Fix validation in NWB testing util classes --- src/pynwb/testing/testh5io.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/pynwb/testing/testh5io.py b/src/pynwb/testing/testh5io.py index b45407bfb..b8055db0d 100644 --- a/src/pynwb/testing/testh5io.py +++ b/src/pynwb/testing/testh5io.py @@ -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): @@ -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)) From 167d7b26adafa532eba072def697014028dadcc8 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sat, 21 Oct 2023 14:15:46 -0700 Subject: [PATCH 2/4] Update testh5io.py to set cache_spec=True --- src/pynwb/testing/testh5io.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pynwb/testing/testh5io.py b/src/pynwb/testing/testh5io.py index b8055db0d..6b0bc3ae9 100644 --- a/src/pynwb/testing/testh5io.py +++ b/src/pynwb/testing/testh5io.py @@ -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 @@ -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 @@ -290,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. """ @@ -321,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. From 4ecf2dc12bffbff1450e76b530305398576a1761 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sat, 21 Oct 2023 14:20:51 -0700 Subject: [PATCH 3/4] Update testh5io.py --- src/pynwb/testing/testh5io.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pynwb/testing/testh5io.py b/src/pynwb/testing/testh5io.py index 6b0bc3ae9..c7b3bfdcc 100644 --- a/src/pynwb/testing/testh5io.py +++ b/src/pynwb/testing/testh5io.py @@ -163,12 +163,12 @@ def getContainer(self, nwbfile): def validate(self): """ Validate the created files """ if os.path.exists(self.filename): - errors = pynwb_validate(paths=[self.filename]) + errors, _ = pynwb_validate(paths=[self.filename]) if errors: raise Exception("\n".join(errors)) if os.path.exists(self.export_filename): - errors = pynwb_validate(paths=[self.export_filename]) + errors, _ = pynwb_validate(paths=[self.export_filename]) if errors: raise Exception("\n".join(errors)) @@ -362,11 +362,11 @@ def roundtripExportContainer(self, cache_spec=True): def validate(self): """Validate the created files.""" if os.path.exists(self.filename): - errors = pynwb_validate(paths=[self.filename]) + errors, _ = pynwb_validate(paths=[self.filename]) if errors: raise Exception("\n".join(errors)) if os.path.exists(self.export_filename): - errors = pynwb_validate(paths=[self.export_filename]) + errors, _ = pynwb_validate(paths=[self.export_filename]) if errors: raise Exception("\n".join(errors)) From 8bbe51a03f85e5d0c6cb8edf8441181fc55d6c3b Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Sun, 22 Oct 2023 11:01:37 -0700 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3a79232..c821f11c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Enhancements and minor changes - 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) ## PyNWB 2.5.0 (August 18, 2023)