|
13 | 13 | from zappend.api import FileObj |
14 | 14 | from zappend.api import SliceSource |
15 | 15 | from zappend.api import zappend |
| 16 | +from zappend.fsutil.transaction import Transaction |
16 | 17 | from .helpers import clear_memory_fs |
17 | 18 | from .helpers import make_test_dataset |
18 | 19 |
|
@@ -108,6 +109,39 @@ def test_some_slices_local_output_to_non_existing_dir(self): |
108 | 109 | for slice_dir in slices: |
109 | 110 | shutil.rmtree(slice_dir, ignore_errors=True) |
110 | 111 |
|
| 112 | + def test_some_slices_local_output_to_existing_dir_force_new(self): |
| 113 | + target_dir = "memory://target.zarr" |
| 114 | + slices = [ |
| 115 | + "memory://slice-0.zarr", |
| 116 | + "memory://slice-1.zarr", |
| 117 | + "memory://slice-2.zarr", |
| 118 | + "memory://slice-3.zarr", |
| 119 | + ] |
| 120 | + for uri in slices: |
| 121 | + make_test_dataset(uri=uri) |
| 122 | + |
| 123 | + # Expect nothing else to happen, even though force_new=True. |
| 124 | + zappend(slices[:1], target_dir=target_dir, force_new=True) |
| 125 | + target_ds = xr.open_zarr(target_dir) |
| 126 | + self.assertEqual({"time": 3, "y": 50, "x": 100}, target_ds.sizes) |
| 127 | + |
| 128 | + # Expect deletion of existing target_dir |
| 129 | + zappend(slices[1:], target_dir=target_dir, force_new=True) |
| 130 | + target_ds = xr.open_zarr(target_dir) |
| 131 | + self.assertEqual({"time": 9, "y": 50, "x": 100}, target_ds.sizes) |
| 132 | + |
| 133 | + # Expect no changes, even if force_new=True, because dry_run=True |
| 134 | + zappend(slices, target_dir=target_dir, force_new=True, dry_run=True) |
| 135 | + target_ds = xr.open_zarr(target_dir) |
| 136 | + self.assertEqual({"time": 9, "y": 50, "x": 100}, target_ds.sizes) |
| 137 | + |
| 138 | + # Expect the lock file to be deleted too |
| 139 | + lock_file = Transaction.get_lock_file(FileObj(target_dir)) |
| 140 | + lock_file.write("") |
| 141 | + self.assertEqual(True, lock_file.exists()) |
| 142 | + zappend(slices, target_dir=target_dir, force_new=True) |
| 143 | + self.assertEqual(False, lock_file.exists()) |
| 144 | + |
111 | 145 | def test_some_slices_with_class_slice_source(self): |
112 | 146 | target_dir = "memory://target.zarr" |
113 | 147 | slices = [make_test_dataset(index=3 * i) for i in range(3)] |
|
0 commit comments