Source code for ewoksscxrd.tests.test_dataportal

import os
import pytest
import numpy as np
from PIL import Image

from ewoksscxrd.tasks.dataportal import DataPortal


[docs] def create_dummy_image(shape=(10, 10)) -> np.ndarray: """Helper: create a gradient float image array.""" return np.linspace(0, 255, num=shape[0] * shape[1], dtype=float).reshape(shape)
[docs] @pytest.fixture def simple_image() -> np.ndarray: """Fixture providing a basic gradient image.""" return create_dummy_image((10, 10))
[docs] @pytest.fixture def output_paths(tmp_path): """Fixture providing a base output path and expected gallery dir.""" base = tmp_path / "proc" / "sample" output_file = base / "image.tif" gallery_dir = base / "gallery" return {"output": str(output_file), "gallery_dir": str(gallery_dir)}
[docs] @pytest.fixture(autouse=True) def stub_store_to_icat(monkeypatch): """Prevent real ICAT calls""" monkeypatch.setattr(DataPortal, "store_to_icat", lambda self: None)
[docs] def test_save_no_overwrite(simple_image, output_paths): gallery_dir = output_paths["gallery_dir"] os.makedirs(gallery_dir, exist_ok=True) gallery_file = os.path.join(gallery_dir, "image_average.png") with Image.new("L", (10, 10)) as dummy: dummy.save(gallery_file) task = DataPortal( inputs={ "image": simple_image, "output": output_paths["output"], "gallery_output_binning": 1, "gallery_overwrite": False, } ) task.gallery_overwrite = False task.gallery_output_binning = 1 with pytest.raises(OSError): task.save_to_gallery(gallery_file, simple_image)