diff --git a/internal_tests/pytests/command_builder/test_command_builder.py b/internal_tests/pytests/command_builder/test_command_builder.py index 98aed81ffd..e0a79733af 100644 --- a/internal_tests/pytests/command_builder/test_command_builder.py +++ b/internal_tests/pytests/command_builder/test_command_builder.py @@ -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 diff --git a/internal_tests/pytests/util/string_manip/test_util_string_manip.py b/internal_tests/pytests/util/string_manip/test_util_string_manip.py index 8678831f3c..0442ecc72f 100644 --- a/internal_tests/pytests/util/string_manip/test_util_string_manip.py +++ b/internal_tests/pytests/util/string_manip/test_util_string_manip.py @@ -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): diff --git a/metplus/util/diff_util.py b/metplus/util/diff_util.py index 8c59539052..1de442caac 100644 --- a/metplus/util/diff_util.py +++ b/metplus/util/diff_util.py @@ -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'): diff --git a/metplus/util/string_manip.py b/metplus/util/string_manip.py index af1d719016..c0d1042f7f 100644 --- a/metplus/util/string_manip.py +++ b/metplus/util/string_manip.py @@ -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) diff --git a/metplus/wrappers/command_builder.py b/metplus/wrappers/command_builder.py index bec31ba318..05b66f89bb 100755 --- a/metplus/wrappers/command_builder.py +++ b/metplus/wrappers/command_builder.py @@ -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: