Exemplo n.º 1
0
def test_expand_variables_in_dict():

    to_expand = {"a": "abc", "b": "expanded_{foo}", "c": "{foo2}_expanded"}

    obtained = expand_variables(to_expand, {"foo": "bar", "foo2": "bar2"})

    assert obtained["a"] == "abc"
    assert obtained["b"] == "expanded_bar"
    assert obtained["c"] == "bar2_expanded"
Exemplo n.º 2
0
def test_expand_variables_in_list():

    to_expand = ["abc", "expanded_{foo}", "{foo2}_expanded"]

    obtained = expand_variables(to_expand, {"foo": "bar", "foo2": "bar2"})

    assert obtained[0] == "abc"
    assert obtained[1] == "expanded_bar"
    assert obtained[2] == "bar2_expanded"
Exemplo n.º 3
0
def test_expand_variables_in_list_with_subdict():

    to_expand = ["abc", "expanded_{foo}", "{foo2[a]}_expanded"]

    obtained = expand_variables(to_expand, {
        "foo": "bar",
        "foo2": {
            "a": "subdir"
        }
    })

    assert obtained[0] == "abc"
    assert obtained[1] == "expanded_bar"
    assert obtained[2] == "subdir_expanded"
Exemplo n.º 4
0
def test_expand_variables_in_str_with_subdir():
    context = {"d": {"a": "_insubdict_"}}
    obtained = expand_variables("a{d[a]}c", context)

    assert "a_insubdict_c" == obtained
Exemplo n.º 5
0
def test_expand_variables_in_str():
    assert "abc" == expand_variables("a{v}c", {"v": "b"})
    assert "foo" == expand_variables("{bar}", {"bar": "foo"})