def test_has_nodetypes_actuallyhas(self, mock_keggapi_link): mock_keggapi_link.return_value = [hsa_nodes, enzyme_nodes] graph = kgu.kegg_link_graph("hsa", "enzyme") self.assertTrue(kgu.has_nodetypes(graph))
def test_get_nodes_by_nodetype_missingnodetype(self, mock_keggapi_link): mock_keggapi_link.return_value = [hsa_nodes, enzyme_nodes] graph = kgu.kegg_link_graph("hsa", "enzyme") with self.assertRaises(errors.MissingNodetypeError): kgu.get_nodes_by_nodetype(graph, "map")
def test_get_nodes_by_nodetype_invalidgraph(self, mock_keggapi_link): mock_keggapi_link.return_value = [hsa_nodes, enzyme_nodes] graph = nx.Graph() with self.assertRaises(errors.NotAKeggGraphError): kgu.get_nodes_by_nodetype(graph, "hsa")
def test_get_nodes_by_nodetype(self, mock_keggapi_link): mock_keggapi_link.return_value = [hsa_nodes, enzyme_nodes] graph = kgu.kegg_link_graph("hsa", "enzyme") self.assertEqual( kgu.get_nodes_by_nodetype(graph, "hsa", return_dict=True), dict.fromkeys(hsa_nodes, "hsa"))
def test_neighbor_graph_edges(self): self.assertEqual( set( list( kgu.neighbor_graph(testgraph, { hsa_nodes[0]: 'hsa' }).edges)[0]), set([hsa_nodes[0], enzyme_nodes[0]]))
def test_kegg_link_graph_returns_bipartite_graphs(self, mocker): mocker.return_value = [hsa_nodes, enzyme_nodes] graph = kgu.kegg_link_graph("hsa", "enzyme") self.assertTrue(nx.is_bipartite(graph), "Graph is not bipartite")
def test_kegg_link_graph_adds_nodes(self, mock_keggapi_link): mock_keggapi_link.return_value = [hsa_nodes, enzyme_nodes] graph = kgu.kegg_link_graph("hsa", "enzyme") self.assertTrue( set(graph.nodes) == set(hsa_nodes + enzyme_nodes), "Different number of nodes")
def test_kegg_link_graph_all_nodes_are_correctly_copied(self, mocker): mocker.return_value = [hsa_nodes, enzyme_nodes] graph = kgu.kegg_link_graph("hsa", "enzyme") self.assertEqual( len(hsa_nodes) + len(enzyme_nodes), len(graph.nodes), "Not all nodes are being copied")
def test_has_nodetype_doesnthave(self): graph = nx.Graph() self.assertFalse(kgu.has_nodetypes(graph))
def test_neighbor_graph_nodes(self): self.assertEqual( set(kgu.neighbor_graph(testgraph, { hsa_nodes[0]: "hsa" }).nodes), set([hsa_nodes[0], enzyme_nodes[0]]))
def test_linked_nodes(self): self.assertEqual( kgu.linked_nodes(testgraph, hsa_nodes[0], return_dict=True), {enzyme_nodes[0]: "enzyme"})
def test_unique_nodetypes(self): self.assertEqual(kgu.get_unique_nodetypes(testgraph), ['enzyme', 'hsa'])
def test_get_nodes_by_nodetype_correct_nodetype_dict(self): hsa_nodetypes = dict.fromkeys(hsa_nodes, "hsa") self.assertEqual( kgu.get_nodes_by_nodetype(testgraph, "hsa", return_dict=True), hsa_nodetypes)