Skip to content

Commit ab2297b

Browse files
committed
add comprehensive https test
1 parent d0207f0 commit ab2297b

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

tests/test_real_https.py

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,77 @@
44
import pytest
55

66
import activestorage
7+
from requests.exceptions import MissingSchema
78
from activestorage.active import Active, load_from_https
89

910

11+
def test_https():
12+
"""
13+
Run a https test with a small enough file for the test
14+
not to be marked as slow. We test all aspects here.
15+
File: https://esgf.ceda.ac.uk/thredds/fileServer/esg_cmip6/CMIP6/CMIP/MOHC/UKESM1-1-LL/piControl/r1i1p1f2/Amon/ta/gn/latest/ta_Amon_UKESM1-1-LL_piControl_r1i1p1f2_gn_274301-274912.nc
16+
Size: 75 MiB, variable: ta
17+
Entire test uses at most 400M RES memory.
18+
"""
19+
test_file_uri = "https://esgf.ceda.ac.uk/thredds/fileServer/esg_cmip6/CMIP6/CMIP/MOHC/UKESM1-1-LL/piControl/r1i1p1f2/Amon/ta/gn/latest/ta_Amon_UKESM1-1-LL_piControl_r1i1p1f2_gn_274301-274912.nc"
20+
active_storage_url = "https://reductionist.jasmin.ac.uk/" # Wacasoft new Reductionist
21+
22+
# declared storage type, no activa storage URL
23+
active = Active(test_file_uri, "ta",
24+
storage_type="https", )
25+
active._version = 2
26+
with pytest.raises(MissingSchema):
27+
result = active.min()[0:3, 4:6, 7:9]
28+
29+
# declared storage type
30+
active = Active(test_file_uri, "ta",
31+
storage_type="https",
32+
active_storage_url=active_storage_url)
33+
active._version = 2
34+
result = active.min()[0:3, 4:6, 7:9]
35+
print("Result is", result)
36+
assert result == np.array([220.3180694580078], dtype="float32")
37+
38+
# inferred storage type
39+
active = Active(test_file_uri, "ta",
40+
active_storage_url=active_storage_url)
41+
active._version = 2
42+
result = active.min()[0:3, 4:6, 7:9]
43+
print("Result is", result)
44+
assert result == np.array([220.3180694580078], dtype="float32")
45+
46+
# set these as fixed floats
47+
f_1 = 176.882080078125
48+
f_2 = 190.227783203125
49+
50+
# inferred storage type, pop axis
51+
active = Active(test_file_uri, "ta",
52+
storage_type="https",
53+
active_storage_url=active_storage_url)
54+
active._version = 2
55+
result = active.min(axis=(0, 1))[:]
56+
print("Result is", result)
57+
print("Result shape is", result.shape)
58+
assert result.shape == (1, 1, 144, 192)
59+
assert result[0, 0, 0, 0] == f_1
60+
assert result[0, 0, 143, 191] == f_2
61+
62+
# load dataset with Pyfive
63+
dataset = load_from_https(test_file_uri)
64+
av = dataset['ta']
65+
r_min = np.min(av[:], axis=(0, 1))
66+
# NOTE the difference in shapes:
67+
# - Reductionist: (1, 1, 144, 192)
68+
# - numpy: (144, 192)
69+
# Contents is identical though.
70+
print(r_min)
71+
assert r_min[0, 0] == f_1
72+
assert r_min[143, 191] == f_2
73+
74+
1075
@pytest.mark.skip(
1176
reason="save time: test_https_implicit_storage is more general.")
12-
def test_https():
77+
def test_https_v1():
1378
"""Run a true test with a https FILE."""
1479
test_file_uri = "https://esgf.ceda.ac.uk/thredds/fileServer/esg_cmip6/CMIP6/AerChemMIP/MOHC/UKESM1-0-LL/ssp370SST-lowNTCF/r1i1p1f2/Amon/cl/gn/latest/cl_Amon_UKESM1-0-LL_ssp370SST-lowNTCF_r1i1p1f2_gn_205001-209912.nc"
1580

@@ -21,7 +86,7 @@ def test_https():
2186

2287

2388
@pytest.mark.skip(reason="save time: 2xdata = 2xtime compared to test_https.")
24-
def test_https_100years():
89+
def test_https_v1_100years_file():
2590
"""Run a true test with a https FILE."""
2691
test_file_uri = "https://esgf.ceda.ac.uk/thredds/fileServer/esg_cmip6/CMIP6/CMIP/MOHC/UKESM1-1-LL/historical/r1i1p1f2/Amon/pr/gn/latest/pr_Amon_UKESM1-1-LL_historical_r1i1p1f2_gn_195001-201412.nc"
2792
active = Active(test_file_uri, "pr")
@@ -31,10 +96,8 @@ def test_https_100years():
3196
assert result == np.array([5.4734613e-07], dtype="float32")
3297

3398

34-
# this could be a slow test on GHA depending on network load
35-
# also Githb machines are very far from Oxford
3699
@pytest.mark.slow
37-
def test_https_reductionist():
100+
def test_https_bigger_file():
38101
"""Run a true test with a https FILE."""
39102
test_file_uri = "https://esgf.ceda.ac.uk/thredds/fileServer/esg_cmip6/CMIP6/AerChemMIP/MOHC/UKESM1-0-LL/ssp370SST-lowNTCF/r1i1p1f2/Amon/cl/gn/latest/cl_Amon_UKESM1-0-LL_ssp370SST-lowNTCF_r1i1p1f2_gn_205001-209912.nc"
40103
active_storage_url = "https://reductionist.jasmin.ac.uk/" # Wacasoft new Reductionist
@@ -45,8 +108,6 @@ def test_https_reductionist():
45108
assert result == np.array([0.6909787], dtype="float32")
46109

47110

48-
# this could be a slow test on GHA depending on network load
49-
# also Githb machines are very far from Oxford
50111
@pytest.mark.slow
51112
def test_https_implicit_storage():
52113
"""Run a true test with a https FILE."""
@@ -100,8 +161,6 @@ def test_https_dataset():
100161
assert result == np.array([0.6909787], dtype="float32")
101162

102163

103-
# this could be a slow test on GHA depending on network load
104-
# also Githb machines are very far from Oxford
105164
@pytest.mark.slow
106165
def test_https_dataset_implicit_storage():
107166
"""Run a true test with a https DATASET."""

0 commit comments

Comments
 (0)