Ejemplo n.º 1
0
def test_config_not_defined(tmp_path):
    """Tests that each string variable is not written if not defined"""
    from configuration import render_server_cfg, render_basic_cfg, render_armaprofile

    def check_file(file_name, variable_names, test_var):
        """Check that the given variable names or test value doesn't exist in the given file"""
        with open(file_name, 'r') as f:
            text = f.read()
            for variable_name in variable_names:
                assert variable_name not in text, f'{variable_name} is defined!'
                assert test_var not in text, f'test value for {variable_name} still somehow defined!'

    all_global_variables = dict(
        CONFIG_STRING_ARRAY_VARIABLES, **CONFIG_BOOL_INT_VARIABLES,
        **CONFIG_NUMBER_OR_BOOL_ARRAY_VARIABLES,
        **CONFIG_STRING_ARRAY_VARIABLES, **BASIC_INT_VARIABLES,
        **BASIC_CLASS_INT_VARIABLES, **PROFILE_OPTIONS_VARIABLES,
        **PROFILE_VARIABLES, **PROFILES_CUSTOM_AI_LEVEL)

    for global_var in all_global_variables:
        if global_var in os.environ:
            del os.environ[global_var]

    render_server_cfg(tmp_path / PATH_CONFIG)
    render_basic_cfg(tmp_path / PATH_BASIC)
    render_armaprofile(tmp_path / PATH_PROFILE)

    for file_name in (tmp_path / PATH_CONFIG, tmp_path / PATH_BASIC,
                      tmp_path / PATH_PROFILE):
        check_file(file_name, all_global_variables.values(), 'test_var')
Ejemplo n.º 2
0
def test_profile_custom_difficulty(tmp_path):
    """Tests that the variable in the CustomDifficulty class in the profile file is written correctly."""
    from configuration import render_armaprofile

    test_value = '1'
    os.environ['PROFILE_AI_LEVEL_PRESET'] = test_value
    variable = PROFILE_VARIABLES['PROFILE_AI_LEVEL_PRESET']

    render_armaprofile(tmp_path / PATH_PROFILE)

    with open(tmp_path / PATH_PROFILE, 'r') as f:
        text = f.read()
        test_text = '};\n    %s = %s;\n    };' % (variable, test_value)
        assert test_text in text, f'{variable} not defined correctly!'
Ejemplo n.º 3
0
def test_profile_option_variables(tmp_path):
    """Tests that each variable for the Options class is written correctly to the profile file"""
    from configuration import render_armaprofile

    test_value = '1'
    global_variables = PROFILE_OPTIONS_VARIABLES
    for global_var in global_variables:
        os.environ[global_var] = test_value

    render_armaprofile(tmp_path / PATH_PROFILE)

    with open(tmp_path / PATH_PROFILE, 'r') as f:
        text = f.read()
        for variable in global_variables.values():
            assert f'{variable} = {test_value};' in text, f'{variable} not defined correctly!'
Ejemplo n.º 4
0
def test_profile_custom_ai_level(tmp_path):
    """Tests that the variables in the CustomAILevel class in the profile file is written correctly."""
    from configuration import render_armaprofile

    test_value = '0.5'
    os.environ['PROFILE_CUSTOM_AI_LEVEL_SKILL_AI'] = test_value
    variable1 = PROFILES_CUSTOM_AI_LEVEL['PROFILE_CUSTOM_AI_LEVEL_SKILL_AI']
    os.environ['PROFILE_CUSTOM_AI_LEVEL_PRECISION_AI'] = test_value
    variable2 = PROFILES_CUSTOM_AI_LEVEL[
        'PROFILE_CUSTOM_AI_LEVEL_PRECISION_AI']

    render_armaprofile(tmp_path / PATH_PROFILE)

    with open(tmp_path / PATH_PROFILE, 'r') as f:
        text = f.read()
        test_text = 'class CustomAILevel\n    {\n        %s = %s;\n        %s = %s;\n        };' % (
            variable1, test_value, variable2, test_value)
        assert test_text in text, 'CustomAILevel is not defined correctly!'
Ejemplo n.º 5
0
def launch(executable_path, mod_line, arguments, kw_arguments):
    """Run the Arma3 Server executable"""
    run_params = [executable_path]
    for param in arguments:
        run_params.append(f'-{param}')
    for key, value in kw_arguments.items():
        run_params.append(f'-{key}={value}')
    with open(PATH_MODLINES, 'r') as open_file:
        modlines = json.loads(open_file.read())
    print(f'Using mod line {mod_line}: {modlines[mod_line]}')
    for mod_dir in modlines[mod_line]:
        run_params.append(f'-mod={str(Path(PATH_MODS) / mod_dir)}')
    print(f'Launching with params {run_params}')
    run(run_params)

if __name__ == '__main__':
    render_server_cfg(PATH_SERVER_CFG)
    render_basic_cfg(PATH_BASIC_CFG)
    render_armaprofile(PATH_PROFILE)
    launch(
        executable_path='/arma3/arma3server',
        mod_line=os.environ['MODLINE'],
        arguments=('filePatching',),
        kw_arguments={
            'port': '2302',
            'name': 'server',
            'config': PATH_SERVER_CFG,
            'cfg': PATH_BASIC_CFG
        }
    )