Skip to content

Commit

Permalink
Adjust test to not count warnings on read (#1698)
Browse files Browse the repository at this point in the history
* Show uncaught warning correctly

* Adjust test to not check for warnings

* Update changelog

* Fix flake8
  • Loading branch information
rly authored Jun 25, 2023
1 parent 6a8cb1d commit 59e8075
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
[#1690](https://github.com/NeurodataWithoutBorders/pynwb/pull/1690)
- Update `requirements-doc.txt` to resolve Python 3.7 incompatibility. @rly
[#1694](https://github.com/NeurodataWithoutBorders/pynwb/pull/1694)
- Fixed test battery to show and check for warnings appropriately. @rly
[#1698](https://github.com/NeurodataWithoutBorders/pynwb/pull/1698)

## PyNWB 2.3.2 (April 10, 2023)

Expand Down
4 changes: 2 additions & 2 deletions src/pynwb/testing/testh5io.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def roundtripContainer(self, cache_spec=False):
BrokenLinkWarning)):
raise Exception('%s: %s' % (w.category.__name__, w.message))
else:
warnings.warn(w.message, w.category)
warnings.showwarning(w.message, w.category, w.filename, w.lineno, w.file, w.line)

try:
return self.getContainer(self.read_nwbfile)
Expand Down Expand Up @@ -141,7 +141,7 @@ def roundtripExportContainer(self, cache_spec=False):
BrokenLinkWarning)):
raise Exception('%s: %s' % (w.category.__name__, w.message))
else:
warnings.warn(w.message, w.category)
warnings.showwarning(w.message, w.category, w.filename, w.lineno, w.file, w.line)

try:
return self.getContainer(self.read_exported_nwbfile)
Expand Down
61 changes: 27 additions & 34 deletions tests/unit/test_epoch_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pynwb import NWBFile, NWBHDF5IO
from pynwb.base import TimeSeries, TimeSeriesReference, TimeSeriesReferenceVectorData
import numpy as np
import warnings
import h5py


Expand Down Expand Up @@ -66,41 +65,35 @@ def test_legacy_format(self):
nwbfile = NWBFile(description, identifier, self.start_time, file_create_date=self.create_date)
self.addContainer(nwbfile)

with warnings.catch_warnings(record=True) as ws:
# write the file
with NWBHDF5IO(self.filename, mode='w') as write_io:
write_io.write(nwbfile, cache_spec=False)
# Modify the HDF5 file to look like NWB 2.4 and earlier. This simply means
# modifying the neurodata_type on the TimeIntervals.timeseries column
with h5py.File(self.filename, mode='a') as infile:
infile['/intervals/epochs/timeseries'].attrs['neurodata_type'] = 'VectorData'
infile.attrs['nwb_version'] = '2.3.0'
# Make sure we didn't have warnings
self.assertEqual(len(ws), 0)
# write the file
with NWBHDF5IO(self.filename, mode='w') as write_io:
write_io.write(nwbfile, cache_spec=False)
# Modify the HDF5 file to look like NWB 2.4 and earlier. This simply means
# modifying the neurodata_type on the TimeIntervals.timeseries column
with h5py.File(self.filename, mode='a') as infile:
infile['/intervals/epochs/timeseries'].attrs['neurodata_type'] = 'VectorData'
infile.attrs['nwb_version'] = '2.3.0'

# Read the file back
with warnings.catch_warnings(record=True) as ws:
self.reader = NWBHDF5IO(self.filename, mode='r')
self.read_nwbfile = self.reader.read()
self.reader = NWBHDF5IO(self.filename, mode='r')
self.read_nwbfile = self.reader.read()

# Test that the VectorData column for timeseries has been converted to TimeSeriesReferenceVectorData
self.assertIsInstance(self.read_nwbfile.epochs.timeseries, TimeSeriesReferenceVectorData)
# Test that the VectorData column for timeseries has been converted to TimeSeriesReferenceVectorData
self.assertIsInstance(self.read_nwbfile.epochs.timeseries, TimeSeriesReferenceVectorData)

# Test that slicing into epochs.timeseries works as expected
re = self.read_nwbfile.epochs.timeseries[0]
self.assertIsInstance(re, TimeSeriesReference)
self.assertTupleEqual((re[0], re[1], re[2].object_id), (0, 5, nwbfile.get_acquisition('a').object_id))
# Test that slicing into epochs.timeseries works as expected
re = self.read_nwbfile.epochs.timeseries[0]
self.assertIsInstance(re, TimeSeriesReference)
self.assertTupleEqual((re[0], re[1], re[2].object_id), (0, 5, nwbfile.get_acquisition('a').object_id))

# Test that slicing into epochs works as expected
re = self.read_nwbfile.epochs[0:1]
self.assertListEqual(re.columns.tolist(), ['start_time', 'stop_time', 'temperature', 'tags', 'timeseries'])
for i in re.loc[0, 'timeseries']:
self.assertIsInstance(i, TimeSeriesReference)
self.assertTupleEqual(
(re.loc[0, 'timeseries'][0][0], re.loc[0, 'timeseries'][0][1], re.loc[0, 'timeseries'][0][2].object_id),
(0, 5, nwbfile.get_acquisition('a').object_id))
self.assertTupleEqual(
(re.loc[0, 'timeseries'][1][0], re.loc[0, 'timeseries'][1][1], re.loc[0, 'timeseries'][1][2].object_id),
(0, 3, nwbfile.get_acquisition('b').object_id))
# Make sure we didn't have warnings
self.assertEqual(len(ws), 0)
# Test that slicing into epochs works as expected
re = self.read_nwbfile.epochs[0:1]
self.assertListEqual(re.columns.tolist(), ['start_time', 'stop_time', 'temperature', 'tags', 'timeseries'])
for i in re.loc[0, 'timeseries']:
self.assertIsInstance(i, TimeSeriesReference)
self.assertTupleEqual(
(re.loc[0, 'timeseries'][0][0], re.loc[0, 'timeseries'][0][1], re.loc[0, 'timeseries'][0][2].object_id),
(0, 5, nwbfile.get_acquisition('a').object_id))
self.assertTupleEqual(
(re.loc[0, 'timeseries'][1][0], re.loc[0, 'timeseries'][1][1], re.loc[0, 'timeseries'][1][2].object_id),
(0, 3, nwbfile.get_acquisition('b').object_id))

0 comments on commit 59e8075

Please sign in to comment.