Skip to content

Commit

Permalink
Fix tests for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Oct 11, 2024
1 parent 030f75a commit b40584e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
27 changes: 27 additions & 0 deletions tests/test_unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
import shutil
from pathlib import Path
from platform import system

import pooch
import pytest

from brainglobe_stitch.image_mosaic import ImageMosaic

TEMP_DIR = Path.home() / "temp_test_directory"
TEST_DATA_URL = "https://gin.g-node.org/IgorTatarnikov/brainglobe-stitch-test/raw/master/brainglobe-stitch/brainglobe-stitch-test-data.zip"

Expand Down Expand Up @@ -76,6 +79,30 @@ def naive_bdv_directory():
shutil.rmtree(test_dir)


@pytest.fixture(scope="module")
def image_mosaic(naive_bdv_directory):
"""
Fixture for creating an ImageMosaic object for testing. A clean directory
is created for this module using the naive_bdv_directory fixture. Tests
using this fixture will modify the directory.
The __del__ method is called at the end of the module to close any open h5
files.
Yields
------
ImageMosaic
An ImageMosaic object for testing.
"""
os.remove(naive_bdv_directory / "test_data_bdv_tile_config.txt")
image_mosaic = ImageMosaic(naive_bdv_directory)

yield image_mosaic

# Explicit call to close open h5 files
image_mosaic.__del__()


@pytest.fixture
def bdv_directory_function_level():
"""
Expand Down
25 changes: 0 additions & 25 deletions tests/test_unit/test_image_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@
import zarr

from brainglobe_stitch.file_utils import get_slice_attributes, safe_find
from brainglobe_stitch.image_mosaic import ImageMosaic


@pytest.fixture(scope="module")
def image_mosaic(naive_bdv_directory):
"""
Fixture for creating an ImageMosaic object for testing. A clean directory
is created for this module using the naive_bdv_directory fixture. Tests
using this fixture will modify the directory.
The __del__ method is called at the end of the module to close any open h5
files.
Yields
------
ImageMosaic
An ImageMosaic object for testing.
"""
os.remove(naive_bdv_directory / "test_data_bdv_tile_config.txt")
image_mosaic = ImageMosaic(naive_bdv_directory)

yield image_mosaic

# Explicit call to close open h5 files
image_mosaic.__del__()


@pytest.fixture(scope="module")
Expand Down
20 changes: 7 additions & 13 deletions tests/test_unit/test_stitching_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,13 @@ def test_update_tiles_from_mosaic(

@pytest.mark.parametrize("file_name", ["fused_image.h5", "fused_image.zarr"])
def test_on_fuse_button_clicked(
make_napari_viewer_proxy, naive_bdv_directory, mocker, file_name
stitching_widget_with_mosaic, mocker, file_name
):
mock_display_info = mocker.patch(
"brainglobe_stitch.stitching_widget.display_info",
autospec=True,
)
viewer = make_napari_viewer_proxy()
stitching_widget = StitchingWidget(viewer)

stitching_widget.image_mosaic = ImageMosaic(naive_bdv_directory)
stitching_widget = stitching_widget_with_mosaic

mock_fuse = mocker.patch(
"brainglobe_stitch.stitching_widget.ImageMosaic.fuse",
Expand All @@ -501,12 +498,11 @@ def test_on_fuse_button_clicked(


def test_on_fuse_button_clicked_no_file_name(
make_napari_viewer_proxy, naive_bdv_directory, mocker
stitching_widget_with_mosaic, image_mosaic, mocker
):
viewer = make_napari_viewer_proxy()
stitching_widget = StitchingWidget(viewer)
stitching_widget = stitching_widget_with_mosaic

stitching_widget.image_mosaic = ImageMosaic(naive_bdv_directory)
stitching_widget.image_mosaic = image_mosaic
error_message = "Output file name not specified"

mock_show_warning = mocker.patch(
Expand All @@ -527,12 +523,10 @@ def test_on_fuse_button_clicked_no_file_name(


def test_on_fuse_button_clicked_wrong_suffix(
make_napari_viewer_proxy, naive_bdv_directory, mocker
stitching_widget_with_mosaic, mocker
):
viewer = make_napari_viewer_proxy()
stitching_widget = StitchingWidget(viewer)
stitching_widget = stitching_widget_with_mosaic

stitching_widget.image_mosaic = ImageMosaic(naive_bdv_directory)
stitching_widget.output_file_name_field.setText("fused_image.tif")
error_message = "Output file name should end with .zarr, .h5"

Expand Down

0 comments on commit b40584e

Please sign in to comment.