Skip to content

Commit 6efae9d

Browse files
committed
adds tests to datatree backend to assert multiple dimensions downloaded at once (per group)
1 parent 1ffbce8 commit 6efae9d

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

xarray/tests/test_backends_datatree.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import numpy as np
1111
import pytest
12+
from packaging.version import Version
1213

1314
import xarray as xr
1415
from xarray import DataTree, load_datatree, open_datatree, open_groups
@@ -633,7 +634,15 @@ def test_inherited_coords(self, url=simplegroup_datatree_url) -> None:
633634
│ Temperature (time, Z, Y, X) float32 ...
634635
| Salinity (time, Z, Y, X) float32 ...
635636
"""
636-
tree = open_datatree(url, engine=self.engine)
637+
import pydap
638+
from requests_cache import CachedSession
639+
640+
_version_ = Version(pydap.__version__)
641+
642+
session = CachedSession()
643+
session.cache.clear()
644+
645+
tree = open_datatree(url, engine=self.engine, session=session)
637646
assert set(tree.dims) == {"time", "Z", "nv"}
638647
assert tree["/SimpleGroup"].coords["time"].dims == ("time",)
639648
assert tree["/SimpleGroup"].coords["Z"].dims == ("Z",)
@@ -644,6 +653,19 @@ def test_inherited_coords(self, url=simplegroup_datatree_url) -> None:
644653
list(expected.dims) + ["Z", "nv"]
645654
)
646655

656+
# group (including root). So in this case 3. In the future there
657+
# should a only be 2 downloads (all dimensions should be downloaded)
658+
# within single
659+
660+
if _version_ > Version("3.5.5"):
661+
# Total downloads are: 1 dmr, + 1 dap url per Group | root.
662+
# since there is a group then 2 dap url. In the future there
663+
# should only be 1 dap url downloaded.
664+
assert len(session.cache.urls()) == 3
665+
else:
666+
# 1 dmr + 1 dap url per dimension (total there are 4 dimension arrays)
667+
assert len(session.cache.urls()) == 5
668+
647669
def test_open_groups_to_dict(self, url=all_aligned_child_nodes_url) -> None:
648670
aligned_dict_of_datasets = open_groups(url, engine=self.engine)
649671
aligned_dt = DataTree.from_dict(aligned_dict_of_datasets)

0 commit comments

Comments
 (0)