Skip to content

Commit 31b3418

Browse files
jonasjuckergithub-actions
andauthored
last test (#399)
Co-authored-by: github-actions <github-actions@github.com>
1 parent 42c0b4e commit 31b3418

File tree

2 files changed

+90
-4
lines changed

2 files changed

+90
-4
lines changed

python/WrapExtpar.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,13 @@ def setup_oro_namelist_icon(args, lonmax, lonmin, latmax, latmin):
451451

452452
# &orography_smoothing
453453
namelist['lfilter_oro'] = ".FALSE."
454+
454455
# not relevant for ICON grid, but required for namelist
455456
namelist.update(orography_smoothing_params())
457+
namelist['lpreproc_oro'] = ".FALSE."
458+
namelist['sgsl_files'] = 'placeholder_file'
459+
namelist['idem_type'] = args['itopo_type']
460+
namelist['raw_data_sgsl_path'] = args['raw_data_path']
456461

457462
# &radtopo
458463
if args['lradtopo']:
@@ -802,9 +807,9 @@ def replace_placeholders(args, templates, dir, actual_values):
802807
# check that no @PLACEHOLDERS@ are left
803808
for template in templates:
804809
if '@' in all_templates[template]:
805-
logging.error(f'Not all placeholders in {template} were replaced')
806810
raise ValueError(
807-
f'Not all placeholders in {template} were replaced')
811+
f'Not all placeholders in {all_templates[template]} were replaced'
812+
)
808813

809814
# write complete template to file
810815
for template in templates:

test/pytest/test_wrap_extpar.py

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import os
2+
import tempfile
3+
import shutil
4+
import requests
25
import pytest
36

47
try:
@@ -12,6 +15,33 @@
1215
from WrapExtpar import *
1316

1417

18+
@pytest.fixture
19+
def tmp_dir():
20+
tmp_dir = tempfile.mkdtemp()
21+
yield tmp_dir
22+
shutil.rmtree(tmp_dir)
23+
24+
25+
@pytest.fixture
26+
def icon_grid(tmp_dir):
27+
28+
# URL of the file to download
29+
url = 'http://icon-downloads.mpimet.mpg.de/grids/public/mpim/0013/icon_grid_0013_R02B04_G.nc'
30+
31+
# Local file path to save the downloaded file
32+
output_file = os.path.join(tmp_dir, 'icon_grid_0013_R02B04_G.nc')
33+
34+
# Download the file
35+
response = requests.get(url, stream=True)
36+
response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx
37+
38+
# Write the content to a local file
39+
with open(output_file, 'wb') as file:
40+
for chunk in response.iter_content(chunk_size=8192):
41+
file.write(chunk)
42+
yield output_file
43+
44+
1545
def test_setup_flake_namelist():
1646
args = {'raw_data_path': '/path/to/raw/data'}
1747
expected_namelist = {
@@ -645,6 +675,8 @@ def test_setup_oro_namelist_icon_globe():
645675
".FALSE.",
646676
'sgsl_buffer_file':
647677
'placeholder_file',
678+
'sgsl_files':
679+
'placeholder_file',
648680
'itopo_type':
649681
1,
650682
'raw_data_orography_path':
@@ -669,8 +701,12 @@ def test_setup_oro_namelist_icon_globe():
669701
"'placeholder_file'",
670702
'raw_data_scale_sep_path':
671703
'/path/to/raw/data',
704+
'raw_data_sgsl_path':
705+
'/path/to/raw/data',
672706
'lfilter_oro':
673707
".FALSE.",
708+
'lpreproc_oro':
709+
'.FALSE.',
674710
'ilow_pass_oro':
675711
4,
676712
'numfilt_oro':
@@ -685,6 +721,8 @@ def test_setup_oro_namelist_icon_globe():
685721
750.0,
686722
'eps_filter':
687723
0.1,
724+
'idem_type':
725+
1,
688726
'rfill_valley':
689727
0.0,
690728
'ifill_valley':
@@ -726,6 +764,8 @@ def test_setup_oro_namelist_icon_merit_lradtopo():
726764
".FALSE.",
727765
'sgsl_buffer_file':
728766
'placeholder_file',
767+
'sgsl_files':
768+
'placeholder_file',
729769
'itopo_type':
730770
3,
731771
'raw_data_orography_path':
@@ -746,8 +786,12 @@ def test_setup_oro_namelist_icon_merit_lradtopo():
746786
"'placeholder_file'",
747787
'raw_data_scale_sep_path':
748788
'/path/to/raw/data',
789+
'raw_data_sgsl_path':
790+
'/path/to/raw/data',
749791
'lfilter_oro':
750792
".FALSE.",
793+
'lpreproc_oro':
794+
'.FALSE.',
751795
'ilow_pass_oro':
752796
4,
753797
'numfilt_oro':
@@ -762,6 +806,8 @@ def test_setup_oro_namelist_icon_merit_lradtopo():
762806
750.0,
763807
'eps_filter':
764808
0.1,
809+
'idem_type':
810+
3,
765811
'rfill_valley':
766812
0.0,
767813
'ifill_valley':
@@ -819,7 +865,7 @@ def test_setup_edgar_namelist():
819865
assert setup_edgar_namelist(args) == expected_namelist
820866

821867

822-
def test_all_placeholders_replaced_cosmo():
868+
def test_all_placeholders_replaced_cosmo(tmp_dir):
823869
args = {
824870
"igrid_type": 2,
825871
"input_grid": 'test/testsuite/data/clm/12km_globe/INPUT_COSMO_GRID',
@@ -837,7 +883,42 @@ def test_all_placeholders_replaced_cosmo():
837883
"use_array_cache": False,
838884
"radtopo_radius": 40000.0,
839885
"raw_data_path": '/dummy/raw_data_path',
840-
"run_dir": './.pytest_rundir',
886+
"run_dir": str(tmp_dir),
887+
"account": 'dummy_account',
888+
"host": 'docker',
889+
"no_batch_job": True,
890+
"lurban": False,
891+
"lsgsl": False,
892+
"lfilter_oro": False,
893+
"lradtopo": False
894+
}
895+
896+
namelist = setup_namelist(args)
897+
runscript = setup_runscript(args)
898+
# in this function all placeholders from the template are replaced,
899+
# it raises an error if there are any placeholders left
900+
prepare_sandbox(args, namelist, runscript, test_run=True)
901+
902+
903+
def test_all_placeholders_replaced_icon(tmp_dir, icon_grid):
904+
args = {
905+
"igrid_type": 1,
906+
"input_grid": icon_grid,
907+
"iaot_type": 1,
908+
"ilu_type": 1,
909+
"ialb_type": 1,
910+
"isoil_type": 1,
911+
"itopo_type": 1,
912+
"it_cl_type": 1,
913+
"iera_type": 1,
914+
"iemiss_type": 1,
915+
"enable_cdnc": False,
916+
"enable_edgar": False,
917+
"enable_art": False,
918+
"use_array_cache": False,
919+
"radtopo_radius": 40000.0,
920+
"raw_data_path": '/dummy/raw_data_path',
921+
"run_dir": str(tmp_dir),
841922
"account": 'dummy_account',
842923
"host": 'docker',
843924
"no_batch_job": True,

0 commit comments

Comments
 (0)