/usr/lib/python3/dist-packages/pydap/tests/test_cas_esgf.py is in python3-pydap 3.2.2+ds1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | from pydap.client import open_url
import pydap.net
from pydap.cas import esgf
import requests
import numpy as np
import os
import pytest
url = ('http://aims3.llnl.gov/thredds/dodsC/'
'cmip5_css02_data/cmip5/output1/CCCma/CanCM4/'
'decadal1995/fx/atmos/fx/r0i0p0/orog/1/'
'orog_fx_CanCM4_decadal1995_r0i0p0.nc')
test_url = url + '.dods?orog[0:1:4][0:1:4]'
@pytest.mark.auth
@pytest.mark.prod_url
@pytest.mark.skipif(not (os.environ.get('OPENID_ESGF_NO_REG') and
os.environ.get('PASSWORD_ESGF_NO_REG')),
reason=('Without auth credentials, '
'this test cannot work'))
def test_registration_esgf_auth():
"""
Attempt to access a ESGF OPENDAP link for which
the user has not yet selected a registration group.
This procedure has to be completed only once per project
over the lifetime of an ESGF OPENID
Requires OPENID_ESGF_NO_REG and PASSWORD_ESGF_NO_REG
environment variables. These must be associated with credentials
where no group was selected.
"""
with pytest.raises(UserWarning):
esgf.setup_session(os.environ.get('OPENID_ESGF_NO_REG'),
os.environ.get('PASSWORD_ESGF_NO_REG'),
check_url=url)
@pytest.mark.auth
@pytest.mark.prod_url
@pytest.mark.skipif(not (os.environ.get('OPENID_ESGF') and
os.environ.get('PASSWORD_ESGF')),
reason=('Without auth credentials, '
'this test cannot work'))
def test_basic_esgf_auth():
"""
Set up PyDAP to use the ESGF request() function.
The intent here is to ensure that pydap.net is able to
open and url if and only if requests is able to
open the same url.
"""
session = esgf.setup_session(os.environ.get('OPENID_ESGF'),
os.environ.get('PASSWORD_ESGF'),
check_url=url)
res = requests.get(test_url, cookies=session.cookies,
verify=False)
assert(res.status_code == 200)
res.close()
res = pydap.net.follow_redirect(test_url, session=session)
assert(res.status_code == 200)
@pytest.mark.auth
@pytest.mark.prod_url
@pytest.mark.skipif(not (os.environ.get('OPENID_ESGF') and
os.environ.get('PASSWORD_ESGF')),
reason=('Without auth credentials, '
'this test cannot work'))
def test_dimension_esgf_query():
session = esgf.setup_session(os.environ.get('OPENID_ESGF'),
os.environ.get('PASSWORD_ESGF'),
check_url=url)
# Ensure authentication:
res = pydap.net.follow_redirect(test_url, session=session)
assert(res.status_code == 200)
dataset = open_url(url, session=session)
data = dataset['lon'][:5]
expected_data = np.array([0.0, 2.8125, 5.625, 8.4375, 11.25])
assert(np.isclose(data, expected_data).all())
@pytest.mark.auth
@pytest.mark.prod_url
@pytest.mark.skipif(not (os.environ.get('OPENID_ESGF') and
os.environ.get('PASSWORD_ESGF')),
reason=('Without auth credentials, '
'this test cannot work'))
def test_variable_esgf_query():
session = esgf.setup_session(os.environ.get('OPENID_ESGF'),
os.environ.get('PASSWORD_ESGF'),
check_url=url)
# Ensure authentication:
res = pydap.net.follow_redirect(test_url, session=session)
assert(res.status_code == 200)
dataset = open_url(url, session=session, output_grid=False)
data = dataset['orog'][50:55, 50:55]
expected_data = [[197.70425, 16.319595, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
[677.014, 628.29675, 551.06, 455.5758, 343.7354],
[1268.3304, 1287.9553, 1161.0402, 978.3153, 809.143]]
assert(np.isclose(data, expected_data).all())
@pytest.mark.auth
@pytest.mark.prod_url
@pytest.mark.skipif(not (os.environ.get('OPENID_ESGF_CEDA') and
os.environ.get('USERNAME_ESGF_CEDA') and
os.environ.get('PASSWORD_ESGF_CEDA')),
reason=('Without auth credentials, '
'this test cannot work'))
def test_variable_esgf_query_ceda():
session = esgf.setup_session(
os.environ.get('OPENID_ESGF_CEDA'),
os.environ.get('PASSWORD_ESGF_CEDA'),
check_url=url,
username=os.environ.get('USERNAME_ESGF_CEDA'))
# Ensure authentication:
res = pydap.net.follow_redirect(test_url, session=session)
assert(res.status_code == 200)
dataset = open_url(url, session=session, output_grid=False)
data = dataset['orog'][50:55, 50:55]
expected_data = [[197.70425, 16.319595, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
[677.014, 628.29675, 551.06, 455.5758, 343.7354],
[1268.3304, 1287.9553, 1161.0402, 978.3153, 809.143]]
assert(np.isclose(data, expected_data).all())
|