Skip to content

Commit

Permalink
made test independent of cds
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Sep 25, 2024
1 parent 995e18b commit 317783f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pytest
import dfm_tools as dfmt
import os
import xarray as xr
import pandas as pd


@pytest.mark.requiressecrets
Expand All @@ -25,3 +27,13 @@ def file_nc_era5_pattern(tmp_path):
# assert downloaded files
file_nc_era5_pattern = os.path.join(tmp_path, "*.nc")
return file_nc_era5_pattern


@pytest.fixture
def ds_era5_empty():
# create dummy dataset
ds_era5_empty = xr.Dataset()
ds_era5_empty['longitude'] = xr.DataArray()
time_data = pd.date_range('2010-01-31', '2010-02-01', freq="3h")
ds_era5_empty['time'] = xr.DataArray(time_data, dims='time')
return ds_era5_empty
14 changes: 7 additions & 7 deletions tests/test_modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,18 @@ def test_make_paths_relative(tmp_path):


@pytest.mark.unittest
@pytest.mark.requiressecrets
@pytest.mark.timeout(60) # useful since CDS downloads are terribly slow sometimes, so skip in that case
def test_preprocess_merge_meteofiles_era5_unsupported_varlist(file_nc_era5_pattern, tmp_path):
def test_preprocess_merge_meteofiles_era5_unsupported_varlist(tmp_path, ds_era5_empty):
file_nc = os.path.join(tmp_path,"era5_msl_empty.nc")
ds_era5_empty.to_netcdf(file_nc)

ext_old = None # this won't be reached, so not relevant what to supply
date_min = '2010-01-31'
date_max = '2010-02-01'
date_min = ds_era5_empty.time.to_pandas().iloc[0]
date_max = ds_era5_empty.time.to_pandas().iloc[-1]
varlist_list = ['msl']
dir_output_data_era5 = os.path.dirname(file_nc_era5_pattern)
with pytest.raises(KeyError) as e:
ext_old = dfmt.preprocess_merge_meteofiles_era5(ext_old=ext_old,
varkey_list=varlist_list,
dir_data=dir_output_data_era5,
dir_data=tmp_path,
dir_output=tmp_path,
time_slice=slice(date_min, date_max))
assert "is not supported by dfmt.preprocess_merge_meteofiles_era5" in str(e.value)
Expand Down

0 comments on commit 317783f

Please sign in to comment.