Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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', [])
def test_codes_new_from_samples_errors():
with pytest.raises(ValueError):
bindings.codes_new_from_samples('non-existent')
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)
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'])
def test_codes_new_from_samples():
res = bindings.codes_new_from_samples('regular_ll_sfc_grib2')
assert isinstance(res, bindings.ffi.CData)
assert "grib_handle *'" in repr(res)
def from_sample_name(cls, sample_name, product_kind=eccodes.CODES_PRODUCT_GRIB, **kwargs):
codes_id = eccodes.codes_new_from_samples(sample_name, product_kind)
return cls(codes_id=codes_id, **kwargs)