Skip to content

Commit

Permalink
start adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Aug 27, 2024
1 parent 4c5fa1e commit 3d66f79
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 84 deletions.
4 changes: 4 additions & 0 deletions src/pynwb/ndx_microscopy/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
mock_MicroscopyLightSource,
mock_MicroscopyOpticalChannel,
mock_MicroscopyPlaneSegmentation,
mock_MicroscopyResponseSeries,
mock_MicroscopyResponseSeriesContainer,
mock_MicroscopySegmentations,
mock_MultiChannelMicroscopyVolume,
mock_PlanarImagingSpace,
Expand All @@ -25,5 +27,7 @@
"mock_VariableDepthMicroscopySeries",
"mock_VolumetricMicroscopySeries",
"mock_MultiChannelMicroscopyVolume",
"mock_MicroscopyResponseSeries",
"mock_MicroscopyResponseSeriesContainer",
"mock_VariableDepthMultiChannelMicroscopyVolume",
]
38 changes: 11 additions & 27 deletions src/pynwb/ndx_microscopy/testing/_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ def mock_MicroscopyResponseSeries(
) -> ndx_microscopy.MicroscopyResponseSeries:
series_name = name or name_generator("MicroscopyResponseSeries")

response_series = ndx_microscopy.MicroscopyResponseSeries(
number_of_frames = 100
number_of_rois = len(table_region.data)
series_data = data if data is not None else np.ones(shape=(number_of_frames, number_of_rois))

microscopy_response_series = ndx_microscopy.MicroscopyResponseSeries(
name=series_name,
description=description,
table_region=table_region,
Expand All @@ -391,38 +395,21 @@ def mock_MicroscopyResponseSeries(
timestamps=timestamps,
)

return response_series
return microscopy_response_series


def mock_MicroscopyResponseSeriesContainer(
*,
table_region: pynwb.core.DynamicTableRegion,
microscopy_response_series: List[microscopy_response_series],
name: Optional[str] = None,
description: str = "A mock instance of a MicroscopyResponseSeriesContainer type to be used for rapid testing.",
data: Optional[np.ndarray] = None,
unit: str = "a.u.",
conversion: float = 1.0,
offset: float = 0.0,
starting_time: Optional[float] = None,
rate: Optional[float] = None,
timestamps: Optional[np.ndarray] = None,
) -> ndx_microscopy.MicroscopyResponseSeriesContainer:
series_name = name or name_generator("MicroscopyResponseSeries")
container_name = name or name_generator("MicroscopyResponseSeriesContainer")

response_series = ndx_microscopy.MicroscopyResponseSeries(
name=series_name,
description=description,
table_region=table_region,
data=data,
unit=unit,
conversion=conversion,
offset=offset,
starting_time=starting_time,
rate=rate,
timestamps=timestamps,
microscopy_response_series_container = ndx_microscopy.MicroscopyResponseSeriesContainer(
name=container_name, microscopy_response_series=microscopy_response_series
)

return response_series
return microscopy_response_series_container


def mock_VariableDepthMultiChannelMicroscopyVolume(
Expand Down Expand Up @@ -464,6 +451,3 @@ def mock_VariableDepthMultiChannelMicroscopyVolume(
offset=offset,
)
return variable_depth_multi_channel_microscopy_volume


# TODO: add mock for MicroscopyResponseSeries
132 changes: 75 additions & 57 deletions src/pynwb/tests/test_constructors.py
Original file line number Diff line number Diff line change
@@ -1,112 +1,132 @@
"""Test in-memory Python API constructors for the ndx-microscopy extension."""

import pynwb.testing.mock.ophys
import pytest

import ndx_microscopy.testing
import pynwb
from ndx_microscopy.testing import (
mock_Microscope,
mock_MicroscopyLightSource,
mock_MicroscopyOpticalChannel,
mock_MicroscopyPlaneSegmentation,
mock_MicroscopySegmentations,
mock_MultiChannelMicroscopyVolume,
mock_PlanarImagingSpace,
mock_PlanarMicroscopySeries,
mock_VariableDepthMicroscopySeries,
mock_VariableDepthMultiChannelMicroscopyVolume,
mock_VolumetricImagingSpace,
mock_VolumetricMicroscopySeries,
)


def test_constructor_microscope():
mock_Microscope()
ndx_microscopy.testing.mock_Microscope()


def test_constructor_light_source():
mock_MicroscopyLightSource()
ndx_microscopy.testing.mock_MicroscopyLightSource()


def test_constructor_microscopy_optical_channel():
mock_MicroscopyOpticalChannel()
ndx_microscopy.testing.mock_MicroscopyOpticalChannel()


def test_constructor_planar_image_space():
microscope = mock_Microscope()
microscope = ndx_microscopy.testing.mock_Microscope()

mock_PlanarImagingSpace(microscope=microscope)
ndx_microscopy.testing.mock_PlanarImagingSpace(microscope=microscope)


def test_constructor_volumetric_image_space():
microscope = mock_Microscope()
microscope = ndx_microscopy.testing.mock_Microscope()

mock_VolumetricImagingSpace(microscope=microscope)
ndx_microscopy.testing.mock_VolumetricImagingSpace(microscope=microscope)


def test_constructor_microscopy_segmentations():
mock_MicroscopySegmentations()
ndx_microscopy.testing.mock_MicroscopySegmentations()


def test_constructor_microscopy_plane_segmentation():
microscope = mock_Microscope()
imaging_space = mock_PlanarImagingSpace(microscope=microscope)
microscope = ndx_microscopy.testing.mock_Microscope()
imaging_space = ndx_microscopy.testing.mock_PlanarImagingSpace(microscope=microscope)

mock_MicroscopyPlaneSegmentation(imaging_space=imaging_space)
ndx_microscopy.testing.mock_MicroscopyPlaneSegmentation(imaging_space=imaging_space)


def test_constructor_microscopy_image_segmentation_with_plane_segmentation():
microscope = mock_Microscope()
imaging_space = mock_PlanarImagingSpace(microscope=microscope)
microscope = ndx_microscopy.testing.mock_Microscope()
imaging_space = ndx_microscopy.testing.mock_PlanarImagingSpace(microscope=microscope)

plane_segmentation_1 = mock_MicroscopyPlaneSegmentation(
plane_segmentation_1 = ndx_microscopy.testing.mock_MicroscopyPlaneSegmentation(
imaging_space=imaging_space, name="MicroscopyPlaneSegmentation1"
)
plane_segmentation_2 = mock_MicroscopyPlaneSegmentation(
plane_segmentation_2 = ndx_microscopy.testing.mock_MicroscopyPlaneSegmentation(
imaging_space=imaging_space, name="MicroscopyPlaneSegmentation2"
)
microscopy_plane_segmentations = [plane_segmentation_1, plane_segmentation_2]

mock_MicroscopySegmentations(microscopy_plane_segmentations=microscopy_plane_segmentations)
ndx_microscopy.testing.mock_MicroscopySegmentations(microscopy_plane_segmentations=microscopy_plane_segmentations)


def test_constructor_planar_microscopy_series():
microscope = mock_Microscope()
light_source = mock_MicroscopyLightSource()
imaging_space = mock_PlanarImagingSpace(microscope=microscope)
optical_channel = mock_MicroscopyOpticalChannel()
microscope = ndx_microscopy.testing.mock_Microscope()
light_source = ndx_microscopy.testing.mock_MicroscopyLightSource()
imaging_space = ndx_microscopy.testing.mock_PlanarImagingSpace(microscope=microscope)
optical_channel = ndx_microscopy.testing.mock_MicroscopyOpticalChannel()

mock_PlanarMicroscopySeries(
ndx_microscopy.testing.mock_PlanarMicroscopySeries(
microscope=microscope, light_source=light_source, imaging_space=imaging_space, optical_channel=optical_channel
)


def test_constructor_variable_depth_microscopy_series():
microscope = mock_Microscope()
light_source = mock_MicroscopyLightSource()
imaging_space = mock_PlanarImagingSpace(microscope=microscope)
optical_channel = mock_MicroscopyOpticalChannel()
microscope = ndx_microscopy.testing.mock_Microscope()
light_source = ndx_microscopy.testing.mock_MicroscopyLightSource()
imaging_space = ndx_microscopy.testing.mock_PlanarImagingSpace(microscope=microscope)
optical_channel = ndx_microscopy.testing.mock_MicroscopyOpticalChannel()

mock_VariableDepthMicroscopySeries(
ndx_microscopy.testing.mock_VariableDepthMicroscopySeries(
microscope=microscope, light_source=light_source, imaging_space=imaging_space, optical_channel=optical_channel
)


def test_constructor_volumetric_microscopy_series():
microscope = mock_Microscope()
light_source = mock_MicroscopyLightSource()
imaging_space = mock_VolumetricImagingSpace(microscope=microscope)
optical_channel = mock_MicroscopyOpticalChannel()
microscope = ndx_microscopy.testing.mock_Microscope()
light_source = ndx_microscopy.testing.mock_MicroscopyLightSource()
imaging_space = ndx_microscopy.testing.mock_VolumetricImagingSpace(microscope=microscope)
optical_channel = ndx_microscopy.testing.mock_MicroscopyOpticalChannel()

mock_VolumetricMicroscopySeries(
ndx_microscopy.testing.mock_VolumetricMicroscopySeries(
microscope=microscope, light_source=light_source, imaging_space=imaging_space, optical_channel=optical_channel
)


def test_constructor_microscopy_response_series():
number_of_rois = 10

plane_segmentation = pynwb.testing.mock.ophys.mock_PlaneSegmentation()

table_region = pynwb.core.DynamicTableRegion(
name="table_region",
description="",
data=[x for x in range(number_of_rois)],
table=plane_segmentation,
)

ndx_microscopy.testing.mock_MicroscopyResponseSeries(table_region=table_region)


def test_constructor_microscopy_response_series_container():
number_of_rois = 10

plane_segmentation = pynwb.testing.mock.ophys.mock_PlaneSegmentation()

table_region = pynwb.core.DynamicTableRegion(
name="table_region",
description="",
data=[x for x in range(number_of_rois)],
table=plane_segmentation,
)

microscopy_response_series = [ndx_microscopy.testing.mock_MicroscopyResponseSeries(table_region=table_region)]

ndx_microscopy.testing.mock_MicroscopyResponseSeriesContainer(microscopy_response_series=microscopy_response_series)


def test_constructor_multi_channel_microscopy_volume():
microscope = mock_Microscope()
imaging_space = mock_VolumetricImagingSpace(microscope=microscope)
light_sources = [mock_MicroscopyLightSource()]
optical_channels = [mock_MicroscopyOpticalChannel()]
microscope = ndx_microscopy.testing.mock_Microscope()
imaging_space = ndx_microscopy.testing.mock_VolumetricImagingSpace(microscope=microscope)
light_sources = [ndx_microscopy.testing.mock_MicroscopyLightSource()]
optical_channels = [ndx_microscopy.testing.mock_MicroscopyOpticalChannel()]

light_sources_used_by_volume = pynwb.base.VectorData(
name="light_sources", description="Light sources used by this MultiChannelVolume.", data=light_sources
Expand All @@ -119,7 +139,7 @@ def test_constructor_multi_channel_microscopy_volume():
),
data=optical_channels,
)
mock_MultiChannelMicroscopyVolume(
ndx_microscopy.testing.mock_MultiChannelMicroscopyVolume(
microscope=microscope,
imaging_space=imaging_space,
light_sources=light_sources_used_by_volume,
Expand All @@ -128,10 +148,10 @@ def test_constructor_multi_channel_microscopy_volume():


def test_constructor_variable_depth_multi_channel_microscopy_volume():
microscope = mock_Microscope()
imaging_space = mock_VolumetricImagingSpace(microscope=microscope)
light_sources = [mock_MicroscopyLightSource()]
optical_channels = [mock_MicroscopyOpticalChannel()]
microscope = ndx_microscopy.testing.mock_Microscope()
imaging_space = ndx_microscopy.testing.mock_VolumetricImagingSpace(microscope=microscope)
light_sources = [ndx_microscopy.testing.mock_MicroscopyLightSource()]
optical_channels = [ndx_microscopy.testing.mock_MicroscopyOpticalChannel()]

light_sources_used_by_volume = pynwb.base.VectorData(
name="light_sources", description="Light sources used by this MultiChannelVolume.", data=light_sources
Expand All @@ -144,15 +164,13 @@ def test_constructor_variable_depth_multi_channel_microscopy_volume():
),
data=optical_channels,
)
mock_VariableDepthMultiChannelMicroscopyVolume(
ndx_microscopy.testing.mock_VariableDepthMultiChannelMicroscopyVolume(
microscope=microscope,
imaging_space=imaging_space,
light_sources=light_sources_used_by_volume,
optical_channels=optical_channels_used_by_volume,
)


# TODO: add constructor tests for MicroscopyResponseSeries

if __name__ == "__main__":
pytest.main() # Required since not a typical package structure

0 comments on commit 3d66f79

Please sign in to comment.