(
self,
cls_name: Literal["Variable", "DataArray", "Dataset"],
method: Literal["sel", "isel"],
indexer,
target_zarr_class,
)
| 4271 | ], |
| 4272 | ) |
| 4273 | async def test_indexing( |
| 4274 | self, |
| 4275 | cls_name: Literal["Variable", "DataArray", "Dataset"], |
| 4276 | method: Literal["sel", "isel"], |
| 4277 | indexer, |
| 4278 | target_zarr_class, |
| 4279 | ) -> None: |
| 4280 | if not has_zarr_v3_async_oindex and target_zarr_class in ( |
| 4281 | "zarr.core.indexing.AsyncOIndex", |
| 4282 | "zarr.core.indexing.AsyncVIndex", |
| 4283 | ): |
| 4284 | pytest.skip( |
| 4285 | "current version of zarr does not support orthogonal or vectorized async indexing" |
| 4286 | ) |
| 4287 | |
| 4288 | if cls_name == "Variable" and method == "sel": |
| 4289 | pytest.skip("Variable doesn't have a .sel method") |
| 4290 | |
| 4291 | # Each type of indexing ends up calling a different zarr indexing method |
| 4292 | # They all use a method named .getitem, but on a different internal zarr class |
| 4293 | def _resolve_class_from_string(class_path: str) -> type[Any]: |
| 4294 | """Resolve a string class path like 'zarr.AsyncArray' to the actual class.""" |
| 4295 | module_path, class_name = class_path.rsplit(".", 1) |
| 4296 | module = import_module(module_path) |
| 4297 | return getattr(module, class_name) |
| 4298 | |
| 4299 | target_class = _resolve_class_from_string(target_zarr_class) |
| 4300 | method_name = "getitem" |
| 4301 | original_method = getattr(target_class, method_name) |
| 4302 | |
| 4303 | original = create_test_data() |
| 4304 | with self.create_zarr_target() as store: |
| 4305 | original.to_zarr(store, consolidated=False, zarr_format=3) |
| 4306 | |
| 4307 | with patch.object( |
| 4308 | target_class, method_name, wraps=original_method, autospec=True |
| 4309 | ) as mocked_meth: |
| 4310 | xr_obj = get_xr_obj(store, cls_name) |
| 4311 | |
| 4312 | # TODO we're not actually testing that these indexing methods are not blocking... |
| 4313 | result = await getattr(xr_obj, method)(**indexer).load_async() |
| 4314 | |
| 4315 | mocked_meth.assert_called() |
| 4316 | mocked_meth.assert_awaited() |
| 4317 | assert mocked_meth.call_count > 0 |
| 4318 | |
| 4319 | expected = getattr(xr_obj, method)(**indexer).load() |
| 4320 | xrt.assert_identical(result, expected) |
| 4321 | |
| 4322 | @pytest.mark.asyncio |
| 4323 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected