Skip to content
Snippets Groups Projects
Commit 8f1ecaf1 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST: added more tests for macro replacement

parent 19119beb
No related branches found
No related tags found
2 merge requests!123REL: Release v0.6.0,!121A few more tests for macro replacment
Pipeline #37494 failed
...@@ -257,6 +257,79 @@ testnode: ...@@ -257,6 +257,79 @@ testnode:
assert dat["testnode"]["obl"]["replaced1"]["d"][1] == "25" 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): def test_circular_macro_definition(register_macros, macro_store_reset):
"""Test the (ab-)use of macros to create an infinite loop.""" """Test the (ab-)use of macros to create an infinite loop."""
cfood = _temp_file_load(""" cfood = _temp_file_load("""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment