diff --git a/dkist/conftest.py b/dkist/conftest.py index b6a78ae64..8f4d71c86 100644 --- a/dkist/conftest.py +++ b/dkist/conftest.py @@ -24,8 +24,9 @@ @pytest.fixture def array(): - shape = np.random.randint(10, 100, size=2) - x = np.ones(shape) + 10 + shape = 2**np.random.randint(2, 7, size=2) + x = np.ones(np.prod(shape)) + 10 + x = x.reshape(shape) return da.from_array(x, tuple(shape)) diff --git a/dkist/io/asdf/tests/test_dataset.py b/dkist/io/asdf/tests/test_dataset.py index f321f03d0..43c6a7a10 100644 --- a/dkist/io/asdf/tests/test_dataset.py +++ b/dkist/io/asdf/tests/test_dataset.py @@ -1,5 +1,6 @@ import sys from pathlib import Path +from unittest.mock import call if sys.version_info < (3, 9): import importlib_resources @@ -140,3 +141,35 @@ def test_read_all_schema_versions(eit_dataset_asdf_path): assert isinstance(dataset.wcs, gwcs.WCS) assert dataset.wcs.world_n_dim == 3 assert dataset.wcs.pixel_n_dim == 3 + + +@pytest.fixture +def wrap_object(mocker): + + def wrap_object(target, attribute): + mock = mocker.MagicMock() + real_attribute = getattr(target, attribute) + + def mocked_attribute(self, *args, **kwargs): + mock.__call__(*args, **kwargs) + return real_attribute(self, *args, **kwargs) + + mocker.patch.object(target, attribute, mocked_attribute) + + return mock + + return wrap_object + + +def test_loader_getitem_with_chunksize(eit_dataset_asdf_path, wrap_object): + chunksize = (32, 16) + with asdf.open(eit_dataset_asdf_path) as tree: + dataset = tree["dataset"] + dataset.files.basepath = rootdir / "EIT" + dataset.files._striped_external_array.chunksize = chunksize + oo = wrap_object(dataset.files._striped_external_array._loader, "__getitem__") + dataset._data = dataset.files._generate_array() + dataset.data.compute() + + expected_call = call((slice(0, chunksize[0], None), slice(0, chunksize[1], None))) + assert expected_call in oo.mock_calls