def test_read_emep_read_var(path_emep): with pytest.raises(ValueError): r = ReadMscwCtm() r.read_var('vmro3') with pytest.raises(ValueError): r = ReadMscwCtm() r.read_var('vmro3') data_dir = path_emep['data_dir'] with pytest.raises(ValueError): r = ReadMscwCtm(data_dir=data_dir) r.read_var('vmro3') with does_not_raise_exception(): r = ReadMscwCtm(data_dir=data_dir) r.read_var('vmro3', 'daily')
def test_colocator_read_ungridded(): col = Colocator(raise_exceptions=True) obs_id = 'AeronetSunV3L2Subset.daily' obs_var = 'od550aer' col.obs_filters = {'longitude': [-30, 30]} col.obs_id = obs_id col.read_opts_ungridded = {'last_file': 10} data = col.read_ungridded(obs_var) assert isinstance(data, UngriddedData) col.read_opts_ungridded = None col.obs_vars = ['od550aer'] with does_not_raise_exception(): data = col.read_ungridded() col.obs_vars = ['invalid'] with pytest.raises(DataCoverageError): data = col.read_ungridded()
EX_WRONG5 = deepcopy(EX_WRONG4) EX_WRONG5['aux_requires']['blablub'] = {'abc': '42'} EX_WRONG6 = deepcopy(EX_WRONG5) EX_WRONG6['aux_requires']['blablub']['def'] = '43' EX_WRONG7 = deepcopy(EX_WRONG6) EX_WRONG7['aux_funs']['blablub'] = 'abc;42+def;43' EX_NOTWRONG1 = deepcopy(EX_WRONG7) EX_NOTWRONG1['aux_units']['blablub'] = '1' @pytest.mark.parametrize('argdict,expectation', [ (AUX_EXAMPLE, does_not_raise_exception()), (EX_WRONG1, pytest.raises(ValueError)), (EX_WRONG2, pytest.raises(ValueError)), (EX_WRONG3, pytest.raises(ValueError)), (EX_WRONG3p5, pytest.raises(ValueError)), (EX_WRONG4, pytest.raises(ValueError)), (EX_WRONG5, pytest.raises(ValueError)), (EX_WRONG6, pytest.raises(ValueError)), (EX_WRONG7, pytest.raises(ValueError)), (EX_NOTWRONG1, does_not_raise_exception()), ]) def test_AuxInfoUngridded___init__(argdict, expectation): with expectation: info = testmod.AuxInfoUngridded(**argdict) for key, dtype in AuxInfoUngriddedTypes.items(): assert isinstance(info.__dict__[key], dtype)
data = xr.DataArray.from_iris(cube) # First coordinate does not exist in the dataarray. lat = [15, 15, 18] lon = [1, 15, 18] subset = helpers.extract_latlon_dataarray(data, lat, lon, check_domain=True) assert isinstance(subset, xr.DataArray) assert len(subset.lat) == len(lat) - 1 and len(subset.lon) == len(lon) - 1 @pytest.mark.parametrize('lat,lon,expectation', [([], [], pytest.raises(DataCoverageError)), ([1, 2], [-1, 2], pytest.raises(DataCoverageError)), ([15], [15], does_not_raise_exception())]) def test_extract_latlon_dataarray_no_matches(lat, lon, expectation): cube = helpers.make_dummy_cube_latlon(lat_res_deg=1, lon_res_deg=1, lat_range=[10, 20], lon_range=[10, 20]) data = xr.DataArray.from_iris(cube) with expectation: helpers.extract_latlon_dataarray(data, lat, lon, check_domain=True) @pytest.mark.parametrize( "date,ts_type,expected", [ ("2000-02-18", "monthly", 29), # February leap year ("2000-02-18", "yearly", 366), # Leap year
def test_colocator_filter_name(): with does_not_raise_exception(): Colocator(filter_name='WORLD') with pytest.raises(Exception): Colocator(filter_name='invalid')
@pytest.mark.parametrize('var1,var2,add_args,numst,mean_first,expectation', [('od550aer', 'od550aer', {}, 13, { 'od550aer': 0.5 }, pytest.raises(ValueError)), ('od550aer', 'ang4487aer', { 'merge_how': 'mean', 'var_name_out': 'blaaa' }, 13, { 'blaaa': 0.251 }, pytest.raises(NotImplementedError)), ('od550aer', 'ang4487aer', {}, 18, { 'od550aer': 0.50155, 'ang4487aer': 0.25738 }, does_not_raise_exception()), ('od550aer', 'ang4487aer', { 'merge_how': 'eval', 'merge_eval_fun': OD450FUN, 'var_name_out': 'od450aer', 'var_unit_out': '1' }, 18, { 'od550aer': 0.50155, 'ang4487aer': 0.25738, 'od450aer': 0.51902 }, does_not_raise_exception())]) def test_combine_vardata_ungridded_single_ungridded(aeronetsunv3lev2_subset, var1, var2, add_args, numst, mean_first, expectation):
""" import pytest from pyaerocom.web import helpers as h from pyaerocom.conftest import does_not_raise_exception @pytest.mark.parametrize( 'input_args,expectation', [ pytest.param(dict(), pytest.raises(ValueError)), # the following input for obs_vars is converted into a # list in the setup class pytest.param( dict(obs_id='Bla', obs_vars='od550aer', obs_vert_type='Column'), does_not_raise_exception()), pytest.param( dict(obs_id='Bla', obs_vars='od550aer', obs_vert_type='Slant-Column'), pytest.raises(ValueError)), ]) def test_ObsConfigEval(input_args, expectation): with expectation: cfg = h.ObsConfigEval(**input_args) for key, val in input_args.items(): if key == 'obs_vars' and isinstance(val, str): val = [val] assert cfg[key] == val def test_ObsConfigEval_keys():