Skip to content

Commit ee03ed6

Browse files
committed
initial tests - quantify cached url
1 parent 7515616 commit ee03ed6

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

xarray/backends/pydap_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ def open(
161161
args = {"dataset": dataset}
162162
if group:
163163
args["group"] = group
164-
if url.startswith(("https", "dap2")):
164+
if url.startswith(("http", "dap2")):
165165
args["protocol"] = "dap2"
166-
else:
166+
elif url.startswith("dap4"):
167167
args["protocol"] = "dap4"
168168
if batch:
169169
if args["protocol"] == "dap2":

xarray/tests/test_backends.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5965,6 +5965,53 @@ def test_session(self) -> None:
59655965
)
59665966

59675967

5968+
@requires_pydap
5969+
@network
5970+
@pytest.mark.parametrize("protocol", ["dap2", "dap4"])
5971+
def test_batchdap4_downloads(protocol) -> None:
5972+
"""Test that in dap4, all dimensions are downloaded at once"""
5973+
import pydap
5974+
from requests_cache import CachedSession
5975+
5976+
_version_ = Version(pydap.__version__)
5977+
session = CachedSession()
5978+
session.cache.clear()
5979+
url = "https://test.opendap.org/opendap/hyrax/data/nc/coads_climatology.nc"
5980+
5981+
open_dataset(
5982+
url.replace("https", protocol),
5983+
engine="pydap",
5984+
session=session,
5985+
decode_times=False,
5986+
)
5987+
if protocol == "dap4":
5988+
if _version_ > Version("3.5.5"):
5989+
# should download 2 urls only (1 dmr and 1 dap)
5990+
assert len(session.cache.urls()) == 2
5991+
else:
5992+
assert len(session.cache.urls()) == 4
5993+
# das + dds + 3 dods urls
5994+
elif protocol == "dap2":
5995+
assert len(session.cache.urls()) == 5
5996+
5997+
5998+
@requires_pydap
5999+
@network
6000+
def test_batch_warnswithdap2() -> None:
6001+
from requests_cache import CachedSession
6002+
6003+
session = CachedSession()
6004+
session.cache.clear()
6005+
url = "dap2://test.opendap.org/opendap/hyrax/data/nc/coads_climatology.nc"
6006+
with pytest.warns(UserWarning):
6007+
open_dataset(
6008+
url, engine="pydap", session=session, batch=True, decode_times=False
6009+
)
6010+
6011+
# no batching is supported here
6012+
assert len(session.cache.urls()) == 5
6013+
6014+
59686015
class TestEncodingInvalid:
59696016
def test_extract_nc4_variable_encoding(self) -> None:
59706017
var = xr.Variable(("x",), [1, 2, 3], {}, {"foo": "bar"})

0 commit comments

Comments
 (0)