def test_codes_set(): message_id = eccodes.codes_new_from_samples(b'regular_ll_sfc_grib2') eccodes.codes_set(message_id, b'endStep', 2) eccodes.codes_set(message_id, b'longitudeOfFirstGridPointInDegrees', 1.) eccodes.codes_set(message_id, b'gridType', b'regular_ll') eccodes.codes_set_array(message_id, b'values', [0.])
def test_codes_set(): message_id = eccodes.codes_new_from_samples(b'regular_ll_sfc_grib2') eccodes.codes_set(message_id, b'endStep', 2) eccodes.codes_set(message_id, b'longitudeOfFirstGridPointInDegrees', 1.) eccodes.codes_set(message_id, b'gridType', b'regular_ll') with pytest.raises(TypeError): eccodes.codes_set(message_id, b'endStep', [])
def test_codes_write(tmpdir): message_id = eccodes.codes_new_from_samples(b'regular_ll_sfc_grib2') grib_file = tmpdir.join('test.grib') with open(str(grib_file), 'wb') as file: eccodes.codes_write(message_id, file) assert grib_file.read_binary()[:4] == b'GRIB' with open(str(grib_file)) as file: eccodes.codes_handle_new_from_file(file)
def test_codes_set_array(): message_id = eccodes.codes_new_from_samples(b'regular_ll_sfc_grib2') eccodes.codes_set_array(message_id, b'values', [0.]) eccodes.codes_set_array(message_id, b'values', [0]) with pytest.raises(ValueError): eccodes.codes_set_array(message_id, b'values', []) with pytest.raises(TypeError): eccodes.codes_set_array(message_id, b'values', ['a'])
def test_codes_new_from_samples_errors(): with pytest.raises(ValueError): eccodes.codes_new_from_samples(b'non-existent')
def test_codes_new_from_samples(): res = eccodes.codes_new_from_samples(b'regular_ll_sfc_grib2') assert isinstance(res, eccodes.ffi.CData) assert "grib_handle *'" in repr(res)