diff --git a/unittests/test_yaml_model_parser.py b/unittests/test_yaml_model_parser.py index 1019a93a0aa4292cea75fe8fba57e19e55359baa..c66fef131f34e33c19335f5fd1e5858dec4b3e24 100644 --- a/unittests/test_yaml_model_parser.py +++ b/unittests/test_yaml_model_parser.py @@ -597,3 +597,50 @@ prop2: model = parse_model_from_string(model_string) prop2 = model["prop2"] assert prop2.role == "Property" + + +def test_fancy_yaml(): + """Testing aliases and other fancy YAML features.""" + # Simple aliasing + model_string = """ +foo: + datatype: INTEGER +RT1: + obligatory_properties: &RT1_oblig + foo: +RT2: + obligatory_properties: *RT1_oblig + """ + model = parse_model_from_string(model_string) + assert str(model) == """{'foo': <Property name="foo" datatype="INTEGER"/> +, 'RT1': <RecordType name="RT1"> + <Property name="foo" importance="OBLIGATORY" flag="inheritance:FIX"/> +</RecordType> +, 'RT2': <RecordType name="RT2"> + <Property name="foo" importance="OBLIGATORY" flag="inheritance:FIX"/> +</RecordType> +}""" + + # Aliasing with override + model_string = """ +foo: + datatype: INTEGER +RT1: + obligatory_properties: &RT1_oblig + foo: +RT2: + obligatory_properties: + <<: *RT1_oblig + bar: + """ + model = parse_model_from_string(model_string) + assert str(model) == """{'foo': <Property name="foo" datatype="INTEGER"/> +, 'RT1': <RecordType name="RT1"> + <Property name="foo" importance="OBLIGATORY" flag="inheritance:FIX"/> +</RecordType> +, 'RT2': <RecordType name="RT2"> + <Property name="foo" importance="OBLIGATORY" flag="inheritance:FIX"/> + <Property name="bar" importance="OBLIGATORY" flag="inheritance:FIX"/> +</RecordType> +, 'bar': <RecordType name="bar"/> +}"""