diff --git a/tests/io/test_readwrite.py b/tests/io/test_readwrite.py index 046baf3b..d3b350aa 100644 --- a/tests/io/test_readwrite.py +++ b/tests/io/test_readwrite.py @@ -12,6 +12,7 @@ from numpy.random import default_rng from shapely.geometry import Point from spatial_image import SpatialImage + from spatialdata import SpatialData from spatialdata._io._utils import _are_directories_identical from spatialdata.models import TableModel @@ -20,7 +21,6 @@ set_transformation, ) from spatialdata.transformations.transformations import Identity, Scale - from tests.conftest import _get_images, _get_labels, _get_points, _get_shapes RNG = default_rng() @@ -238,6 +238,18 @@ def test_replace_transformation_on_disk_non_raster(self, shapes, points): t1 = get_transformation(SpatialData.read(f).__getattribute__(k)[elem_name]) assert type(t1) == Scale + def test_overwrite_files_without_backed_data(self, full_sdata): + with tempfile.TemporaryDirectory() as tmpdir: + f = os.path.join(tmpdir, "data.zarr") + old_data = SpatialData() + old_data.write(f) + # Since not backed, no risk of overwriting backing data. Should not raise. + try: + full_sdata.write(f, overwrite=True) + except Exception as e: + assert "The file path specified is the same as the one used for backing" not in str(e) + raise # Let other unexpected exceptions bubble up + def test_overwrite_files_with_backed_data(self, full_sdata): # addressing https://github.com/scverse/spatialdata/issues/137 with tempfile.TemporaryDirectory() as tmpdir: