Beispiel #1
0
def test_node_to_dict_with_no_children(node):
    """Test `node_to_dict` with no child nodes."""
    d = xml_to_dict.node_to_dict(node)

    assert d['tag'] == 'TAG'
    assert d['text'] == 'TEXT'
    assert len(d['attrs'].keys()) == 0
    assert 'children' not in d
Beispiel #2
0
def test_node_to_dict_with_children(parent):
    """Test `node_to_dict` with child nodes."""
    d = xml_to_dict.node_to_dict(parent)

    assert d['tag'] == 'PARENT'
    assert len(d['children'])
    for child in d['children']:
        assert child['tag'] in ['CHILD1', 'CHILD2']
    assert len(d['attrs'].keys()) == 0
    assert 'text' not in d
Beispiel #3
0
def test_get_children_no_match(parent):
    """Test `get_children` when there are no matching children."""
    cs = xml_to_dict.get_children(xml_to_dict.node_to_dict(parent), 'CHILD')

    assert len(list(cs)) == 0
Beispiel #4
0
def test_get_children(parent):
    """Test `get_children`."""
    cs = xml_to_dict.get_children(xml_to_dict.node_to_dict(parent), 'CHILD1')

    for c in cs:
        assert c['tag'] == 'CHILD1'
Beispiel #5
0
def test_get_child_no_match(parent):
    """Test `get_child` when there's no matching child."""
    c = xml_to_dict.get_child(xml_to_dict.node_to_dict(parent), 'CHILD')

    assert c is None
Beispiel #6
0
def test_get_child(parent):
    """Test `get_child`."""
    c = xml_to_dict.get_child(xml_to_dict.node_to_dict(parent), 'CHILD1')

    assert c['tag'] == 'CHILD1'
    assert c['text'] == 'TEXT1'