コード例 #1
0
ファイル: test_tag_node.py プロジェクト: funkyfuture/delb
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)
コード例 #2
0
ファイル: test_attributes.py プロジェクト: funkyfuture/delb
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