Skip to content

Commit 1ffbce8

Browse files
committed
initial tests - quantify cached url
1 parent 4fb2182 commit 1ffbce8

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
@@ -6449,6 +6449,53 @@ def test_session(self) -> None:
64496449
)
64506450

64516451

6452+
@requires_pydap
6453+
@network
6454+
@pytest.mark.parametrize("protocol", ["dap2", "dap4"])
6455+
def test_batchdap4_downloads(protocol) -> None:
6456+
"""Test that in dap4, all dimensions are downloaded at once"""
6457+
import pydap
6458+
from requests_cache import CachedSession
6459+
6460+
_version_ = Version(pydap.__version__)
6461+
session = CachedSession()
6462+
session.cache.clear()
6463+
url = "https://test.opendap.org/opendap/hyrax/data/nc/coads_climatology.nc"
6464+
6465+
open_dataset(
6466+
url.replace("https", protocol),
6467+
engine="pydap",
6468+
session=session,
6469+
decode_times=False,
6470+
)
6471+
if protocol == "dap4":
6472+
if _version_ > Version("3.5.5"):
6473+
# should download 2 urls only (1 dmr and 1 dap)
6474+
assert len(session.cache.urls()) == 2
6475+
else:
6476+
assert len(session.cache.urls()) == 4
6477+
# das + dds + 3 dods urls
6478+
elif protocol == "dap2":
6479+
assert len(session.cache.urls()) == 5
6480+
6481+
6482+
@requires_pydap
6483+
@network
6484+
def test_batch_warnswithdap2() -> None:
6485+
from requests_cache import CachedSession
6486+
6487+
session = CachedSession()
6488+
session.cache.clear()
6489+
url = "dap2://test.opendap.org/opendap/hyrax/data/nc/coads_climatology.nc"
6490+
with pytest.warns(UserWarning):
6491+
open_dataset(
6492+
url, engine="pydap", session=session, batch=True, decode_times=False
6493+
)
6494+
6495+
# no batching is supported here
6496+
assert len(session.cache.urls()) == 5
6497+
6498+
64526499
class TestEncodingInvalid:
64536500
def test_extract_nc4_variable_encoding(self) -> None:
64546501
var = xr.Variable(("x",), [1, 2, 3], {}, {"foo": "bar"})

0 commit comments

Comments
 (0)