Skip to content

Commit

Permalink
combine contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed May 4, 2022
1 parent c8090db commit 606457c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions nwbinspector/nwbinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ def inspect_nwb(
nwbfile_path = str(nwbfile_path)
filterwarnings(action="ignore", message="No cached namespaces found in .*")
filterwarnings(action="ignore", message="Ignoring cached namespace .*")
if not skip_validate:
with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io:
with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io:
if not skip_validate:
validation_errors = pynwb.validate(io=io)
for validation_error in validation_errors:
yield InspectorMessage(
Expand All @@ -466,19 +466,18 @@ def inspect_nwb(
file_path=nwbfile_path,
)

try:
with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io:
try:
nwbfile = io.read()
for inspector_message in run_checks(nwbfile=nwbfile, checks=checks):
inspector_message.file_path = nwbfile_path
yield inspector_message
except Exception as ex:
yield InspectorMessage(
message=traceback.format_exc(),
importance=Importance.ERROR,
check_function_name=f"During io.read() - {type(ex)}: {str(ex)}",
file_path=nwbfile_path,
)
except Exception as ex:
yield InspectorMessage(
message=traceback.format_exc(),
importance=Importance.ERROR,
check_function_name=f"During io.read() - {type(ex)}: {str(ex)}",
file_path=nwbfile_path,
)


def run_checks(nwbfile: pynwb.NWBFile, checks: list):
Expand Down

0 comments on commit 606457c

Please sign in to comment.