1 #!/usr/bin/env python 2 from nose.tools import assert_equal 3 import networkx as nx 4 import os,tempfile 5 6 class TestGpickle(object): 7 def setUp(self): 8 G=nx.Graph(name="test") 9 e=[('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')] 10 G.add_edges_from(e,width=10) 11 G.add_node('g',color='green') 12 G.graph['number']=1 13 self.G=G 14 15 def test_gpickle(self): 16 G=self.G 17 (fd,fname)=tempfile.mkstemp() 18 nx.write_gpickle(G,fname); 19 Gin=nx.read_gpickle(fname); 20 assert_equal(sorted(G.nodes(data=True)), 21 sorted(Gin.nodes(data=True))) 22 assert_equal(sorted(G.edges(data=True)), 23 sorted(Gin.edges(data=True))) 24 assert_equal(G.graph,Gin.graph) 25 os.close(fd) 26 os.unlink(fname) 27 28