示例#1
0
def test_tc_pairs_storm_id_lists(metplus_config, config_overrides, storm_type,
                                 values_to_check):
    config = metplus_config()

    set_minimum_config_settings(config)

    config.set('config', 'INIT_TIME_FMT', '%Y')
    config.set('config', 'INIT_BEG', '2019')
    config.set('config', 'INIT_END', '2019')

    test_data_dir = os.path.join(config.getdir('METPLUS_BASE'),
                                 'internal_tests', 'data', 'tc_pairs')
    bdeck_dir = os.path.join(test_data_dir, 'bdeck')
    edeck_dir = os.path.join(test_data_dir, 'edeck')

    config.set('config', 'TC_PAIRS_BDECK_INPUT_DIR', bdeck_dir)
    config.set('config', 'TC_PAIRS_EDECK_INPUT_DIR', edeck_dir)
    config.set('config', 'TC_PAIRS_BDECK_TEMPLATE',
               'storm_id_b{basin?fmt=%s}{cyclone?fmt=%s}{date?fmt=%Y}.dat')
    config.set('config', 'TC_PAIRS_EDECK_TEMPLATE',
               'storm_id_e{basin?fmt=%s}{cyclone?fmt=%s}{date?fmt=%Y}.dat')

    # LOOP_ORDER processes runs once, times runs once per time
    config.set('config', 'LOOP_ORDER', 'processes')

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

    wrapper = TCPairsWrapper(config)
    assert wrapper.isOK

    all_cmds = wrapper.run_all_times()
    print(f"ALL COMMANDS:")
    for idx, (cmd, env_list) in enumerate(all_cmds):
        print(f"CMD{idx}: {cmd}")
        print(f"ENV{idx}: {env_list}")

    assert (len(all_cmds) == len(values_to_check))

    for (cmd, env_vars), value_to_check in zip(all_cmds, values_to_check):
        env_var_key = f'METPLUS_{storm_type.upper()}'

        match = next(
            (item for item in env_vars if item.startswith(env_var_key)), None)
        assert (match is not None)
        print(f"Checking env var: {env_var_key}")
        actual_value = match.split('=', 1)[1]
        expected_value = f'{storm_type} = ["{value_to_check}"];'

        assert actual_value == expected_value
示例#2
0
def test_tc_pairs_read_all_files(metplus_config, config_overrides,
                                 env_var_values):
    # run using init and valid time variables
    for loop_by in ['INIT', 'VALID']:
        config = metplus_config()

        set_minimum_config_settings(config, loop_by)

        test_data_dir = os.path.join(config.getdir('METPLUS_BASE'),
                                     'internal_tests', 'data', 'tc_pairs')
        bdeck_dir = os.path.join(test_data_dir, 'bdeck')
        adeck_dir = os.path.join(test_data_dir, 'adeck')

        config.set('config', 'TC_PAIRS_BDECK_INPUT_DIR', bdeck_dir)
        config.set('config', 'TC_PAIRS_ADECK_INPUT_DIR', adeck_dir)

        # LOOP_ORDER processes runs once, times runs once per time
        config.set('config', 'LOOP_ORDER', 'processes')

        config.set('config', 'TC_PAIRS_READ_ALL_FILES', True)
        config.set('config', 'TC_PAIRS_OUTPUT_TEMPLATE', '')

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

        env_var_values[f'METPLUS_{loop_by}_BEG'] = (
            f'{loop_by.lower()}_beg = "{run_times[0]}";')

        env_var_values[f'METPLUS_{loop_by}_END'] = (
            f'{loop_by.lower()}_end = "{run_times[-1]}";')

        wrapper = TCPairsWrapper(config)
        assert wrapper.isOK

        app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
        verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
        config_file = wrapper.c_dict.get('CONFIG_FILE')
        out_dir = wrapper.c_dict.get('OUTPUT_DIR')
        expected_cmds = [
            (f"{app_path} {verbosity} "
             f"-bdeck {bdeck_dir} "
             f"-adeck {adeck_dir} "
             f"-config {config_file} "
             f"-out {out_dir}/tc_pairs"),
        ]

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

        for (cmd, env_vars), expected_cmd in zip(all_cmds, expected_cmds):
            # check that environment variables were set properly
            for env_var_key in wrapper.WRAPPER_ENV_VAR_KEYS:
                match = next(
                    (item
                     for item in env_vars if item.startswith(env_var_key)),
                    None)
                assert (match is not None)
                print(f'Checking env var: {env_var_key}')
                actual_value = match.split('=', 1)[1]
                assert (env_var_values.get(env_var_key, '') == actual_value)

        # unset begin and end for next loop
        del env_var_values[f'METPLUS_{loop_by}_BEG']
        del env_var_values[f'METPLUS_{loop_by}_END']