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

Catch critical warnings and throw errors in unit tests #1112

Merged
merged 9 commits into from
Jan 16, 2020
24 changes: 18 additions & 6 deletions tests/integration/ui_write/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import numpy as np
import h5py
import numpy.testing as npt
import warnings

from pynwb import get_manager, NWBFile, NWBHDF5IO, validate as pynwb_validate
from pynwb.testing import remove_test_file
from hdmf.backends.warnings import BrokenLinkWarning
from hdmf.backends.hdf5 import HDF5IO

from hdmf.build.warnings import MissingRequiredWarning, OrphanContainerWarning
from hdmf.container import Data, Container

CORE_NAMESPACE = 'core'
Expand Down Expand Up @@ -167,11 +169,21 @@ def roundtripContainer(self, cache_spec=False):
nwbfile = NWBFile(description, identifier, self.start_time, file_create_date=self.create_date)
self.addContainer(nwbfile)

self.writer = HDF5IO(self.filename, manager=get_manager(), mode='w')
self.writer.write(nwbfile, cache_spec=cache_spec)
self.writer.close()
self.reader = HDF5IO(self.filename, manager=get_manager(), mode='r')
self.read_nwbfile = self.reader.read()
with warnings.catch_warnings(record=True) as ws:
self.writer = HDF5IO(self.filename, manager=get_manager(), mode='w')
self.writer.write(nwbfile, cache_spec=cache_spec)
self.writer.close()
self.reader = HDF5IO(self.filename, manager=get_manager(), mode='r')
self.read_nwbfile = self.reader.read()

if ws:
for w in ws:
if issubclass(w.category, (MissingRequiredWarning,
OrphanContainerWarning,
BrokenLinkWarning)):
raise Exception('%s: %s' % (w.category.__name__, w.message))
else:
warnings.warn(w.message, w.category)

try:
tmp = self.getContainer(self.read_nwbfile)
Expand Down