def test_detach_node_retain_child_nodes(): root = Document( "<root><node><child/>childish<!-- [~.ö] --></node></root>").root node = root.first_child node.detach(retain_child_nodes=True) assert len(node) == 0 assert str(root) == "<root><child/>childish<!-- [~.ö] --></root>" child = root.first_child child.detach(retain_child_nodes=True) assert str(root) == "<root>childish<!-- [~.ö] --></root>" with pytest.raises(InvalidOperation): root.detach(retain_child_nodes=True)
def test_detach_sustains_attributes(): node = Document("<root xmlns='https://default.ns'><node foo='bar'/></root>" ).root.first_child assert node._etree_obj is node.attributes._element node.detach() assert node._etree_obj is node.attributes._element