Esempio n. 1
0
def test_defaults_updating_defaults():
    test = """
        outer:
            .load_defaults_from: file1
            inner:
                test-0: test winner
                .load_defaults_from: file2
    """
    file1 = """
        inner:
            test-1: file1 loser
            .load_defaults_from: file3
    """
    file2 = """
        test-1: file2 winner
        test-2: file2 winner
    """
    file3 = """
        test-1: file3 loser
        test-2: file3 loser
        test-3: file3 only
    """
    expected = """
        outer:
            inner:
                test-0: test winner
                test-1: file2 winner
                test-2: file2 winner
                test-3: file3 only
    """
    check(test, expected, {}, {"file1": file1, "file2": file2, "file3": file3})
Esempio n. 2
0
def test_malformed_use():
    test = """
        .def foo: bar
        .use (foo): ""
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 3
0
def test_nested_update():
    test = """
        outer:
            .load_defaults_from: file1
            outer-one: 1
            inner:
                inner-one: 1
                inner-two: 2
    """
    file1 = """
        outer-two: 2
        inner:
            inner-two: will update
            inner-three: 3
    """
    expected = """
        outer:
            outer-one: 1
            outer-two: 2
            inner:
                inner-one: 1
                inner-two: 2
                inner-three: 3
    """
    check(test, expected, {}, {"file1": file1})
Esempio n. 4
0
def test_unmergeable_if_scalars():
    test = """
        .if(x): 1
        .if (x): 2
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {"x": True}, {})
Esempio n. 5
0
def test_def_with_extra_args_in_list():
    test = """
        .def foo(x): {}
        .use foo: [1, 2]
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 6
0
def test_def_with_missing_args_in_obj():
    test = """
        .def foo(x): {}
        .use foo: {}
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 7
0
def test_unmergeable_fields_after_if():
    test = """
        .if (x): 1
        foo: 2
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {"x": True}, {})
Esempio n. 8
0
def test_elif_before_if():
    test = """
        .elif (x): a
        .if (x): b
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {"x": True}, {})
Esempio n. 9
0
def test_for_cannot_merge():
    test = """
        foo: bar
        .for (x in xs): .(x)
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {"xs": []}, {})
Esempio n. 10
0
def test_for_variable_disappears():
    test = """
        - .for (x in xs): .(x)
        - .(x)
    """
    with pytest.raises(YATLEnvironmentError):
        check(test, "", {"xs": ["a", "b"]}, {})
Esempio n. 11
0
def test_nested_load_defaults_from():
    test = """
        top:
            .load_defaults_from: file1
            test-0: test winner
            test-3: test winner
    """
    file1 = """
        .load_defaults_from: file2
        test-0: file1 loser
        test-1: file1 winner
    """
    file2 = """
        test-0: file2 loser
        test-1: file2 loser
        test-2: file2 winner
        test-3: file2 loser
    """
    expected = """
        top:
            test-0: test winner
            test-1: file1 winner
            test-2: file2 winner
            test-3: test winner
    """
    check(test, expected, {}, {"file1": file1, "file2": file2})
Esempio n. 12
0
def test_def_that_returns_value_in_obj():
    test = """
        .def foo: bar
        a: b
        .use foo: ""
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 13
0
def test_def_with_wrong_arg():
    test = """
        .def foo(x): {}
        .use foo:
            y: bar
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 14
0
def test_zero_arg_def_with_something_truthy():
    test = """
        .def foo:
            key: val
        .use foo: blah
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 15
0
def test_two_arg_def_passed_as_value():
    test = """
        .def foo(k, v):
            .(k): .(v)
        .use foo: oops error
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 16
0
def test_interpolation_in_key():
    test = """
        .(foo): baz
    """
    expected = """
        bar: baz
    """
    check(test, expected, {"foo": "bar"}, {})
Esempio n. 17
0
def test_empty_for():
    test = """
        - .for (x in xs): .(x)
    """
    expected = """
        []
    """
    check(test, expected, {"xs": []}, {})
Esempio n. 18
0
def test_two_interpolations():
    test = """
        .(foo) and .(bar)
    """
    expected = """
        abc and xyz
    """
    check(test, expected, {"foo": "abc", "bar": "xyz"}, {})
Esempio n. 19
0
def test_int_interpolation():
    test = """
        - .(foo)
    """
    expected = """
        - 1
    """
    check(test, expected, {"foo": 1}, {})
Esempio n. 20
0
def test_interpolation_in_object():
    test = """
        foo: .(bar)
    """
    expected = """
        foo: baz
    """
    check(test, expected, {"bar": "baz"}, {})
Esempio n. 21
0
def test_interpolation_in_array():
    test = """
        - .(foo)
    """
    expected = """
        - bar
    """
    check(test, expected, {"foo": "bar"}, {})
Esempio n. 22
0
def test_interpolation_in_value():
    test = """
        .(foo)
    """
    expected = """
        bar
    """
    check(test, expected, {"foo": "bar"}, {})
Esempio n. 23
0
def test_unmergeable_if_list_and_dict():
    test = """
        .if(x):
            - b
        .if (x):
            foo: a
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {"x": True}, {})
Esempio n. 24
0
def test_def_with_extra_args_in_obj():
    test = """
        .def foo(x): {}
        .use foo:
            x: foo
            y: bar
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {}, {})
Esempio n. 25
0
def test_if_returns_list():
    test = """
        .if (x):
            - foo
    """
    expected = """
        - foo
    """
    check(test, expected, {"x": True}, {})
Esempio n. 26
0
def test_for_as_object():
    test = """
        .for (x in xs): .(x)
    """
    expected = """
        - a
        - b
    """
    check(test, expected, {"xs": ["a", "b"]}, {})
Esempio n. 27
0
def test_break_before_else():
    test = """
        .if (x):
            foo: 1
        bar: 2
        .else:
            baz: 3
    """
    with pytest.raises(YATLSyntaxError):
        check(test, "", {"x": True}, {})
Esempio n. 28
0
def test_zero_arg_def_with_empty_list():
    test = """
        .def foo:
            key: val
        .use foo: []
    """
    expected = """
        key: val
    """
    check(test, expected, {}, {})
Esempio n. 29
0
def redefine_def():
    test = """
        .def foo: first
        .def foo: second
        .use foo: []
    """
    expected = """
        second
    """
    check(test, expected, {}, {})
Esempio n. 30
0
def test_one_arg_def_passed_as_value():
    test = """
        .def foo(x):
            .(x)-key: .(x)-value
        .use foo: bar
    """
    expected = """
        bar-key: bar-value
    """
    check(test, expected, {}, {})