Skip to content

Commit

Permalink
per #2189, added unit tests that demonstrate bug and fix logic to mak…
Browse files Browse the repository at this point in the history
…e tests pass
  • Loading branch information
georgemccabe committed May 31, 2023
1 parent 62f2759 commit d37b4dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Expand Up @@ -128,6 +128,8 @@ def test_threshold(key, value):
("goSFP90", None),
("NA", [('NA', '')]),
("<USP90(2.5)", [('<', 'USP90(2.5)')]),
('gt4 && lt5', [('gt', 4), ('lt', 5)]),
(' gt4', [('gt', 4)]),
]
)
@pytest.mark.util
Expand Down
Expand Up @@ -14,9 +14,10 @@
obs_name = 'APCP_03'
obs_level_no_quotes = '(*,*)'
obs_level = f'"{obs_level_no_quotes}"'
fcst_fmt = f'field = [{{ name="{fcst_name}"; level="{fcst_level}"; }}];'
both_thresh = ' lt-0.5,gt-0.5 && lt0.5,gt0.5 '
fcst_fmt = f'field = [{{ name="{fcst_name}"; level="{fcst_level}"; cat_thresh=[{both_thresh}]; }}];'
obs_fmt = (f'field = [{{ name="{obs_name}"; '
f'level="{obs_level_no_quotes}"; }}];')
f'level="{obs_level_no_quotes}"; cat_thresh=[{both_thresh}]; }}];')
time_fmt = '%Y%m%d%H'
run_times = ['2005080700', '2005080712']

Expand Down Expand Up @@ -52,6 +53,7 @@ def set_minimum_config_settings(config):
config.set('config', 'FCST_VAR1_LEVELS', fcst_level)
config.set('config', 'OBS_VAR1_NAME', obs_name)
config.set('config', 'OBS_VAR1_LEVELS', obs_level)
config.set('config', 'BOTH_VAR1_THRESH', both_thresh)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -751,6 +753,7 @@ def test_grid_stat_single_field(metplus_config, config_overrides,
]

all_cmds = wrapper.run_all_times()
assert len(all_cmds) == len(expected_cmds)
print(f"ALL COMMANDS: {all_cmds}")

missing_env = [item for item in env_var_values
Expand Down
2 changes: 1 addition & 1 deletion metplus/util/string_manip.py
Expand Up @@ -323,7 +323,7 @@ def get_threshold_via_regex(thresh_string):
# split thresh string by || or &&
thresh_split = re.split(r'\|\||&&', thresh_string)
# check each threshold for validity
for thresh in thresh_split:
for thresh in [item.strip() for item in thresh_split]:
found_match = False
for comp in list(VALID_COMPARISONS)+list(VALID_COMPARISONS.values()):
# if valid, add to list of tuples
Expand Down

0 comments on commit d37b4dd

Please sign in to comment.