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})
def test_malformed_use(): test = """ .def foo: bar .use (foo): "" """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
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})
def test_unmergeable_if_scalars(): test = """ .if(x): 1 .if (x): 2 """ with pytest.raises(YATLSyntaxError): check(test, "", {"x": True}, {})
def test_def_with_extra_args_in_list(): test = """ .def foo(x): {} .use foo: [1, 2] """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
def test_def_with_missing_args_in_obj(): test = """ .def foo(x): {} .use foo: {} """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
def test_unmergeable_fields_after_if(): test = """ .if (x): 1 foo: 2 """ with pytest.raises(YATLSyntaxError): check(test, "", {"x": True}, {})
def test_elif_before_if(): test = """ .elif (x): a .if (x): b """ with pytest.raises(YATLSyntaxError): check(test, "", {"x": True}, {})
def test_for_cannot_merge(): test = """ foo: bar .for (x in xs): .(x) """ with pytest.raises(YATLSyntaxError): check(test, "", {"xs": []}, {})
def test_for_variable_disappears(): test = """ - .for (x in xs): .(x) - .(x) """ with pytest.raises(YATLEnvironmentError): check(test, "", {"xs": ["a", "b"]}, {})
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})
def test_def_that_returns_value_in_obj(): test = """ .def foo: bar a: b .use foo: "" """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
def test_def_with_wrong_arg(): test = """ .def foo(x): {} .use foo: y: bar """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
def test_zero_arg_def_with_something_truthy(): test = """ .def foo: key: val .use foo: blah """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
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, "", {}, {})
def test_interpolation_in_key(): test = """ .(foo): baz """ expected = """ bar: baz """ check(test, expected, {"foo": "bar"}, {})
def test_empty_for(): test = """ - .for (x in xs): .(x) """ expected = """ [] """ check(test, expected, {"xs": []}, {})
def test_two_interpolations(): test = """ .(foo) and .(bar) """ expected = """ abc and xyz """ check(test, expected, {"foo": "abc", "bar": "xyz"}, {})
def test_int_interpolation(): test = """ - .(foo) """ expected = """ - 1 """ check(test, expected, {"foo": 1}, {})
def test_interpolation_in_object(): test = """ foo: .(bar) """ expected = """ foo: baz """ check(test, expected, {"bar": "baz"}, {})
def test_interpolation_in_array(): test = """ - .(foo) """ expected = """ - bar """ check(test, expected, {"foo": "bar"}, {})
def test_interpolation_in_value(): test = """ .(foo) """ expected = """ bar """ check(test, expected, {"foo": "bar"}, {})
def test_unmergeable_if_list_and_dict(): test = """ .if(x): - b .if (x): foo: a """ with pytest.raises(YATLSyntaxError): check(test, "", {"x": True}, {})
def test_def_with_extra_args_in_obj(): test = """ .def foo(x): {} .use foo: x: foo y: bar """ with pytest.raises(YATLSyntaxError): check(test, "", {}, {})
def test_if_returns_list(): test = """ .if (x): - foo """ expected = """ - foo """ check(test, expected, {"x": True}, {})
def test_for_as_object(): test = """ .for (x in xs): .(x) """ expected = """ - a - b """ check(test, expected, {"xs": ["a", "b"]}, {})
def test_break_before_else(): test = """ .if (x): foo: 1 bar: 2 .else: baz: 3 """ with pytest.raises(YATLSyntaxError): check(test, "", {"x": True}, {})
def test_zero_arg_def_with_empty_list(): test = """ .def foo: key: val .use foo: [] """ expected = """ key: val """ check(test, expected, {}, {})
def redefine_def(): test = """ .def foo: first .def foo: second .use foo: [] """ expected = """ second """ check(test, expected, {}, {})
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, {}, {})