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
|
from pyfdb import FDB, URI
def test_list_element_uri(read_only_fdb_setup):
fdb = FDB(read_only_fdb_setup)
selection = {
"type": "an",
"class": "ea",
"domain": "g",
"expver": "0001",
"stream": "oper",
"date": "20200101",
"levtype": "sfc",
"step": "0",
"time": "1800",
}
list_iterator = fdb.list(selection, level=1)
assert list_iterator
elements = list(list_iterator)
assert len(elements) == 1
print(elements[0])
print(elements[0].uri)
print("----------------------------------")
selection = {
"type": "an",
"class": "ea",
"domain": "g",
"expver": "0001",
"stream": "oper",
"date": "20200101",
"levtype": "sfc",
"step": "0",
"time": "1800",
}
list_iterator = fdb.list(selection, level=2)
assert list_iterator
elements = list(list_iterator)
assert len(elements) == 1
print(elements[0])
print(elements[0].uri)
print("----------------------------------")
selection = {
"type": "an",
"class": "ea",
"domain": "g",
"expver": "0001",
"stream": "oper",
"date": "20200101",
"levtype": "sfc",
"step": "0",
"time": "1800",
}
list_iterator = fdb.list(selection, level=3)
assert list_iterator
elements = [el.uri for el in list_iterator if el.uri]
assert len(elements) == 3
for el in elements:
assert el is not None
assert el.path() is not None
def test_uri_roundtrip():
uri_str = (
"scheme://user:secretpass@example.com:8443/path/to/resource?query=search&sort=asc#section-2"
)
test_uri = URI(uri_str)
assert test_uri.scheme() == "scheme"
assert test_uri.username() == "user"
assert test_uri.password() == "secretpass"
assert test_uri.hostname() == "example.com"
assert test_uri.hostname() == "example.com"
assert test_uri.netloc() == "user:secretpass@example.com:8443"
assert test_uri.port() == 8443
assert test_uri.path() == "/path/to/resource"
assert test_uri.query() == "query=search&sort=asc"
assert test_uri.fragment() == "section-2"
assert str(test_uri) == uri_str
print(test_uri)
def test_uri_cmp():
uri_str = (
"scheme://user:secretpass@example.com:8443/path/to/resource?query=search&sort=asc#section-2"
)
test_uri = URI(uri_str)
uri_str_section3 = (
"scheme://user:secretpass@example.com:8443/path/to/resource?query=search&sort=asc#section-3"
)
test_uri_section3 = URI(uri_str_section3)
assert test_uri != test_uri_section3
assert uri_str_section3 != test_uri_section3
|