Skip to content

Commit

Permalink
per #1910, added unit tests to ensure that level is set properly in t…
Browse files Browse the repository at this point in the history
…he forecast input template
  • Loading branch information
georgemccabe committed Nov 7, 2022
1 parent 1b3b91d commit f67106f
Showing 1 changed file with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,49 @@ def set_minimum_config_settings(config, set_fields=True):
config.set('config', 'OBS_VAR1_LEVELS', obs_level)


@pytest.mark.parametrize(
'config_overrides, expected_filename', [
# 0 - set forecast level
({'FCST_VAR1_NAME': 'fcst_file',
'FCST_VAR1_LEVELS': 'A06',
'OBS_VAR1_NAME': 'obs_file',
'OBS_VAR1_LEVELS': 'A06',
'FCST_ENSEMBLE_STAT_INPUT_TEMPLATE': '{fcst_name}_A{level?fmt=%3H}',
},
f'{fcst_dir}/fcst_file_A006'),
# 1 - don't set forecast level
({'FCST_ENSEMBLE_STAT_INPUT_TEMPLATE': 'fcst_file_A{level?fmt=%3H}'},
f'{fcst_dir}/fcst_file_A000'),
]
)
@pytest.mark.wrapper_c
def test_ensemble_stat_level_in_template(metplus_config, config_overrides,
expected_filename):

config = metplus_config

set_minimum_config_settings(config, set_fields=False)

# set config variable overrides
for key, value in config_overrides.items():
config.set('config', key, value)

wrapper = EnsembleStatWrapper(config)
assert wrapper.isOK

file_list_dir = wrapper.config.getdir('FILE_LISTS_DIR')
file_list_file = f"{file_list_dir}/20050807000000_12_ensemble_stat.txt"
if os.path.exists(file_list_file):
os.remove(file_list_file)

wrapper.run_all_times()
assert os.path.exists(file_list_file)
with open(file_list_file, 'r') as file_handle:
filenames = file_handle.read().splitlines()[1:]
assert len(filenames) == 1
assert filenames[0] == expected_filename


@pytest.mark.parametrize(
'config_overrides, env_var_values', [
# 0 : no ens, 1 fcst, 1 obs
Expand Down Expand Up @@ -577,8 +620,7 @@ def test_ensemble_stat_single_field(metplus_config, config_overrides,

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
file_list_dir = os.path.join(wrapper.config.getdir('STAGING_DIR'),
'file_lists')
file_list_dir = wrapper.config.getdir('FILE_LISTS_DIR')
config_file = wrapper.c_dict.get('CONFIG_FILE')
out_dir = wrapper.c_dict.get('OUTPUT_DIR')
expected_cmds = [(f"{app_path} {verbosity} "
Expand Down Expand Up @@ -655,8 +697,7 @@ def test_ensemble_stat_fill_missing(metplus_config, config_overrides,

wrapper = EnsembleStatWrapper(config)

file_list_file = os.path.join(wrapper.config.getdir('STAGING_DIR'),
'file_lists',
file_list_file = os.path.join(wrapper.config.getdir('FILE_LISTS_DIR'),
'20050807000000_12_ensemble_stat.txt')
if os.path.exists(file_list_file):
os.remove(file_list_file)
Expand Down

0 comments on commit f67106f

Please sign in to comment.