def test_add_met_config_dict_nested(metplus_config): dict_name = 'outer' beg = -3 end = 5 sub_dict_name = 'inner' sub_dict_value1 = 'value1' sub_dict_value2 = 'value2' expected_value = ( f'{dict_name} = {{beg = {beg};end = {end};{sub_dict_name} = ' f'{{var1 = {sub_dict_value1};var2 = {sub_dict_value2};}}}}') config = metplus_config() config.set('config', 'APP_OUTER_BEG', beg) config.set('config', 'APP_OUTER_END', end) config.set('config', 'APP_OUTER_INNER_VAR1', sub_dict_value1) config.set('config', 'APP_OUTER_INNER_VAR2', sub_dict_value2) cbw = CommandBuilder(config) cbw.app_name = 'app' items = { 'beg': 'int', 'end': 'int', 'inner': ('dict', None, { 'var1': ('string', 'remove_quotes', None), 'var2': ('string', 'remove_quotes', None), }), } 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
def test_handle_regrid_new(metplus_config, config_overrides, expected_output): config = metplus_config() # set config values for key, value in config_overrides.items(): config.set('config', key, value) cbw = CommandBuilder(config) # set app_name to grid_stat for testing cbw.app_name = 'app' cbw.handle_regrid(cbw.c_dict) assert cbw.env_var_dict['METPLUS_REGRID_DICT'] == expected_output
def test_handle_description(metplus_config, config_overrides, expected_value): config = metplus_config() # set config values for key, value in config_overrides.items(): config.set('config', key, value) cbw = CommandBuilder(config) # set app_name to grid_stat for testing cbw.app_name = 'grid_stat' cbw.handle_description() assert cbw.env_var_dict.get('METPLUS_DESC', '') == expected_value
def test_add_met_config_window(metplus_config): dict_name = 'fcst_hr_window' beg = -3 end = 5 expected_value = f'{dict_name} = {{beg = -3;end = 5;}}' config = metplus_config() config.set('config', 'TC_GEN_FCST_HR_WINDOW_BEG', beg) config.set('config', 'TC_GEN_FCST_HR_WINDOW_END', end) cbw = CommandBuilder(config) cbw.app_name = 'tc_gen' cbw.add_met_config_window(dict_name) print(f"env_var_dict: {cbw.env_var_dict}") actual_value = cbw.env_var_dict.get('METPLUS_FCST_HR_WINDOW_DICT') assert actual_value == expected_value
def test_handle_regrid_old(metplus_config, config_overrides, set_to_grid, expected_dict): config = metplus_config() # set config values for key, value in config_overrides.items(): config.set('config', key, value) cbw = CommandBuilder(config) # set app_name to grid_stat for testing cbw.app_name = 'app' # create empty dictionary for testing c_dict = {} cbw.handle_regrid(c_dict, set_to_grid=set_to_grid) assert len(c_dict) == len(expected_dict) for key, value in expected_dict.items(): assert c_dict.get(key, '') == value
def test_read_climo_file_name(metplus_config, config_overrides, expected_value): # name of app used for testing to read/set config variables app_name = 'grid_stat' # check mean and stdev climo variables for climo_type in CommandBuilder.climo_types: prefix = f'{app_name.upper()}_CLIMO_{climo_type.upper()}_' config = metplus_config() # set config values for key, value in config_overrides.items(): config.set('config', f'{prefix}{key}', value) cbw = CommandBuilder(config) # set app_name to grid_stat for testing cbw.app_name = app_name cbw.read_climo_file_name(climo_type) actual_value = cbw.config.getraw('config', f'{prefix}FILE_NAME', '') assert actual_value == expected_value