def testToNetworkXGraph(self):
        try:
            import networkx
        except __HOLE__ as error:
            logging.debug(error)
            return

        numVertices = 10
        numFeatures = 3
        vList = VertexList(numVertices, numFeatures)

        graph = self.GraphType(vList)
        graph.addEdge(5, 1, 4)
        graph.addEdge(5, 2, 2)
        graph.addEdge(2, 7, 4)
        graph.addEdge(1, 9, 6)

        graph2 = self.GraphType(vList, False)
        graph2.addEdge(5, 1, 4)
        graph2.addEdge(5, 2, 2)
        graph2.addEdge(2, 7, 4)
        graph2.addEdge(1, 9, 6)
        networkXGraph = graph.toNetworkXGraph()

        self.assertEquals(networkXGraph.get_edge_data(5, 1), {'value' : 4.0})
        self.assertEquals(networkXGraph.get_edge_data(5, 2), {'value' : 2.0})
        self.assertEquals(networkXGraph.get_edge_data(2, 7), {'value' : 4.0})
        self.assertEquals(networkXGraph.get_edge_data(1, 9), {'value' : 6.0})
        self.assertEquals(networkXGraph.get_edge_data(9, 1), {'value' : 6.0})

        vertexIndexList = []

        for i in networkXGraph.__iter__():
            vertexIndexList.append(i)

        vertexIndexList.sort()
        self.assertTrue(vertexIndexList == list(range(numVertices)))
        self.assertTrue(networkXGraph.edges() == [(1, 9), (1, 5), (2, 5), (2, 7)])
        self.assertTrue(type(networkXGraph) == networkx.Graph)

        #Now we test the case where we have a directed graph
        networkXGraph = graph2.toNetworkXGraph()

        self.assertEquals(networkXGraph.get_edge_data(5, 1), {'value' : 4.0})
        self.assertEquals(networkXGraph.get_edge_data(5, 2), {'value' : 2.0})
        self.assertEquals(networkXGraph.get_edge_data(2, 7), {'value' : 4.0})
        self.assertEquals(networkXGraph.get_edge_data(1, 9), {'value' : 6.0})
        self.assertFalse(networkXGraph.has_edge(9, 1))

        vertexIndexList = []

        for i in networkXGraph.__iter__():
            vertexIndexList.append(i)

        vertexIndexList.sort()
        self.assertTrue(vertexIndexList == list(range(numVertices)))
        self.assertTrue(networkXGraph.edges() == [(1, 9), (2, 7), (5, 1), (5, 2)])
        self.assertTrue(type(networkXGraph) == networkx.DiGraph)

        #Test a graph with no edges
        numVertices = 10
        numFeatures = 3
        vList = VertexList(numVertices, numFeatures)
        vList.setVertices(numpy.random.rand(numVertices, numFeatures))

        graph = self.GraphType(vList)
        networkXGraph = graph.toNetworkXGraph()

        self.assertTrue(networkXGraph.order() == numVertices)
        self.assertTrue(networkXGraph.size() == 0)

        self.assertTrue((networkXGraph.nodes(data=True)[0][1]['label'] ==graph.getVertex(0)).all())
dataset/ETHPy150Open charanpald/APGL/apgl/graph/test/MatrixGraphTest.py/MatrixGraphTest.testToNetworkXGraph