|
5 | 5 | import shutil |
6 | 6 | import unittest |
7 | 7 |
|
| 8 | +import numpy as np |
8 | 9 | import xarray as xr |
9 | 10 |
|
10 | 11 | from zappend.api import FileObj |
|
14 | 15 | from .helpers import make_test_dataset |
15 | 16 |
|
16 | 17 |
|
| 18 | +# noinspection PyMethodMayBeStatic |
17 | 19 | class ApiTest(unittest.TestCase): |
18 | 20 | def setUp(self): |
19 | 21 | clear_memory_fs() |
@@ -73,6 +75,79 @@ def process_slice(ctx, slice_ds: xr.Dataset) -> SliceSource: |
73 | 75 | self.assertEqual({"chl"}, set(ds.data_vars)) |
74 | 76 | self.assertEqual({"time", "y", "x"}, set(ds.coords)) |
75 | 77 |
|
| 78 | + def test_some_slices_with_inc_append_step(self): |
| 79 | + target_dir = "memory://target.zarr" |
| 80 | + slices = [ |
| 81 | + make_test_dataset(index=0, shape=(1, 50, 100)), |
| 82 | + make_test_dataset(index=1, shape=(1, 50, 100)), |
| 83 | + make_test_dataset(index=2, shape=(1, 50, 100)), |
| 84 | + ] |
| 85 | + zappend(slices, target_dir=target_dir, append_step="1d") |
| 86 | + ds = xr.open_zarr(target_dir) |
| 87 | + np.testing.assert_array_equal( |
| 88 | + ds.time.values, |
| 89 | + np.array(["2024-01-01", "2024-01-02", "2024-01-03"], dtype=np.datetime64), |
| 90 | + ) |
| 91 | + |
| 92 | + def test_some_slices_with_dec_append_step(self): |
| 93 | + target_dir = "memory://target.zarr" |
| 94 | + slices = [ |
| 95 | + make_test_dataset(index=2, shape=(1, 50, 100)), |
| 96 | + make_test_dataset(index=1, shape=(1, 50, 100)), |
| 97 | + make_test_dataset(index=0, shape=(1, 50, 100)), |
| 98 | + ] |
| 99 | + zappend(slices, target_dir=target_dir, append_step="-1d") |
| 100 | + ds = xr.open_zarr(target_dir) |
| 101 | + np.testing.assert_array_equal( |
| 102 | + ds.time.values, |
| 103 | + np.array(["2024-01-03", "2024-01-02", "2024-01-01"], dtype=np.datetime64), |
| 104 | + ) |
| 105 | + |
| 106 | + def test_some_slices_with_one_missing_append_step(self): |
| 107 | + target_dir = "memory://target.zarr" |
| 108 | + slices = [ |
| 109 | + make_test_dataset(index=0, shape=(1, 50, 100)), |
| 110 | + make_test_dataset(index=2, shape=(1, 50, 100)), |
| 111 | + ] |
| 112 | + zappend(slices, target_dir=target_dir, append_step="1d") |
| 113 | + ds = xr.open_zarr(target_dir) |
| 114 | + np.testing.assert_array_equal( |
| 115 | + ds.time.values, |
| 116 | + np.array(["2024-01-01", "2024-01-02", "2024-01-03"], dtype=np.datetime64), |
| 117 | + ) |
| 118 | + |
| 119 | + def test_some_slices_with_three_missing_append_steps(self): |
| 120 | + target_dir = "memory://target.zarr" |
| 121 | + slices = [ |
| 122 | + make_test_dataset(index=0, shape=(1, 50, 100)), |
| 123 | + make_test_dataset(index=4, shape=(1, 50, 100)), |
| 124 | + ] |
| 125 | + zappend(slices, target_dir=target_dir, append_step="1d") |
| 126 | + ds = xr.open_zarr(target_dir) |
| 127 | + np.testing.assert_array_equal( |
| 128 | + ds.time.values, |
| 129 | + np.array( |
| 130 | + ["2024-01-01", "2024-01-02", "2024-01-03", "2024-01-04", "2024-01-05"], |
| 131 | + dtype=np.datetime64, |
| 132 | + ), |
| 133 | + ) |
| 134 | + |
| 135 | + def test_it_raises_for_wrong_append_step(self): |
| 136 | + # TODO: implement me |
| 137 | + pass |
| 138 | + |
| 139 | + def test_some_slices_with_inc_append_labels(self): |
| 140 | + # TODO: implement me |
| 141 | + pass |
| 142 | + |
| 143 | + def test_some_slices_with_dec_append_labels(self): |
| 144 | + # TODO: implement me |
| 145 | + pass |
| 146 | + |
| 147 | + def test_it_raises_for_none_inc_append_labels(self): |
| 148 | + # TODO: implement me |
| 149 | + pass |
| 150 | + |
76 | 151 | def test_some_slices_with_profiling(self): |
77 | 152 | target_dir = "memory://target.zarr" |
78 | 153 | slices = [ |
|
0 commit comments