def test_resolve_env_variable_fails():
    """Test the case when resolving the environment variable fails."""
    with pytest.raises(
        ValueError, match="Cannot resolve environment variable 'some:wrong:variable'."
    ):
        wrong_var = "some:wrong:variable"
        yaml_file = dedent(
            f"""
            some_variable_name: ${{{wrong_var}}}
            """
        )
        stream = io.StringIO(yaml_file)
        yaml_load(stream)
Exemple #2
0
def test_yaml_dump_load():
    """Test yaml dump/load works."""
    data = OrderedDict({"a": 12, "b": None})
    stream = io.StringIO()
    yaml_dump(data, stream)
    stream.seek(0)
    loaded_data = yaml_load(stream)
    assert loaded_data == data
def test_resolve_env_variable_without_default_negative():
    """Test that the AEAYamlLoader resolves unspecified env variable without default correctly."""
    random_variable_name = _generate_random_string()
    variable_key = "my_variable"
    yaml_file = dedent(
        f"""
    {variable_key}: ${{{random_variable_name}}}
    """
    )
    stream = io.StringIO(yaml_file)
    yaml_obj = yaml_load(stream)
    assert yaml_obj[variable_key] == ""
Exemple #4
0
    def get_component_config_value(self) -> dict:
        """Get component variable value."""
        package_type, package_name, *path = self.PATH.split(".")
        file_path = Path(
            f"{package_type}") / package_name / f"{package_type[:-1]}.yaml"

        with open(file_path, "r") as fp:
            data = yaml_load(fp)

        value = data
        for i in path:
            value = value[i]
        return value
def test_resolve_env_variable_with_default():
    """Test that the AEAYamlLoader resolves env default variable correctly."""
    random_variable_name = _generate_random_string()
    variable_value = "my_variable_default"
    variable_key = "my_variable"
    yaml_file = dedent(
        f"""
    {variable_key}: ${{{random_variable_name}:{variable_value}}}
    """
    )
    stream = io.StringIO(yaml_file)
    yaml_obj = yaml_load(stream)
    assert yaml_obj[variable_key] == variable_value
def test_resolve_env_variable_without_default_positive():
    """Test that the AEAYamlLoader resolves env variable without default correctly."""
    random_variable_name = _generate_random_string()
    variable_value = "my_value"
    variable_key = "my_variable"
    os.environ[random_variable_name] = variable_value
    try:
        yaml_file = dedent(
            f"""
        {variable_key}: ${{{random_variable_name}}}
        """
        )
        stream = io.StringIO(yaml_file)
        yaml_obj = yaml_load(stream)
    finally:
        os.environ.pop(random_variable_name)
    assert yaml_obj[variable_key] == variable_value
Exemple #7
0
 def _load_component_config(self, file_pointer: TextIO) -> T:
     """Load a component configuration."""
     configuration_file_json = yaml_load(file_pointer)
     return self._load_from_json(configuration_file_json)