Skip to content

Commit 42c0b4e

Browse files
jonasjuckergithub-actions
andauthored
Check that templates do not contain placeholders (#398)
Co-authored-by: github-actions <github-actions@github.com>
1 parent 6fef826 commit 42c0b4e

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ venv.bak/
104104

105105
# Page deployment
106106
site/
107+
108+
# Pytest folders of tests
109+
.pytest_rundir

python/WrapExtpar.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
except ImportError: # package not installed -> use PYTHONPATH
1717
from grid_def import CosmoGrid, IconGrid
1818
from utilities import launch_shell
19-
DATA_DIR = ".."
19+
DATA_DIR = os.path.join(os.path.dirname(__file__), '..')
2020

2121

2222
def main():
@@ -179,12 +179,13 @@ def run_extpar(args):
179179
logging.info("job finished")
180180

181181

182-
def prepare_sandbox(args, namelist, runscript):
182+
def prepare_sandbox(args, namelist, runscript, test_run=False):
183183

184184
os.makedirs(args['run_dir'], exist_ok=True)
185185
write_namelist(args, namelist)
186186
write_runscript(args, runscript)
187-
copy_required_files(args, runscript['extpar_executables'])
187+
if not test_run:
188+
copy_required_files(args, runscript['extpar_executables'])
188189

189190

190191
def write_runscript(args, runscript):
@@ -305,6 +306,9 @@ def setup_oro_namelist_cosmo(args):
305306
ord('p') + 1)))
306307
]
307308
namelist['lpreproc_oro'] = ".FALSE."
309+
else:
310+
namelist['lpreproc_oro'] = ".FALSE."
311+
namelist['sgsl_files'] = 'placeholder_file'
308312

309313
if tg.dlon < 0.02 and tg.dlat < 0.02:
310314
namelist['lscale_separation'] = ".FALSE."
@@ -795,6 +799,13 @@ def replace_placeholders(args, templates, dir, actual_values):
795799
all_templates[template] = all_templates[template].replace(
796800
key, str(value))
797801

802+
# check that no @PLACEHOLDERS@ are left
803+
for template in templates:
804+
if '@' in all_templates[template]:
805+
logging.error(f'Not all placeholders in {template} were replaced')
806+
raise ValueError(
807+
f'Not all placeholders in {template} were replaced')
808+
798809
# write complete template to file
799810
for template in templates:
800811
# special case for namelist.py, which is a python file but not valid with placeholders

test/pytest/test_wrap_extpar.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
from extpar.WrapExtpar import *
21
import os
32
import pytest
43

4+
try:
5+
from extpar.WrapExtpar import *
6+
except ImportError:
7+
import sys
8+
sys.path.append(
9+
os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
10+
sys.path.append(
11+
os.path.join(os.path.dirname(__file__), '..', '..', 'python/lib'))
12+
from WrapExtpar import *
13+
514

615
def test_setup_flake_namelist():
716
args = {'raw_data_path': '/path/to/raw/data'}
@@ -808,3 +817,38 @@ def test_setup_edgar_namelist():
808817
'edgar_buffer_file': 'edgar_buffer.nc'
809818
}
810819
assert setup_edgar_namelist(args) == expected_namelist
820+
821+
822+
def test_all_placeholders_replaced_cosmo():
823+
args = {
824+
"igrid_type": 2,
825+
"input_grid": 'test/testsuite/data/clm/12km_globe/INPUT_COSMO_GRID',
826+
"iaot_type": 1,
827+
"ilu_type": 1,
828+
"ialb_type": 1,
829+
"isoil_type": 1,
830+
"itopo_type": 1,
831+
"it_cl_type": 1,
832+
"iera_type": 1,
833+
"iemiss_type": 1,
834+
"enable_cdnc": False,
835+
"enable_edgar": False,
836+
"enable_art": False,
837+
"use_array_cache": False,
838+
"radtopo_radius": 40000.0,
839+
"raw_data_path": '/dummy/raw_data_path',
840+
"run_dir": './.pytest_rundir',
841+
"account": 'dummy_account',
842+
"host": 'docker',
843+
"no_batch_job": True,
844+
"lurban": False,
845+
"lsgsl": False,
846+
"lfilter_oro": False,
847+
"lradtopo": False
848+
}
849+
850+
namelist = setup_namelist(args)
851+
runscript = setup_runscript(args)
852+
# in this function all placeholders from the template are replaced,
853+
# it raises an error if there are any placeholders left
854+
prepare_sandbox(args, namelist, runscript, test_run=True)

0 commit comments

Comments
 (0)