Skip to content

Commit

Permalink
test that chunksize influences how dask calls getitem
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Mar 28, 2023
1 parent 89889a9 commit b879eab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dkist/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
33 changes: 33 additions & 0 deletions dkist/io/asdf/tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from pathlib import Path
from unittest.mock import call

if sys.version_info < (3, 9):
import importlib_resources
Expand Down Expand Up @@ -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

0 comments on commit b879eab

Please sign in to comment.