Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix 1534 develop fix removal of semi-colon at end of list #1535

Merged
merged 8 commits into from
Apr 20, 2022
26 changes: 26 additions & 0 deletions internal_tests/pytests/command_builder/test_command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,29 @@ def test_add_met_config_dict_nested(metplus_config):
cbw.add_met_config_dict(dict_name, items)
print(f"env_var_dict: {cbw.env_var_dict}")
assert cbw.env_var_dict.get('METPLUS_OUTER_DICT') == expected_value

@pytest.mark.parametrize(
'extra, expected_value', [
# trailing semi-colon should be added at end automatically
('file_type = NETCDF_NCCF',
"'name=\"name\"; level=\"(*,*)\"; file_type = NETCDF_NCCF;'"),
('file_type = NETCDF_NCCF;',
"'name=\"name\"; level=\"(*,*)\"; file_type = NETCDF_NCCF;'"),
('file_type = NETCDF_NCCF; other_opt = "opt"',
"'name=\"name\"; level=\"(*,*)\"; file_type = NETCDF_NCCF; other_opt = \"opt\";'"),
]
)
def test_get_field_info_extra(metplus_config, extra, expected_value):
d_type = 'FCST'
name = 'name'
level = '"(*,*)"'
config = metplus_config()
wrapper = CommandBuilder(config)
actual_value = wrapper.get_field_info(
d_type=d_type,
v_name=name,
v_level=level,
v_extra=extra,
add_curly_braces=False
)[0]
assert actual_value == expected_value
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def test_remove_quotes(before, after):
# 12: list with square braces and ending semi-colon (MET format) no quotes
('[MET_BASE/poly/LMV.poly];',
["MET_BASE/poly/LMV.poly"]),
# 13: single item ending with semi-colon should keep semi-colon
('file_type = NETCDF_NCCF;',
["file_type = NETCDF_NCCF;"]),
# 14: list with line break at beginning
('\nsome_value,\n some_other_value',
["some_value", "some_other_value"]),
]
)
def test_getlist(string_list, output_list):
Expand Down
2 changes: 1 addition & 1 deletion metplus/util/diff_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def compare_files(filepath_a, filepath_b, debug=False, dir_a=None, dir_b=None,
if not os.path.exists(filepath_b):
if debug:
print(f"ERROR: File does not exist: {filepath_b}")
return (filepath_a, '', 'file not found', '')
return (filepath_a, '', 'file not found (in truth but missing now)', '')

file_type = get_file_type(filepath_a)
if file_type.startswith('skip'):
Expand Down
11 changes: 9 additions & 2 deletions metplus/util/string_manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ def getlist(list_str, expand_begin_end_incr=True):
if not list_str:
return []

# FIRST remove surrounding comma, and spaces, form the string.
list_str = list_str.strip(';[] ').strip().strip(',').strip()
# remove surrounding comma and spaces from the string
list_str = list_str.strip(', ').strip()

# remove trailing semi-colon IF found after []s
if list_str.endswith('];'):
list_str = list_str.strip('; ').strip()

# remove [ from start (left) and ] from end (right)
list_str = list_str.lstrip('[ ').rstrip('] ').strip()

# remove space around commas
list_str = re.sub(r'\s*,\s*', ',', list_str)
Expand Down
6 changes: 5 additions & 1 deletion metplus/wrappers/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,11 @@ def get_field_info(self, d_type='', v_name='', v_level='', v_thresh=None,

# handle extra options if set
if v_extra:
field += f' {v_extra}'
extra = v_extra.strip()
# if trailing semi-colon is not found, add it
if not extra.endswith(';'):
extra = f"{extra};"
field += f' {extra}'

# add curly braces around field info
if add_curly_braces:
Expand Down