Skip to content

Commit

Permalink
WIP tests for ImageMosaic
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Mar 6, 2024
1 parent f749742 commit 6712b3d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
7 changes: 3 additions & 4 deletions brainglobe_stitch/image_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ def load_mesospim_directory(self) -> None:
print("Resolution pyramid not found.")
# Close the file as it's open as read only
self.h5_file.close()
print("Creating resolution pyramid...")
print("Creating resolution pyramid.")

# Create resolution pyramid
with Progress() as progress:
task = progress.add_task(
"Creating resolution pyramid...", total=100
)
task = progress.add_task("Downsampling...", total=100)

for update in create_pyramid_bdv_h5(
self.h5_path,
Expand Down Expand Up @@ -214,6 +212,7 @@ def write_big_stitcher_tile_config(
The metadata for each tile in the image.
"""
# Remove .h5_meta.txt from the file name
print("Tile positions not found. Writing tile config file.")
output_file = str(meta_file_name)[:-12] + "_tile_config.txt"

tile_xy_locations = []
Expand Down
26 changes: 26 additions & 0 deletions tests/test_unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import shutil
from pathlib import Path

import pytest

TEMP_DIR = Path("./temp_directory")


@pytest.fixture(scope="class")
def naive_bdv_directory():
test_dir = Path("./test_directory")

shutil.copytree(
TEMP_DIR,
test_dir,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns("*data_bdv.h5"),
)
# Create UNIX style hidden files that should be ignored
(test_dir / ".test_data_original_bdv.h5").touch()
(test_dir / ".test_data_bdv.h5_meta.txt").touch()
(test_dir / ".test_data_bdv.h5_meta.txt").touch()

yield test_dir

shutil.rmtree(test_dir)
20 changes: 0 additions & 20 deletions tests/test_unit/test_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@
)


@pytest.fixture(scope="class")
def naive_bdv_directory():
test_dir = Path("./test_directory")

shutil.copytree(
TEMP_DIR,
test_dir,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns("*data_bdv.h5"),
)
# Create UNIX style hidden files that should be ignored
(test_dir / ".test_data_original_bdv.h5").touch()
(test_dir / ".test_data_bdv.h5_meta.txt").touch()
(test_dir / ".test_data_bdv.h5_meta.txt").touch()

yield test_dir

shutil.rmtree(test_dir)


@pytest.fixture
def bad_bdv_directory():
bad_dir = Path("./bad_directory")
Expand Down
26 changes: 26 additions & 0 deletions tests/test_unit/test_image_mosaic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

import pytest

from brainglobe_stitch.image_mosaic import ImageMosaic


@pytest.fixture(scope="class")
def image_mosaic(naive_bdv_directory):
os.remove(naive_bdv_directory / "test_data_bdv_tile_config.txt")
image_mosaic = ImageMosaic(naive_bdv_directory)

return image_mosaic


def test_image_mosaic_init(image_mosaic, naive_bdv_directory):
image_mosaic = image_mosaic
assert image_mosaic.xml_path == naive_bdv_directory / "test_data_bdv.xml"
assert (
image_mosaic.meta_path
== naive_bdv_directory / "test_data_bdv.h5_meta.txt"
)
assert (
image_mosaic.h5_path
== naive_bdv_directory / "test_data_original_bdv.h5"
)

0 comments on commit 6712b3d

Please sign in to comment.