From 92f10d52dcdc9899391e4adce010a77c564cac06 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Mon, 27 May 2024 15:19:46 +0200 Subject: [PATCH] write mock fun for Microscopy and MicroscopyTable --- src/pynwb/ndx_microscopy/testing/__init__.py | 8 ++-- src/pynwb/ndx_microscopy/testing/_mock.py | 35 +++++++++++++++ src/pynwb/tests/test_constructors.py | 10 ----- src/pynwb/tests/test_ndx_microscopy.py | 46 +++++++------------- 4 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/pynwb/ndx_microscopy/testing/__init__.py b/src/pynwb/ndx_microscopy/testing/__init__.py index 11cedf0..48c2353 100644 --- a/src/pynwb/ndx_microscopy/testing/__init__.py +++ b/src/pynwb/ndx_microscopy/testing/__init__.py @@ -1,6 +1,6 @@ from ._mock import ( - mock_ExcitationSource, - mock_Microscope, + mock_MicroscopyTable, + mock_Microscopy, mock_PlanarImagingSpace, mock_PlanarMicroscopySeries, mock_VariableDepthMicroscopySeries, @@ -9,8 +9,8 @@ ) __all__ = [ - "mock_Microscope", - "mock_ExcitationSource", + "mock_MicroscopyTable", + "mock_Microscopy", "mock_PlanarImagingSpace", "mock_VolumetricImagingSpace", "mock_PlanarMicroscopySeries", diff --git a/src/pynwb/ndx_microscopy/testing/_mock.py b/src/pynwb/ndx_microscopy/testing/_mock.py index 84848cd..0270f4d 100644 --- a/src/pynwb/ndx_microscopy/testing/_mock.py +++ b/src/pynwb/ndx_microscopy/testing/_mock.py @@ -5,16 +5,28 @@ from pynwb.testing.mock.utils import name_generator import ndx_microscopy +from ndx_ophys_devices.testing import ( + mock_Indicator, + mock_ExcitationSource, + mock_Photodetector, + mock_DichroicMirror, + mock_BandOpticalFilter, + mock_EdgeOpticalFilter, + mock_Microscope, + mock_ObjectiveLens, +) def mock_Microscopy( *, + microscopy_table: ndx_microscopy.MicroscopyTable, name: Optional[str] = None, description: str = "This is a mock instance of a Microscopy type to be used for rapid testing.", ) -> ndx_microscopy.Microscopy: microscopy = ndx_microscopy.Microscopy( name=name or name_generator("Microscopy"), description=description, + microscopy_table=microscopy_table, ) return microscopy @@ -23,11 +35,25 @@ def mock_MicroscopyTable( *, name: Optional[str] = None, description: str = "This is a mock instance of a Microscopy Table type to be used for rapid testing.", + number_of_rows: int = 2, ) -> ndx_microscopy.MicroscopyTable: microscopy_table = ndx_microscopy.MicroscopyTable( name=name or name_generator("MicroscopyTable"), description=description, ) + for row in range(number_of_rows): + microscopy_table.add_row( + location=f"The location targeted of row number {row}", + notes=f"The notes for row number {row}", + indicator=mock_Indicator(name=f"indicator_{row}"), + excitation_source=mock_ExcitationSource(name=f"excitation_source_{row}"), + photodetector=mock_Photodetector(name=f"photodetector_{row}"), + dichroic_mirror=mock_DichroicMirror(name=f"dichroic_mirror_{row}"), + emission_filter=mock_BandOpticalFilter(name=f"emission_filter_{row}"), + excitation_filter=mock_EdgeOpticalFilter(name=f"excitation_filter_{row}"), + objective_lens=mock_ObjectiveLens(name=f"objective_lens_{row}"), + microscope=mock_Microscope(name=f"microscope_{row}"), + ) return microscopy_table @@ -104,6 +130,9 @@ def mock_PlanarMicroscopySeries( series_rate = None series_timestamps = timestamps + microscopy_table = mock_MicroscopyTable() + microscopy_table_region = microscopy_table.create_microscopy_table_region(region=microscopy_table_region) + planar_microscopy_series = ndx_microscopy.PlanarMicroscopySeries( name=series_name, description=description, @@ -160,6 +189,9 @@ def mock_VariableDepthMicroscopySeries( series_rate = None series_timestamps = timestamps + microscopy_table = mock_MicroscopyTable() + microscopy_table_region = microscopy_table.create_microscopy_table_region(region=microscopy_table_region) + variable_depth_microscopy_series = ndx_microscopy.VariableDepthMicroscopySeries( name=series_name, description=description, @@ -210,6 +242,9 @@ def mock_VolumetricMicroscopySeries( series_rate = None series_timestamps = timestamps + microscopy_table = mock_MicroscopyTable() + microscopy_table_region = microscopy_table.create_microscopy_table_region(region=microscopy_table_region) + volumetric_microscopy_series = ndx_microscopy.VolumetricMicroscopySeries( name=series_name, description=description, diff --git a/src/pynwb/tests/test_constructors.py b/src/pynwb/tests/test_constructors.py index 9d78539..2e97866 100644 --- a/src/pynwb/tests/test_constructors.py +++ b/src/pynwb/tests/test_constructors.py @@ -1,16 +1,6 @@ """Test in-memory Python API constructors for ndx-microscopy extension.""" import pytest -from ndx_ophys_devices.testing import ( - mock_BandOpticalFilter, - mock_DichroicMirror, - mock_EdgeOpticalFilter, - mock_ExcitationSource, - mock_Indicator, - mock_Microscope, - mock_ObjectiveLens, - mock_Photodetector, -) from ndx_microscopy.testing import ( mock_Microscopy, diff --git a/src/pynwb/tests/test_ndx_microscopy.py b/src/pynwb/tests/test_ndx_microscopy.py index c056f09..d2c89b4 100644 --- a/src/pynwb/tests/test_ndx_microscopy.py +++ b/src/pynwb/tests/test_ndx_microscopy.py @@ -8,8 +8,8 @@ import pynwb from ndx_microscopy.testing import ( - mock_ExcitationSource, - mock_Microscope, + mock_Microscopy, + mock_MicroscopyTable, mock_PlanarImagingSpace, mock_PlanarMicroscopySeries, mock_VariableDepthMicroscopySeries, @@ -19,59 +19,45 @@ from pynwb import NWBHDF5IO, NWBFile -def test_constructor_microscope(): - mock_Microscope() +def test_constructor_microscopy(): + mock_Microscopy() -def test_constructor_light_source(): - mock_ExcitationSource() +def test_constructor_microscopy_table(): + mock_MicroscopyTable() def test_constructor_planar_image_space(): - microscope = mock_Microscope() - - mock_PlanarImagingSpace(microscope=microscope) + mock_PlanarImagingSpace() def test_constructor_volumetric_image_space(): - microscope = mock_Microscope() - - mock_VolumetricImagingSpace(microscope=microscope) + mock_VolumetricImagingSpace() def test_constructor_planar_microscopy_series(): - microscope = mock_Microscope() - light_source = mock_ExcitationSource() - imaging_space = mock_PlanarImagingSpace(microscope=microscope) - - mock_PlanarMicroscopySeries(microscope=microscope, light_source=light_source, imaging_space=imaging_space) + imaging_space = mock_PlanarImagingSpace() + mock_PlanarMicroscopySeries(imaging_space=imaging_space) def test_constructor_variable_depth_microscopy_series(): - microscope = mock_Microscope() - light_source = mock_ExcitationSource() - imaging_space = mock_PlanarImagingSpace(microscope=microscope) + imaging_space = mock_PlanarImagingSpace() - mock_VariableDepthMicroscopySeries(microscope=microscope, light_source=light_source, imaging_space=imaging_space) + mock_VariableDepthMicroscopySeries(imaging_space=imaging_space) def test_constructor_volumetric_microscopy_series(): - microscope = mock_Microscope() - light_source = mock_ExcitationSource() - imaging_space = mock_PlanarImagingSpace(microscope=microscope) + imaging_space = mock_VolumetricImagingSpace() - mock_VolumetricMicroscopySeries(microscope=microscope, light_source=light_source, imaging_space=imaging_space) + mock_VolumetricMicroscopySeries(imaging_space=imaging_space) @pytest.fixture(scope="module") def nwbfile_with_microscopy(): nwbfile = pynwb.testing.mock.mock_NWBFile() - microscope = mock_Microscope() - light_source = mock_ExcitationSource() - imaging_space = mock_PlanarImagingSpace(microscope=microscope) - - mock_PlanarMicroscopySeries(microscope=microscope, light_source=light_source, imaging_space=imaging_space) + imaging_space = mock_PlanarImagingSpace() + mock_PlanarMicroscopySeries(imaging_space=imaging_space) return nwbfile