def test_update_tag(self): old_tag = "!tagged" new_tag = "!changed" old_node = ry.scalarstring.PlainScalarString("tagged value") tagged_node = ry.comments.TaggedScalar(old_node, tag=old_tag) new_node = Nodes.apply_yaml_tag(tagged_node, new_tag) assert new_node.tag.value == new_tag assert new_node.value == old_node
def test_delete_tag(self): old_tag = "!tagged" new_tag = "" old_node = ry.scalarstring.PlainScalarString("tagged value") tagged_node = ry.comments.TaggedScalar(old_node, tag=old_tag) new_node = Nodes.apply_yaml_tag(tagged_node, new_tag) assert not hasattr(new_node, "tag") assert new_node == old_node
def _tag_nodes(document, tag, nodes): """Assign a data-type tag to a set of nodes.""" for node_coord in nodes: old_node = node_coord.node if node_coord.parent is None: node_coord.node.yaml_set_tag(tag) else: node_coord.parent[node_coord.parentref] = Nodes.apply_yaml_tag( node_coord.node, tag) if Anchors.get_node_anchor(old_node) is not None: Anchors.replace_anchor(document, old_node, node_coord.parent[node_coord.parentref])
def test_tag_map(self): new_tag = "!something" old_node = ry.comments.CommentedMap({"key": "value"}) new_node = Nodes.apply_yaml_tag(old_node, new_tag) assert new_node.tag.value == new_tag