~ubuntu-branches/ubuntu/utopic/python-networkx/utopic

« back to all changes in this revision

Viewing changes to networkx/readwrite/json_graph/tests/test_node_link.py

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-08-11 12:41:30 UTC
  • mfrom: (1.4.1) (5.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120811124130-whr6uso7fncyg8bi
Tags: 1.7-1
* New upstream release
* debian/patches/changeset_*
  - removed, included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import json
 
2
from nose.tools import assert_equal, assert_raises, assert_not_equal,assert_true
 
3
import networkx as nx
 
4
from networkx.readwrite.json_graph import *
 
5
 
 
6
class TestNodeLink:
 
7
 
 
8
    def test_graph(self):
 
9
        G = nx.path_graph(4)
 
10
        H = node_link_graph(node_link_data(G))
 
11
        nx.is_isomorphic(G,H)
 
12
 
 
13
    def test_graph_attributes(self):
 
14
        G = nx.path_graph(4)
 
15
        G.add_node(1,color='red')
 
16
        G.add_edge(1,2,width=7)
 
17
        G.graph[1]='one'
 
18
        G.graph['foo']='bar'
 
19
 
 
20
        H = node_link_graph(node_link_data(G))
 
21
        assert_equal(H.graph['foo'],'bar')
 
22
        assert_equal(H.node[1]['color'],'red')
 
23
        assert_equal(H[1][2]['width'],7)
 
24
 
 
25
        d=json.dumps(node_link_data(G))
 
26
        H = node_link_graph(json.loads(d))
 
27
        assert_equal(H.graph['foo'],'bar')
 
28
        assert_equal(H.graph[1],'one')
 
29
        assert_equal(H.node[1]['color'],'red')
 
30
        assert_equal(H[1][2]['width'],7)
 
31
 
 
32
    def test_digraph(self):
 
33
        G = nx.DiGraph()
 
34
        H = node_link_graph(node_link_data(G))
 
35
        assert_true(H.is_directed())
 
36
 
 
37
    def test_multidigraph(self):
 
38
        G = nx.MultiDiGraph()
 
39
        H = node_link_graph(node_link_data(G))
 
40
        assert_true(H.is_directed())
 
41
        assert_true(H.is_multigraph())