Example #1
0
def test_graphml():
    with open('../data/karate.graphml') as file:
        text = file.read()
    G = decode(text, 'graphml')
    new_text = encode(G, 'graphml')
    H = decode(text, 'graphml')
    assert G.nodes == H.nodes
    assert G.edges == H.edges
    assert G.graph_attr == H.graph_attr
    assert G.edge_attr == H.edge_attr
    assert G.node_attr == G.node_attr
Example #2
0
def test_edgelist(delimiter=' '):
    """Test the decoders.decode_edgelist function."""
    # Create test data
    data_text = 'a b\nb c\nc a\n'

    # Obtain data repr
    data_repr = repr({}) + '\n'
    data_repr += repr(['label']) + '\n'
    data_repr += repr([('a', ), ('b', ), ('c', )]) + '\n'
    data_repr += repr(['node1', 'node2']) + '\n'
    data_repr += repr([((0, 1), ), ((1, 2), ), ((2, 0), )])

    # Decode the data text
    graph = decode(data_text, 'edgelist', delimiter)
    assert repr(graph) == data_repr
Example #3
0
def test_graphml():
    """Test the decoders.decode_graphml function."""
    # Load test data
    with open('../data/test_data_graphml.graphml', 'r') as _file:
        data_text = _file.read()

    # Obtain data repr
    data_repr = repr({'directed': False}) + '\n'
    data_repr += repr(['label']) + '\n'
    data_repr += repr([('a', ), ('b', ), ('c', )]) + '\n'
    data_repr += repr(['edge']) + '\n'
    data_repr += repr([((0, 1), ), ((0, 2), ), ((1, 2), )])

    # Decode the data text
    graph = decode(data_text, 'graphml')
    assert repr(graph) == data_repr
Example #4
0
def test_graphml():
    with open('../data/karate.gml') as file:
        text = file.read()
    assert text == encode(decode(text, 'graphml'), 'graphml')
Example #5
0
def test_edgelist_no_attr():
    with open('../data/karate_no_attr.txt') as file:
        text = file.read()
    assert text == encode(decode(text, 'edgelist', attr=False),
                          'edgelist',
                          attr=False)
Example #6
0
def test_edgelist():
    with open('../data/karate.txt') as file:
        text = file.read()
    assert text == encode(decode(text, 'edgelist', attr=True),
                          'edgelist',
                          attr=True)