From 8a309ac3026f0250fe768838425152e80a0c9fa0 Mon Sep 17 00:00:00 2001 From: Andreas Eisenbarth Date: Tue, 29 Aug 2023 15:14:22 +0200 Subject: [PATCH] Add test for writing unbacked data over existing files --- tests/io/test_readwrite.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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: