diff --git a/unittests/test_macros.py b/unittests/test_macros.py index 5244307db8e694ffb4864380d33936ebb76ae715..9569e78554b2fa1e528e87c69cb5c0290a5039bc 100644 --- a/unittests/test_macros.py +++ b/unittests/test_macros.py @@ -257,6 +257,79 @@ testnode: assert dat["testnode"]["obl"]["replaced1"]["d"][1] == "25" +def test_macros_in_macros(register_macros, macro_store_reset): + """ + Test that macros can be used in macro definitions. + """ + cfood = _temp_file_load(""" +--- +metadata: + crawler-version: 0.3.1 + macros: + - !defmacro + name: one_macro + params: + a: 25 + definition: + macro_sub_$a: + b: $a + another_param: 3 + - !defmacro + name: test_macrodef + params: {} + definition: + macro_top: !macro + one_macro: + - a: 17 + - {} + - a: 98 + not_macro: + a: 26 +--- +extroot: !macro + test_macrodef: + """) + + assert "test_macro" not in cfood["extroot"] + assert cfood["extroot"]["macro_top"]["not_macro"]["a"] == 26 + d = cfood["extroot"]["macro_top"] + assert d["macro_sub_17"]["b"] == "17" + assert d["macro_sub_17"]["another_param"] == 3 + assert d["macro_sub_25"]["b"] == "25" + assert d["macro_sub_25"]["another_param"] == 3 + assert d["macro_sub_98"]["b"] == "98" + assert d["macro_sub_98"]["another_param"] == 3 + + +def test_silent_overwrite(register_macros, macro_store_reset): + cfood = _temp_file_load(""" +--- +metadata: + crawler-version: 0.3.1 + macros: + - !defmacro + name: one_macro + params: + a: 25 + definition: + macro_sub: + b: $a + another_param: 3 + - !defmacro + name: test_macrodef + params: {} + definition: + macro_top: !macro + one_macro: + - a: 17 + - a: 98 +--- +extroot: !macro + test_macrodef: + """) + + assert len(cfood["extroot"]["macro_top"]) == 2 + def test_circular_macro_definition(register_macros, macro_store_reset): """Test the (ab-)use of macros to create an infinite loop.""" cfood = _temp_file_load("""