Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.92 KB)

1
import json
2
from nose.tools import assert_true, assert_false, assert_raises
3
import networkx as nx
4
from networkx.readwrite.json_graph import jit_data, jit_graph
5

    
6

    
7
class TestJIT(object):
8
    def test_jit(self):
9
        G = nx.Graph()
10
        G.add_node('Node1', node_data='foobar')
11
        G.add_node('Node3', node_data='bar')
12
        G.add_node('Node4')
13
        G.add_edge('Node1', 'Node2', weight=9, something='isSomething')
14
        G.add_edge('Node2', 'Node3', weight=4, something='isNotSomething')
15
        G.add_edge('Node1', 'Node2')
16
        d = jit_data(G)
17
        K = jit_graph(json.loads(d))
18
        assert_true(nx.is_isomorphic(G, K))
19

    
20
    def test_jit_2(self):
21
        G = nx.Graph()
22
        G.add_node(1, node_data=3)
23
        G.add_node(3, node_data=0)
24
        G.add_edge(1, 2, weight=9, something=0)
25
        G.add_edge(2, 3, weight=4, something=3)
26
        G.add_edge(1, 2)
27
        d = jit_data(G)
28
        K = jit_graph(json.loads(d))
29
        assert_true(nx.is_isomorphic(G, K))
30

    
31
    def test_jit_directed(self):
32
        G = nx.DiGraph()
33
        G.add_node(1, node_data=3)
34
        G.add_node(3, node_data=0)
35
        G.add_edge(1, 2, weight=9, something=0)
36
        G.add_edge(2, 3, weight=4, something=3)
37
        G.add_edge(1, 2)
38
        d = jit_data(G)
39
        K = jit_graph(json.loads(d), create_using=nx.DiGraph())
40
        assert_true(nx.is_isomorphic(G, K))
41

    
42
    def test_jit_multi_directed(self):
43
        G = nx.MultiDiGraph()
44
        G.add_node(1, node_data=3)
45
        G.add_node(3, node_data=0)
46
        G.add_edge(1, 2, weight=9, something=0)
47
        G.add_edge(2, 3, weight=4, something=3)
48
        G.add_edge(1, 2)
49
        assert_raises(nx.NetworkXNotImplemented, jit_data, G)
50

    
51
        H = nx.DiGraph(G)
52
        d = jit_data(H)
53
        K = jit_graph(json.loads(d), create_using=nx.MultiDiGraph())
54
        assert_true(nx.is_isomorphic(H, K))
55
        K.add_edge(1, 2)
56
        assert_false(nx.is_isomorphic(H, K))
57
        assert_true(nx.is_isomorphic(G, K))