def test_seq_attribute_to_map(class_node: yatiml.Node, class_node_dup_key: yatiml.Node) -> None: assert class_node.has_attribute('list1') assert class_node.get_attribute('list1').is_sequence() class_node.seq_attribute_to_map('list1', 'item_id', 'price') assert class_node.has_attribute_type('list1', dict) attr_node = class_node.get_attribute('list1') assert attr_node.is_mapping() assert attr_node.has_attribute_type('item1', float) item1_node = attr_node.get_attribute('item1') assert item1_node.get_value() == 100.0 assert attr_node.has_attribute_type('item2', dict) item2_node = attr_node.get_attribute('item2') assert not item2_node.has_attribute('item_id') assert item2_node.has_attribute('price') assert item2_node.has_attribute('on_sale') # check that it fails silently if the attribute is missing or not a list class_node.seq_attribute_to_map('non_existent_attribute', 'item_id') class_node.seq_attribute_to_map('attr1', 'item_id') # check that it raises with strict=True and duplicate keys with pytest.raises(yatiml.SeasoningError): class_node_dup_key.seq_attribute_to_map('dup_list', 'item_id', strict=True)
def _yatiml_sweeten(cls, node: yatiml.Node) -> None: node.seq_attribute_to_map('components', 'name', 'implementation') if len(node.get_attribute('conduits').seq_items()) == 0: node.remove_attribute('conduits') node.seq_attribute_to_map('conduits', 'sender', 'receiver')