Exemplo n.º 1
0
 def test_returns_unmodified_if_no_variable_references(self):
     config = {
         collections.CompoundKey(["a", "b"]): "foo",
         collections.CompoundKey(["a"]): "bar",
     }
     replaced = replace_variable_references(config)
     assert config == replaced
Exemplo n.º 2
0
    def test_replaces_root_variable(self):
        config = {
            collections.CompoundKey(["a"]): "${b}",
            collections.CompoundKey(["b"]): "foo",
        }
        replaced = replace_variable_references(config)

        assert (replaced[collections.CompoundKey(
            ["a"])] == replaced[collections.CompoundKey(["b"])])
Exemplo n.º 3
0
 def test_chained_variables(self):
     config = {
         collections.CompoundKey(["a"]): "${b}",
         collections.CompoundKey(["b"]): "${c}",
         collections.CompoundKey(["c"]): "bar",
     }
     replaced = replace_variable_references(config)
     for value in replaced.values():
         assert value == "bar"
Exemplo n.º 4
0
    def test_replaces_from_root_to_nested_keys(self):
        config = {
            collections.CompoundKey(["a"]): "${a.b}",
            collections.CompoundKey(["a", "b"]): "foo",
        }
        replaced = replace_variable_references(config)

        assert (replaced[collections.CompoundKey(
            ["a"])] == replaced[collections.CompoundKey(["a", "b"])])
Exemplo n.º 5
0
 def test_replaces_multiple_existing_variables(self):
     config = {
         collections.CompoundKey(["a"]): "${b}",
         collections.CompoundKey(["b"]): "foo",
         collections.CompoundKey(["c"]): "bar",
         collections.CompoundKey(["d"]): "${c}",
     }
     replaced = replace_variable_references(config)
     assert (replaced[collections.CompoundKey(
         ["a"])] == replaced[collections.CompoundKey(["b"])])
     assert (replaced[collections.CompoundKey(
         ["c"])] == replaced[collections.CompoundKey(["d"])])
Exemplo n.º 6
0
    def test_array_replacement_nested_variable(self):
        config = {
            collections.CompoundKey(["a", "c"]): "foo",
            collections.CompoundKey(["b"]): ["${a.c}", "${a.c}", "${a.c}"],
        }

        replaced = replace_variable_references(config)
        assert replaced[collections.CompoundKey(["b"])] == [
            replaced[collections.CompoundKey(["a", "c"])],
            replaced[collections.CompoundKey(["a", "c"])],
            replaced[collections.CompoundKey(["a", "c"])],
        ]
Exemplo n.º 7
0
    def test_variable_reference_from_array(self):
        config = {
            collections.CompoundKey(["a"]): "foo",
            collections.CompoundKey(["b"]): ["${a}", "${a}", "${a}"],
        }

        replaced = replace_variable_references(config)
        assert replaced[collections.CompoundKey(["b"])] == [
            replaced[collections.CompoundKey(["a"])],
            replaced[collections.CompoundKey(["a"])],
            replaced[collections.CompoundKey(["a"])],
        ]
Exemplo n.º 8
0
 def test_bad_reference_returns_empty_string(self):
     config = {
         collections.CompoundKey(["a"]): "${b}",
         collections.CompoundKey(["c"]): "bar",
         collections.CompoundKey(["d"]): "${c}",
     }
     replaced = replace_variable_references(config)
     assert replaced[collections.CompoundKey(["a"])] == ""
     # not modifying the other, valid entries
     assert replaced[collections.CompoundKey(["c"])] == "bar"
     assert (replaced[collections.CompoundKey(
         ["d"])] == replaced[collections.CompoundKey(["c"])])
Exemplo n.º 9
0
    def test_doesnt_modify_input(self):
        config = {
            collections.CompoundKey(["a", "b"]): "foo",
            collections.CompoundKey(["a"]): "${a.b}",
        }
        before_config = {
            collections.CompoundKey(["a", "b"]): "foo",
            collections.CompoundKey(["a"]): "${a.b}",
        }
        replaced = replace_variable_references(config)

        assert config == before_config
        assert config != replaced
Exemplo n.º 10
0
 def test_single_key_multiple_variables(self):
     same_values = "${b}-${b}"
     different_values = "${b}-${c}"
     config = {
         collections.CompoundKey(["a"]): same_values,
         collections.CompoundKey(["d"]): different_values,
         collections.CompoundKey(["b"]): "foo",
         collections.CompoundKey(["c"]): "bar",
     }
     replaced = replace_variable_references(config)
     assert replaced[collections.CompoundKey(
         ["a"])] == "{val}-{val}".format(
             val=replaced[collections.CompoundKey(["b"])])
     assert replaced[collections.CompoundKey(["d"])] == "{b}-{c}".format(
         b=replaced[collections.CompoundKey(["b"])],
         c=replaced[collections.CompoundKey(["c"])],
     )
Exemplo n.º 11
0
 def test_self_reference_doesnt_cause_recursion_error(self):
     config = {
         collections.CompoundKey(["a"]): "${a}",
     }
     replaced = replace_variable_references(config)
     assert config == replaced