Skip to content

Commit

Permalink
tests don't overwrite data
Browse files Browse the repository at this point in the history
  • Loading branch information
talonchandler committed Sep 18, 2024
1 parent 74bdb7b commit 6b857a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion iohub/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def set_scale(
"""
for input_position_dirpath in input_position_dirpaths:
with open_ome_zarr(
input_position_dirpath, layout="fov", mode="a"
input_position_dirpath, layout="fov", mode="r+"
) as dataset:
for name, value in zip(
["t", "z", "y", "x"], [t_scale, z_scale, y_scale, x_scale]
Expand Down
62 changes: 35 additions & 27 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import re
from pathlib import Path
from unittest.mock import patch

import pytest
Expand All @@ -15,6 +16,8 @@
ndtiff_v3_labeled_positions,
)

from ..ngff.test_ngff import _temp_copy


def pytest_generate_tests(metafunc):
if "mm2gamma_ome_tiff" in metafunc.fixturenames:
Expand Down Expand Up @@ -107,31 +110,36 @@ def test_cli_convert_ome_tiff(grid_layout, tmpdir):
assert "Converting" in result.output


def test_cli_update_scale_metadata():
position_path = hcs_ref / "B" / "03" / "0"
with open_ome_zarr(position_path, layout="fov", mode="a") as input_dataset:
old_scale = input_dataset.scale

random_z = random.uniform(0, 1)
def test_cli_set_scale():
with _temp_copy(hcs_ref) as store_path:
store_path = Path(store_path)
position_path = Path(store_path) / "B" / "03" / "0"

with open_ome_zarr(
position_path, layout="fov", mode="r+"
) as input_dataset:
old_scale = input_dataset.scale

random_z = random.uniform(0, 1)

runner = CliRunner()
result_pos = runner.invoke(
cli,
[
"set-scale",
"-i",
position_path,
"-z",
random_z,
"-y",
0.5,
"-x",
0.5,
],
)
assert result_pos.exit_code == 0
assert "Updating" in result_pos.output

runner = CliRunner()
result_pos = runner.invoke(
cli,
[
"update-scale-metadata",
"-i",
str(position_path),
"-z",
random_z,
"-y",
0.5,
"-x",
0.5,
],
)
assert result_pos.exit_code == 0
assert "Updating" in result_pos.output

with open_ome_zarr(position_path, layout="fov") as output_dataset:
assert tuple(output_dataset.scale[-3:]) == (random_z, 0.5, 0.5)
assert output_dataset.scale != old_scale
with open_ome_zarr(position_path, layout="fov") as output_dataset:
assert tuple(output_dataset.scale[-3:]) == (random_z, 0.5, 0.5)
assert output_dataset.scale != old_scale

0 comments on commit 6b857a9

Please sign in to comment.