Skip to content

Commit

Permalink
try pytestmark
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored May 1, 2024
1 parent 4f44179 commit c95957d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/test_scanimagetiffimagingextractor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys
import platform

import pytest
from numpy.testing import assert_array_equal
import platform

if (
platform.processor() != "arm"
): # Remove this check once scanimage tiff reader is available on ARM -- see https://gitlab.com/vidriotech/scanimagetiffreader-python/-/issues/31
from ScanImageTiffReader import ScanImageTiffReader
from roiextractors import (
ScanImageTiffSinglePlaneImagingExtractor,
ScanImageTiffMultiPlaneImagingExtractor,
Expand All @@ -16,6 +14,8 @@

from .setup_paths import OPHYS_DATA_PATH

IS_ARM64_MAC = sys.platform == "darwin" and platform.processor() == "arm"
pytestmark = pytest.mark.skipif(IS_ARM64_MAC)

@pytest.fixture(scope="module")
def file_path():
Expand Down Expand Up @@ -49,13 +49,11 @@ def expected_properties():
def scan_image_tiff_single_plane_imaging_extractor(request, file_path):
return ScanImageTiffSinglePlaneImagingExtractor(file_path=file_path, **request.param)


@pytest.mark.parametrize("channel_name, plane_name", [("Invalid Channel", "0"), ("Channel 1", "Invalid Plane")])
def test_ScanImageTiffSinglePlaneImagingExtractor__init__invalid(file_path, channel_name, plane_name):
with pytest.raises(ValueError):
ScanImageTiffSinglePlaneImagingExtractor(file_path=file_path, channel_name=channel_name, plane_name=plane_name)


def test_ScanImageTiffSinglePlaneImagingExtractor__init__metadata_provided(file_path):
metadata = extract_extra_metadata(file_path)
parsed_metadata = parse_metadata(metadata)
Expand All @@ -69,7 +67,6 @@ def test_ScanImageTiffSinglePlaneImagingExtractor__init__metadata_provided(file_
assert extractor.metadata == metadata
assert extractor.parsed_metadata == parsed_metadata


def test_ScanImageTiffSinglePlaneImagingExtractor__init__invalid_metadata_provided(file_path):
metadata = {"invalid_key": "invalid_value"}
parsed_metadata = {"invalid_key": "invalid_value"}
Expand All @@ -82,7 +79,6 @@ def test_ScanImageTiffSinglePlaneImagingExtractor__init__invalid_metadata_provid
parsed_metadata=parsed_metadata,
)


def test_ScanImageTiffSinglePlaneImagingExtractor__init__parsed_metadata_not_provided(file_path):
metadata = extract_extra_metadata(file_path)
with pytest.raises(AssertionError):
Expand All @@ -93,9 +89,10 @@ def test_ScanImageTiffSinglePlaneImagingExtractor__init__parsed_metadata_not_pro
metadata=metadata,
)


@pytest.mark.parametrize("frame_idxs", (0, [0, 1, 2], [0, 2, 5]))
def test_get_frames(scan_image_tiff_single_plane_imaging_extractor, frame_idxs, expected_properties):
from ScanImageTiffReader import ScanImageTiffReader

frames = scan_image_tiff_single_plane_imaging_extractor.get_frames(frame_idxs=frame_idxs)
file_path = str(scan_image_tiff_single_plane_imaging_extractor.file_path)
plane = scan_image_tiff_single_plane_imaging_extractor.plane
Expand All @@ -105,6 +102,7 @@ def test_get_frames(scan_image_tiff_single_plane_imaging_extractor, frame_idxs,
frames_per_slice = expected_properties["frames_per_slice"]
if isinstance(frame_idxs, int):
frame_idxs = [frame_idxs]

raw_idxs = []
for idx in frame_idxs:
cycle = idx // frames_per_slice
Expand All @@ -116,18 +114,19 @@ def test_get_frames(scan_image_tiff_single_plane_imaging_extractor, frame_idxs,
+ channel
)
raw_idxs.append(raw_idx)

with ScanImageTiffReader(file_path) as io:
assert_array_equal(frames, io.data()[raw_idxs])


@pytest.mark.parametrize("frame_idxs", ([-1], [50]))
def test_get_frames_invalid(scan_image_tiff_single_plane_imaging_extractor, frame_idxs):
with pytest.raises(ValueError):
scan_image_tiff_single_plane_imaging_extractor.get_frames(frame_idxs=frame_idxs)


@pytest.mark.parametrize("frame_idx", (1, 3, 5))
def test_get_single_frame(scan_image_tiff_single_plane_imaging_extractor, expected_properties, frame_idx):
from ScanImageTiffReader import ScanImageTiffReader

frame = scan_image_tiff_single_plane_imaging_extractor._get_single_frame(frame=frame_idx)
file_path = str(scan_image_tiff_single_plane_imaging_extractor.file_path)
plane = scan_image_tiff_single_plane_imaging_extractor.plane
Expand Down Expand Up @@ -160,6 +159,8 @@ def test_get_video(
start_frame,
end_frame,
):
from ScanImageTiffReader import ScanImageTiffReader

video = scan_image_tiff_single_plane_imaging_extractor.get_video(start_frame=start_frame, end_frame=end_frame)
if start_frame is None:
start_frame = 0
Expand All @@ -171,6 +172,7 @@ def test_get_video(
num_planes = expected_properties["num_planes"]
num_channels = expected_properties["num_channels"]
frames_per_slice = expected_properties["frames_per_slice"]

raw_idxs = []
for idx in range(start_frame, end_frame):
cycle = idx // frames_per_slice
Expand All @@ -182,6 +184,7 @@ def test_get_video(
+ channel
)
raw_idxs.append(raw_idx)

with ScanImageTiffReader(file_path) as io:
assert_array_equal(video, io.data()[raw_idxs])

Expand Down

0 comments on commit c95957d

Please sign in to comment.