From bcf15548bb2e83ed4b0697cf1900ee838a730b42 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Wed, 27 Sep 2023 16:02:05 +0200 Subject: [PATCH] add unit tests --- tests/unit_tests/test_ecephys.py | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/unit_tests/test_ecephys.py b/tests/unit_tests/test_ecephys.py index ccd3ab636..d8bb5cba5 100644 --- a/tests/unit_tests/test_ecephys.py +++ b/tests/unit_tests/test_ecephys.py @@ -15,6 +15,7 @@ check_electrical_series_dims, check_electrical_series_reference_electrodes_table, check_spike_times_not_in_unobserved_interval, + check_electrical_series_dtype, ) @@ -155,6 +156,76 @@ def test_trigger_check_electrical_series_reference_electrodes_table(self): == "electrodes does not reference an electrodes table." ) + def test_check_electrical_series_dtype_pass(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=float), + electrodes=electrodes, + rate=30.0, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) is None + + def test_check_electrical_series_dtype_fail(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=np.dtype("int16")), + electrodes=electrodes, + rate=30.0, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) == InspectorMessage( + message=( + "ElectricalSeries data type is integer and conversion factor and offset are both default, the value may not be in the correct unit" + ), + importance=Importance.CRITICAL, + check_function_name="check_electrical_series_dtype", + object_type="ElectricalSeries", + object_name="elec_series", + ) + + def test_check_electrical_series_dtype_non_default_conversion_skip(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=np.dtype("int16")), + electrodes=electrodes, + rate=30.0, + conversion=0.1, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) is None + + def test_check_electrical_series_dtype_non_default_offet_skip(self): + electrodes = self.nwbfile.create_electrode_table_region(region=[0, 1, 2, 3, 4], description="all") + + electrical_series = ElectricalSeries( + name="elec_series", + description="desc", + data=np.ones((100, 5), dtype=np.dtype("int16")), + electrodes=electrodes, + rate=30.0, + offset=0.1, + ) + + self.nwbfile.add_acquisition(electrical_series) + + assert check_electrical_series_dtype(electrical_series) is None + def test_check_spike_times_not_in_unobserved_interval_pass(): units_table = Units(name="TestUnits")