99
1010import numpy as np
1111import pytest
12+ from packaging .version import Version
1213
1314import xarray as xr
1415from xarray import DataTree , load_datatree , open_datatree , open_groups
@@ -639,7 +640,15 @@ def test_inherited_coords(self, url=simplegroup_datatree_url) -> None:
639640 │ Temperature (time, Z, Y, X) float32 ...
640641 | Salinity (time, Z, Y, X) float32 ...
641642 """
642- tree = open_datatree (url , engine = self .engine )
643+ import pydap
644+ from requests_cache import CachedSession
645+
646+ _version_ = Version (pydap .__version__ )
647+
648+ session = CachedSession ()
649+ session .cache .clear ()
650+
651+ tree = open_datatree (url , engine = self .engine , session = session )
643652 assert set (tree .dims ) == {"time" , "Z" , "nv" }
644653 assert tree ["/SimpleGroup" ].coords ["time" ].dims == ("time" ,)
645654 assert tree ["/SimpleGroup" ].coords ["Z" ].dims == ("Z" ,)
@@ -650,6 +659,19 @@ def test_inherited_coords(self, url=simplegroup_datatree_url) -> None:
650659 list (expected .dims ) + ["Z" , "nv" ]
651660 )
652661
662+ # group (including root). So in this case 3. In the future there
663+ # should a only be 2 downloads (all dimensions should be downloaded)
664+ # within single
665+
666+ if _version_ > Version ("3.5.5" ):
667+ # Total downloads are: 1 dmr, + 1 dap url per Group | root.
668+ # since there is a group then 2 dap url. In the future there
669+ # should only be 1 dap url downloaded.
670+ assert len (session .cache .urls ()) == 3
671+ else :
672+ # 1 dmr + 1 dap url per dimension (total there are 4 dimension arrays)
673+ assert len (session .cache .urls ()) == 5
674+
653675 def test_open_groups_to_dict (self , url = all_aligned_child_nodes_url ) -> None :
654676 aligned_dict_of_datasets = open_groups (url , engine = self .engine )
655677 aligned_dt = DataTree .from_dict (aligned_dict_of_datasets )
0 commit comments