Skip to content

Commit c6f9512

Browse files
committed
fixed tests
1 parent ccfefc6 commit c6f9512

File tree

5 files changed

+16
-75
lines changed

5 files changed

+16
-75
lines changed

nwbinspector/register_checks.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
from typing import Optional
77

88
import h5py
9+
from pynwb import NWBFile
10+
from pynwb.file import Subject
11+
from pynwb.ecephys import Device, ElectrodeGroup
12+
13+
KNOWN_LOCATIONS = {
14+
NWBFile: "/",
15+
Subject: "/subject",
16+
Device: "/general/devices",
17+
ElectrodeGroup: "/general/extracellular_ephys/",
18+
# TODO: add ophys equivalents
19+
}
920

1021

1122
class Importance(Enum):
@@ -71,7 +82,7 @@ class InspectorMessage:
7182
check_function_name: str = ""
7283
object_type: str = ""
7384
object_name: str = ""
74-
location: str = ""
85+
location: Optional[str] = None
7586
file_path: str = ""
7687

7788

@@ -154,16 +165,7 @@ def auto_parse(check_function, obj, result: Optional[InspectorMessage] = None):
154165
return auto_parsed_result
155166

156167

157-
known_location_dict = dict(
158-
nwbfile="/",
159-
subject="/subject",
160-
devices="/general/devices",
161-
electrode_group="/general/extracellular_ephys/",
162-
# TODO: add ophys equivalents
163-
)
164-
165-
166-
def parse_location(neurodata_object) -> str:
168+
def parse_location(neurodata_object) -> Optional[str]:
167169
"""Infer the human-readable path of the object within an NWBFile by tracing its parents."""
168170
if neurodata_object.parent is None:
169171
return "/"
@@ -174,4 +176,4 @@ def parse_location(neurodata_object) -> str:
174176
for field in neurodata_object.fields.values():
175177
if isinstance(field, h5py.Dataset):
176178
return "/".join(field.parent.name.split("/")[:-1]) + "/"
177-
return known_location_dict.get(neurodata_object, None)
179+
return KNOWN_LOCATIONS.get(type(neurodata_object))

tests/test_inspector.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ def iterable_check_function(table: DynamicTable):
405405
check_function_name="iterable_check_function",
406406
object_type="TimeIntervals",
407407
object_name="test_table",
408-
location="/acquisition/",
409408
file_path=self.nwbfile_paths[0],
410409
),
411410
InspectorMessage(
@@ -414,7 +413,6 @@ def iterable_check_function(table: DynamicTable):
414413
check_function_name="iterable_check_function",
415414
object_type="TimeIntervals",
416415
object_name="test_table",
417-
location="/acquisition/",
418416
file_path=self.nwbfile_paths[0],
419417
),
420418
]
@@ -439,55 +437,3 @@ def test_inspect_nwb_manual_iteration_stop(self):
439437
generator = inspect_nwb(nwbfile_path=self.nwbfile_paths[2], checks=self.checks)
440438
with self.assertRaises(expected_exception=StopIteration):
441439
next(generator)
442-
443-
444-
class TestSessionStartTimesOnFile(TestCase):
445-
@classmethod
446-
def setUpClass(cls):
447-
cls.tempdir = Path(mkdtemp())
448-
cls.nwbfile_path = cls.tempdir / "test.nwb"
449-
nwbfile = make_minimal_nwbfile()
450-
nwbfile.add_acquisition(DynamicTable(name="test", description=""))
451-
with NWBHDF5IO(path=cls.nwbfile_path, mode="w") as io:
452-
io.write(nwbfile)
453-
454-
@classmethod
455-
def tearDownClass(cls):
456-
rmtree(cls.tempdir)
457-
458-
def test_check_session_start_time_old_date_through_inspect_nwb(self):
459-
results = list(
460-
inspect_nwb(
461-
# nwbfile_path=self.nwbfile_path,
462-
nwbfile_path=self.nwbfile_path,
463-
checks=[check_session_start_time_old_date],
464-
)
465-
)
466-
results_errors = [x for x in results if x.importance.name == "ERROR"]
467-
assert results_errors == []
468-
469-
def test_check_session_start_time_old_date_through_inspect_nwb_before_description_check(self):
470-
results = list(
471-
inspect_nwb(
472-
nwbfile_path=self.nwbfile_path,
473-
checks=[check_session_start_time_old_date, check_description],
474-
)
475-
)
476-
results_errors = [x for x in results if x.importance.name == "ERROR"]
477-
assert results_errors == []
478-
479-
def test_check_session_start_time_old_date_through_inspect_nwb_with_description_check(self):
480-
results = list(
481-
inspect_nwb(
482-
# nwbfile_path=self.nwbfile_path,
483-
nwbfile_path=self.nwbfile_path,
484-
checks=[check_description, check_session_start_time_old_date],
485-
)
486-
)
487-
results_errors = [x for x in results if x.importance.name == "ERROR"]
488-
assert len(results_errors) != 0
489-
# TODO: what this test really should call is below; need to figure out source cause
490-
# print(results_errors)
491-
# if results_errors:
492-
# print(results_errors[0].message)
493-
# assert results_errors == []

tests/unit_tests/test_ecephys.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def test_check_electrical_series_wrong_dims(self):
8989
check_function_name="check_electrical_series_dims",
9090
object_type="ElectricalSeries",
9191
object_name="elec_series",
92-
location="/acquisition/",
9392
)
9493

9594
def test_check_electrical_series_flipped(self):
@@ -112,7 +111,6 @@ def test_check_electrical_series_flipped(self):
112111
check_function_name="check_electrical_series_dims",
113112
object_type="ElectricalSeries",
114113
object_name="elec_series",
115-
location="/acquisition/",
116114
)
117115

118116
def test_pass(self):
@@ -138,7 +136,6 @@ def test_trigger_check_electrical_series_reference_electrodes_table(self):
138136
dyn_tab.add_column("name", "desc")
139137
for i in range(5):
140138
dyn_tab.add_row(name=1)
141-
142139
dynamic_table_region = DynamicTableRegion(
143140
name="electrodes", description="I am wrong", data=[0, 1, 2, 3, 4], table=dyn_tab
144141
)

tests/unit_tests/test_nwbfile_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_check_subject_sex():
204204
check_function_name="check_subject_sex",
205205
object_type="Subject",
206206
object_name="subject",
207-
location="",
207+
location="/subject"
208208
)
209209

210210

tests/unit_tests/test_ophys.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
check_roi_response_series_dims,
1212
check_roi_response_series_link_to_plane_segmentation,
1313
)
14-
from nwbinspector.register_checks import InspectorMessage, Importance, Severity
14+
from nwbinspector.register_checks import InspectorMessage, Importance
1515

1616

1717
class TestCheckRoiResponseSeries(TestCase):
@@ -84,7 +84,6 @@ def test_check_flipped_dims(self):
8484
check_function_name="check_roi_response_series_dims",
8585
object_type="RoiResponseSeries",
8686
object_name="RoiResponseSeries",
87-
location="/processing/ophys/",
8887
)
8988

9089
def test_check_wrong_dims(self):
@@ -110,7 +109,6 @@ def test_check_wrong_dims(self):
110109
check_function_name="check_roi_response_series_dims",
111110
object_type="RoiResponseSeries",
112111
object_name="RoiResponseSeries",
113-
location="/processing/ophys/",
114112
)
115113

116114
def test_pass_check_roi_response_series_dims(self):
@@ -134,7 +132,6 @@ def test_check_roi_response_series_link_to_plane_segmentation(self):
134132
dt.add_column("a", "desc")
135133
for _ in range(5):
136134
dt.add_row(a=1)
137-
138135
dtr = DynamicTableRegion(name="n", description="desc", data=[0, 1, 2, 3, 4], table=dt)
139136
roi_resp_series = RoiResponseSeries(
140137
name="RoiResponseSeries",
@@ -152,7 +149,6 @@ def test_check_roi_response_series_link_to_plane_segmentation(self):
152149
check_function_name="check_roi_response_series_link_to_plane_segmentation",
153150
object_type="RoiResponseSeries",
154151
object_name="RoiResponseSeries",
155-
location="/processing/ophys/",
156152
)
157153

158154
def test_pass_check_roi_response_series_link_to_plane_segmentation(self):

0 commit comments

Comments
 (0)