Skip to content

Commit

Permalink
Add test for writing unbacked data over existing files
Browse files Browse the repository at this point in the history
  • Loading branch information
aeisenbarth committed Aug 29, 2023
1 parent f58c4f4 commit 8a309ac
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/io/test_readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8a309ac

Please sign in to comment.