File: test_retrieve.py

package info (click to toggle)
fdb 5.20.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,268 kB
  • sloc: cpp: 40,830; python: 5,079; sh: 4,996; makefile: 32; ansic: 8
file content (55 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (2)
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
import pytest

from pyfdb import FDB


def test_retrieve(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",
        "param": ["167", "165", "166"],
        "time": "1800",
    }

    data_handle = fdb.retrieve(selection)

    assert data_handle
    data_handle.open()
    assert data_handle.read(4) == b"GRIB"
    data_handle.close()


def test_retrieve_wildcard(read_only_fdb_setup):
    fdb = FDB(read_only_fdb_setup)

    with pytest.raises(TypeError):
        _ = fdb.retrieve({})


def test_retrieve_context_manager(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",
        "param": ["167", "165", "166"],
        "time": "1800",
    }

    with fdb.retrieve(selection) as data_handle:
        assert data_handle
        assert data_handle.read(4) == b"GRIB"