Esempio n. 1
0
def test_edgelist():
    """Test the encoders.encode_edgelist function."""
    graph = GraphData()
    graph.nodes = [('a',), ('b',), ('c',)]
    graph.edges = [((0, 1), 1), ((1, 2), 2), ((2, 0), 1)]

    with_attr = 'a b 1\nb c 2\nc a 1\n'
    assert with_attr == encode(graph, 'edgelist', attr=True)

    no_attr = 'a b\nb c\nc a\n'
    assert no_attr == encode(graph, 'edgelist', attr=False)
Esempio n. 2
0
def test_edgelist_header():
    """Test the encoders.encode_edgelist function."""
    graph = GraphData()
    graph.nodes = [('a',), ('b',), ('c',)]
    graph.edges = [((0, 1), 1), ((1, 2), 2), ((2, 0), 1)]
    graph.edge_attr = ['node1', 'node2', 'weight']

    with_data = 'node1 node2 weight\na b 1\nb c 2\nc a 1\n'
    assert with_data == encode(graph, 'edgelist', attr=True, header=True)

    no_data = 'node1 node2\na b\nb c\nc a\n'
    assert no_data == encode(graph, 'edgelist', attr=False, header=True)
Esempio n. 3
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
Esempio n. 4
0
def test_graphml():
    with open('../data/karate.gml') as file:
        text = file.read()
    assert text == encode(decode(text, 'graphml'), 'graphml')
Esempio n. 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)
Esempio n. 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)