/usr/lib/python2.7/dist-packages/networkx/readwrite/tests/test_yaml.py is in python-networkx 1.8.1-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | """
Unit tests for yaml.
"""
import os,tempfile
from nose import SkipTest
from nose.tools import assert_equal
import networkx as nx
class TestYaml(object):
@classmethod
def setupClass(cls):
global yaml
try:
import yaml
except ImportError:
raise SkipTest('yaml not available.')
def setUp(self):
self.build_graphs()
def build_graphs(self):
self.G = nx.Graph(name="test")
e = [('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
self.G.add_edges_from(e)
self.G.add_node('g')
self.DG = nx.DiGraph(self.G)
self.MG = nx.MultiGraph()
self.MG.add_weighted_edges_from([(1,2,5),(1,2,5),(1,2,1),(3,3,42)])
def assert_equal(self, G, data=False):
(fd, fname) = tempfile.mkstemp()
nx.write_yaml(G, fname)
Gin = nx.read_yaml(fname);
assert_equal(sorted(G.nodes()),sorted(Gin.nodes()))
assert_equal(G.edges(data=data),Gin.edges(data=data))
os.close(fd)
os.unlink(fname)
def testUndirected(self):
self.assert_equal(self.G, False)
def testDirected(self):
self.assert_equal(self.DG, False)
def testMultiGraph(self):
self.assert_equal(self.MG, True)
|