コード例 #1
0
ファイル: test_10_bindings.py プロジェクト: mhdella/cfgrib
def test_codes_set():
    message_id = bindings.codes_new_from_samples(b'regular_ll_sfc_grib2')

    bindings.codes_set(message_id, b'endStep', 2)
    bindings.codes_set(message_id, b'longitudeOfFirstGridPointInDegrees', 1.)
    bindings.codes_set(message_id, b'gridType', b'regular_ll')

    with pytest.raises(TypeError):
        bindings.codes_set(message_id, b'endStep', [])
コード例 #2
0
def test_codes_set():
    message_id = bindings.codes_new_from_samples("regular_ll_sfc_grib2")

    bindings.codes_set(message_id, "endStep", 2)
    bindings.codes_set(message_id, "longitudeOfFirstGridPointInDegrees", 1.0)
    bindings.codes_set(message_id, "gridType", "regular_ll")

    with pytest.raises(TypeError):
        bindings.codes_set(message_id, "endStep", [])
コード例 #3
0
ファイル: test_10_bindings.py プロジェクト: mhdella/cfgrib
def test_codes_write(tmpdir):
    message_id = bindings.codes_new_from_samples(b'regular_ll_sfc_grib2')
    grib_file = tmpdir.join('test.grib')

    with open(str(grib_file), 'wb') as file:
        bindings.codes_write(message_id, file)

    assert grib_file.read_binary()[:4] == b'GRIB'

    with open(str(grib_file)) as file:
        bindings.codes_handle_new_from_file(file)
コード例 #4
0
ファイル: test_10_bindings.py プロジェクト: mhdella/cfgrib
def test_codes_set_array():
    message_id = bindings.codes_new_from_samples(b'regular_ll_sfc_grib2')

    bindings.codes_set_array(message_id, b'values', [0.])
    bindings.codes_set_array(message_id, b'values', [0])

    with pytest.raises(ValueError):
        bindings.codes_set_array(message_id, b'values', [])

    with pytest.raises(TypeError):
        bindings.codes_set_array(message_id, b'values', ['a'])
コード例 #5
0
def test_codes_write(tmpdir):
    message_id = bindings.codes_new_from_samples("regular_ll_sfc_grib2")
    grib_file = tmpdir.join("test.grib")

    with open(str(grib_file), "wb") as file:
        bindings.codes_write(message_id, file)

    assert grib_file.read_binary()[:4] == b"GRIB"

    with open(str(grib_file)) as file:
        bindings.codes_grib_new_from_file(file)
コード例 #6
0
def test_codes_set_array():
    message_id = bindings.codes_new_from_samples("regular_ll_sfc_grib2")

    bindings.codes_set_array(message_id, "values", [0.0])
    bindings.codes_set_array(message_id, "values", [0])

    with pytest.raises(ValueError):
        bindings.codes_set_array(message_id, "values", [])

    with pytest.raises(TypeError):
        bindings.codes_set_array(message_id, "values", ["a"])
コード例 #7
0
ファイル: test_10_bindings.py プロジェクト: mhdella/cfgrib
def test_codes_new_from_samples_errors():
    with pytest.raises(ValueError):
        bindings.codes_new_from_samples(b'non-existent')
コード例 #8
0
ファイル: test_10_bindings.py プロジェクト: mhdella/cfgrib
def test_codes_new_from_samples():
    res = bindings.codes_new_from_samples(b'regular_ll_sfc_grib2')

    assert isinstance(res, bindings.ffi.CData)
    assert "grib_handle *'" in repr(res)