Exemple #1
0
def test_set_env_from_file(config_instance):
    config_instance.args = {'env_file': '.env'}
    contents = {'foo': 'bar', 'BAZ': 'zzyzx'}
    env_file = config_instance.args.get('env_file')
    util.write_file(env_file, util.safe_dump(contents))
    env = config.set_env_from_file({}, env_file)

    assert contents == env
Exemple #2
0
def test_set_env_from_file(config_instance):
    config_instance.args = {"env_file": ".env"}
    contents = {"foo": "bar", "BAZ": "zzyzx"}
    env_file = config_instance.args.get("env_file")
    util.write_file(env_file, util.safe_dump(contents))
    env = config.set_env_from_file({}, env_file)

    assert contents == env
Exemple #3
0
def from_yaml(data):
    """
    Interpolate the provided data and return a dict.

    Currently, this is used to reinterpolate the `molecule.yml` inside an
    Ansible playbook.  If there were any interpolation errors, they would
    have been found and raised earlier.

    :return: dict
    """
    molecule_env_file = os.environ['MOLECULE_ENV_FILE']

    env = os.environ.copy()
    env = config.set_env_from_file(env, molecule_env_file)

    i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Exemple #4
0
def test_set_env_from_file_returns_original_env_when_env_file_not_found(
    config_instance,
):
    env = config.set_env_from_file({}, "file-not-found")

    assert {} == env