def test_perform_any_config_fragment_substitution_bad(): config_str = """ { {% include "does/not/exist" %} "implementation_config": { } } """ with pytest.raises(Exception) as e: Configuration.perform_any_config_fragment_substitution(config_str) assert "Substitution files do not exist: does/not/exist" in str(e)
def test_yaml_perform_any_config_fragment_substitution_env_var(monkeypatch): monkeypatch.setenv("TEST","foo") config_str = """ {% include "test/metadata_fragment.yml" %} implementation_config: {% include "test/read_write_fragment.yml" %} """ final_str = Configuration.perform_any_config_fragment_substitution(config_str) expected = """ metadata: test: foo implementation_config: reader_config: read_data: class: CsvReader destinations: - write_output filename: data/tennis.csv writer_config: write_output: class: CsvWriter dir: cache filename: tennis_output.csv key: data """ assert final_str == expected
def test_perform_any_config_fragment_substitution_env_var(monkeypatch): monkeypatch.setenv("TEST","foo") config_str = """ { {% include "test/metadata_fragment.json" %} "implementation_config": { {% include "test/read_write_fragment.json" %} } } """ final_str = Configuration.perform_any_config_fragment_substitution(config_str) expected = """ { "metadata":{ "test": "foo" }, "implementation_config": { "reader_config": { "read_data": { "class": "CsvReader", "filename": "data/tennis.csv", "destinations": [ "write_output" ] } }, "writer_config": { "write_output": { "class": "CsvWriter", "key": "data", "dir": "cache", "filename": "tennis_output.csv" } } } } """ assert json.loads(final_str) == json.loads(expected)