Skip to content

Commit

Permalink
write mock fun for Microscopy and MicroscopyTable
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandratrapani committed May 27, 2024
1 parent 8d945f7 commit 92f10d5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/pynwb/ndx_microscopy/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ._mock import (
mock_ExcitationSource,
mock_Microscope,
mock_MicroscopyTable,
mock_Microscopy,
mock_PlanarImagingSpace,
mock_PlanarMicroscopySeries,
mock_VariableDepthMicroscopySeries,
Expand All @@ -9,8 +9,8 @@
)

__all__ = [
"mock_Microscope",
"mock_ExcitationSource",
"mock_MicroscopyTable",
"mock_Microscopy",
"mock_PlanarImagingSpace",
"mock_VolumetricImagingSpace",
"mock_PlanarMicroscopySeries",
Expand Down
35 changes: 35 additions & 0 deletions src/pynwb/ndx_microscopy/testing/_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions src/pynwb/tests/test_constructors.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
46 changes: 16 additions & 30 deletions src/pynwb/tests/test_ndx_microscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down

0 comments on commit 92f10d5

Please sign in to comment.