Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / readwrite / json_graph / tests / test_cytoscape.py @ 5cef0f13

History | View | Annotate | Download (2.01 KB)

1
import json
2
from nose.tools import assert_equal, assert_true, raises
3
import networkx as nx
4
from networkx.readwrite.json_graph import *
5

    
6

    
7
class TestCytoscape:
8

    
9
    def test_graph(self):
10
        G = nx.path_graph(4)
11
        H = cytoscape_graph(cytoscape_data(G))
12
        nx.is_isomorphic(G, H)
13

    
14
    def test_graph_attributes(self):
15
        G = nx.path_graph(4)
16
        G.add_node(1, color='red')
17
        G.add_edge(1, 2, width=7)
18
        G.graph['foo'] = 'bar'
19
        G.graph[1] = 'one'
20
        G.add_node(3, name="node", id="123")
21

    
22
        H = cytoscape_graph(cytoscape_data(G))
23
        assert_equal(H.graph['foo'], 'bar')
24
        assert_equal(H.nodes[1]['color'], 'red')
25
        assert_equal(H[1][2]['width'], 7)
26
        assert_equal(H.nodes[3]['name'], 'node')
27
        assert_equal(H.nodes[3]['id'], '123')
28

    
29
        d = json.dumps(cytoscape_data(G))
30
        H = cytoscape_graph(json.loads(d))
31
        assert_equal(H.graph['foo'], 'bar')
32
        assert_equal(H.graph[1], 'one')
33
        assert_equal(H.nodes[1]['color'], 'red')
34
        assert_equal(H[1][2]['width'], 7)
35
        assert_equal(H.nodes[3]['name'], 'node')
36
        assert_equal(H.nodes[3]['id'], '123')
37

    
38
    def test_digraph(self):
39
        G = nx.DiGraph()
40
        nx.add_path(G, [1, 2, 3])
41
        H = cytoscape_graph(cytoscape_data(G))
42
        assert_true(H.is_directed())
43
        nx.is_isomorphic(G, H)
44

    
45
    def test_multidigraph(self):
46
        G = nx.MultiDiGraph()
47
        nx.add_path(G, [1, 2, 3])
48
        H = cytoscape_graph(cytoscape_data(G))
49
        assert_true(H.is_directed())
50
        assert_true(H.is_multigraph())
51

    
52
    def test_multigraph(self):
53
        G = nx.MultiGraph()
54
        G.add_edge(1, 2, key='first')
55
        G.add_edge(1, 2, key='second', color='blue')
56
        H = cytoscape_graph(cytoscape_data(G))
57
        assert_true(nx.is_isomorphic(G, H))
58
        assert_equal(H[1][2]['second']['color'], 'blue')
59

    
60
    @raises(nx.NetworkXError)
61
    def test_exception(self):
62
        G = nx.MultiDiGraph()
63
        attrs = dict(name='node', ident='node')
64
        cytoscape_data(G, attrs)