Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wpreimes committed Oct 25, 2024
1 parent 5b222f3 commit e079468
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
strategy:
matrix:
python-version: [ '3.8', '3.12' ]
python-version: [ '3.9', '3.12']
os: [ "ubuntu-latest" , "windows-latest", "macos-latest"]
name: Py${{ matrix.python-version }}@${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
6 changes: 2 additions & 4 deletions src/ecmwf_models/era5/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,6 @@ def download_and_move(
-1 : Error in at least one request
-10 : No data available for requested time period
"""
if cds_token is not None:
os.environ["CDSAPI_KEY"] = cds_token
check_api_ready()

h_steps = list(h_steps)
product = product.lower()
cds_kwds = cds_kwds or dict()
Expand All @@ -312,6 +308,8 @@ def download_and_move(
c = None
cds_status_tracker = None
else:
if cds_token is not None:
os.environ["CDSAPI_KEY"] = cds_token
check_api_ready()

os.makedirs(target_path, exist_ok=True)
Expand Down
61 changes: 32 additions & 29 deletions tests/tests_era5/test_era5_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def test_download_with_cdo_not_installed():
save_ncs_from_nc(
infile, out_path, 'ERA5', grid=grid, keep_original=True)


def test_dry_download_nc_era5():
with tempfile.TemporaryDirectory() as dl_path:
dl_path = os.path.join(dl_path, 'era5')
Expand All @@ -81,15 +80,16 @@ def test_dry_download_nc_era5():
startdate = enddate = datetime(2010, 1, 1)
variables, h_steps = ['swvl1', 'swvl2', 'lsm'], [0, 12]

download_and_move(
dl_path,
startdate,
enddate,
variables=variables,
keep_original=False,
h_steps=h_steps,
grb=False,
dry_run=True)
with pytest.warns(UserWarning, match='Dry run*'):
download_and_move(
dl_path,
startdate,
enddate,
variables=variables,
keep_original=False,
h_steps=h_steps,
grb=False,
dry_run=True)

cont = os.listdir(dl_path)
assert len(cont) == 2
Expand Down Expand Up @@ -131,15 +131,16 @@ def test_dry_download_grb_era5():
startdate = enddate = datetime(2010, 1, 1)
variables, h_steps = ['swvl1', 'swvl2', 'lsm'], [0, 12]

download_and_move(
dl_path,
startdate,
enddate,
variables=variables,
keep_original=False,
h_steps=h_steps,
grb=True,
dry_run=True)
with pytest.warns(UserWarning, match="Dry run*"):
download_and_move(
dl_path,
startdate,
enddate,
variables=variables,
keep_original=False,
h_steps=h_steps,
grb=True,
dry_run=True)

cont = os.listdir(dl_path)
assert len(cont) == 2
Expand Down Expand Up @@ -180,16 +181,18 @@ def test_download_nc_era5_regridding():
os.path.join(dl_path, 'temp_downloaded', '20100101_20100101.nc'))

startdate = enddate = datetime(2010, 1, 1)
download_and_move(
dl_path,
startdate,
enddate,
variables=['swvl1', 'swvl2', 'lsm'],
keep_original=False,
h_steps=[0, 12],
grb=False,
dry_run=True,
grid=grid)

with pytest.warns(UserWarning, match="Dry run*"):
download_and_move(
dl_path,
startdate,
enddate,
variables=['swvl1', 'swvl2', 'lsm'],
keep_original=False,
h_steps=[0, 12],
grb=False,
dry_run=True,
grid=grid)

cont = os.listdir(dl_path)
assert len(cont) == 2
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_era5/test_era5_download_cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class DownloadTest(unittest.TestCase):

@unittest.skipIf(
os.environ.get('CDSAPI_KEY') is None and not api_ready,
'CDSAPI_KEY not found. Make sure the environment variable exists.'
'CDSAPI_KEY not found.'
)
@pytest.mark.wget
def test_cli_download(self):

with tempfile.TemporaryDirectory() as dl_path:
Expand Down

0 comments on commit e079468

Please sign in to comment.