Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/test_remote_shallower.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ def test_absent_flag_is_a_noop():
client.shallow_results_on_slurm.assert_not_called()


@pytest.mark.parametrize("disabled_gate", [
"IMPORTER_ENABLED", "SHALLOW_ZARR_ENABLED",
"SHALLOW_ZARR_OPERATION_AVAILABLE", "IMPORTER_ORDER_API_AVAILABLE",
])
def test_disabled_shallow_path_does_not_read_canonical_or_contact_hpc(disabled_gate):
function = load()
snapshot = Mock(side_effect=AssertionError("canonical inputs accessed"))
function.__globals__.update({
disabled_gate: False, "load_canonical_input_snapshot": snapshot,
})
client = SimpleNamespace(remote_shallow_zarr=True, shallow_results_on_slurm=Mock())

function(client, "/data", "workflow")

snapshot.assert_not_called()
client.shallow_results_on_slurm.assert_not_called()


def test_shallower_receives_workflow_connection():
function = load()
if 'omero_conn' not in function.__code__.co_varnames and not os.environ.get('BIOMERO_TEST_REMOTE_SHALLOWER'):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_returned_zarr_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from types import SimpleNamespace
from uuid import UUID

import pytest


SOURCE_ROOT = Path(os.environ.get(
"BIOMERO_SCRIPTS_ROOT", Path(__file__).parents[1]
Expand Down Expand Up @@ -113,6 +115,27 @@ def test_missing_snapshot_preserves_legacy_import():
assert "no canonical" in logger.info_calls[-1][0][0]


@pytest.mark.parametrize("disabled_gate", [
"IMPORTER_ENABLED", "SHALLOW_ZARR_ENABLED",
"IMPORTER_ORDER_API_AVAILABLE", "SHALLOW_ZARR_OPERATION_AVAILABLE",
])
def test_disabled_shallow_path_does_not_request_importer_operation(disabled_gate):
namespace = {
"IMPORTER_ENABLED": True,
"SHALLOW_ZARR_ENABLED": True,
"IMPORTER_ORDER_API_AVAILABLE": True,
"SHALLOW_ZARR_OPERATION_AVAILABLE": True,
disabled_gate: False,
}
(build_options,) = _load_functions(
("build_shallow_import_options",), namespace
)

# No constructors or canonical-store access should be needed on this path.
manifest = SimpleNamespace(inputs=(object(),))
assert build_options(manifest) is None


def test_lifecycle_path_selection_prunes_nested_label_zarrs(tmp_path):
result = tmp_path / "result.ome.zarr"
label = result / "labels" / "nuclei.zarr"
Expand Down
60 changes: 60 additions & 0 deletions tests/test_slurm_image_initialization_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,66 @@ def test_initializer_adds_configured_remote_shallower_to_image_array():
assert "converter_specs.append(image_spec(slurmClient))" in source


@pytest.mark.skipif(
'os.getenv("BIOMERO_SHALLOW_ZARR", "false")' not in
INIT_SCRIPT.read_text(encoding="utf-8"),
reason="initializer feature gates are not present on this source revision",
)
@pytest.mark.parametrize(
"importer,shallow,remote,image,expected",
[
(None, None, True, "shallower.sif", False),
("false", "true", True, "shallower.sif", False),
("true", "false", True, "shallower.sif", False),
("true", "", True, "shallower.sif", False),
("true", "true", False, "shallower.sif", False),
("true", "true", True, None, False),
("true", "true", True, "shallower.sif", True),
("TRUE", "TRUE", True, "shallower.sif", True),
],
)
def test_initializer_only_acquires_enabled_remote_shallower(
monkeypatch, importer, shallow, remote, image, expected,
):
source = INIT_SCRIPT.read_text(encoding="utf-8")
tree = ast.parse(source)
# Exercise the actual image-acquisition branch without booting OMERO.
branch = next(
node for node in ast.walk(tree)
if isinstance(node, ast.If)
and any(
isinstance(statement, ast.ImportFrom)
and statement.module == "biomero.remote_shallower"
for statement in node.body
)
)
for name, value in (("IMPORTER_ENABLED", importer),
("BIOMERO_SHALLOW_ZARR", shallow)):
if value is None:
monkeypatch.delenv(name, raising=False)
else:
monkeypatch.setenv(name, value)
client = SimpleNamespace(
remote_shallow_zarr=remote, remote_shallower_image=image,
)
helper = ModuleType("biomero.remote_shallower")
spec = {"kind": "shallower", "destination": image}
helper.image_spec = Mock(return_value=spec)
converter_spec = {"kind": "converter", "destination": "converter.sif"}
specs = [converter_spec]
namespace = {"os": os, "slurmClient": client, "converter_specs": specs}

with patch.dict(sys.modules, {"biomero.remote_shallower": helper}):
exec(compile(ast.Module(body=[branch], type_ignores=[]),
str(INIT_SCRIPT), "exec"), namespace)

assert specs == [converter_spec] + ([spec] if expected else [])
if expected:
helper.image_spec.assert_called_once_with(client)
else:
helper.image_spec.assert_not_called()


def test_workflow_preflight_accepts_ready_remote_shallower():
validator = load_function(RUN_SCRIPT, "validate_remote_shallower_ready")
destination = "/images/shallower.sif"
Expand Down