Skip to content

Commit

Permalink
Integration test for network_util.py (#342)
Browse files Browse the repository at this point in the history
Adds integration test for network_util.py
  • Loading branch information
hrishikesh-dahiya authored and prasadtalasila committed Nov 9, 2018
1 parent bfbd3cf commit eec9e0a
Show file tree
Hide file tree
Showing 5 changed files with 841 additions and 9 deletions.
64 changes: 55 additions & 9 deletions lib/network_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,68 @@
import networkx as nx


class Graph(object):
class Graph(nx.Graph):

def __init__(self):
def __init__(self, incoming_graph_data=None, **attr):
self.graph = nx.Graph()

@property
def name(self):
return self.graph.name

@name.setter
def name(self, s):
self.graph.name = s

def add_node(self, node_for_adding):
self.graph.add_node(node_for_adding)

def add_nodes_from(self, nodes_for_adding, **attr):
self.graph.add_nodes_from(nodes_for_adding)

@property
def nodes(self):
return self.graph.nodes()

def has_node(self, n):
return self.graph.has_node(n)

def add_edge(self, u_of_edge, v_of_edge, **attr):
self.graph.add_edge(u_of_edge, v_of_edge)

def add_edges_from(self, ebunch_to_add, **attr):
self.graph.add_edges_from(ebunch_to_add)

def is_directed(self):
return self.graph.is_directed()

def is_multigraph(self):
return self.graph.is_multigraph()

def edges(self):
return self.graph.edges()

def has_edge(self, u, v):
return self.graph.has_edge(u, v)


class DiGraph(Graph):

def __init__(self):
self.digraph = nx.DiGraph()
self.graph = nx.DiGraph()


class MultiGraph(Graph):

def __init__(self):
self.graph = nx.MultiGraph()


class MultiDiGraph(MultiGraph, DiGraph):

def __init__(self):
self.multidigraph = nx.MultiDiGraph()
self.graph = nx.MultiDiGraph()



def read_pajek(path, encoding='UTF-8'):
Expand All @@ -31,7 +77,7 @@ def read_pajek(path, encoding='UTF-8'):

def is_isomorphic(G1, G2, node_match=None, edge_match=None):

return nx.algorithms.isomorphism.is_isomorphic(G1, G2, node_match, edge_match)
return nx.algorithms.isomorphism.is_isomorphic(G1, G2)


def to_agraph(N):
Expand All @@ -46,19 +92,19 @@ def connected_components(G):

def relabel_nodes(G, mapping, copy=True):

return nx.relabel.relabel_nodes(G, mapping, copy)
return nx.relabel.relabel_nodes(G, mapping)


def write_pajek(G, path, encoding='UTF-8'):

return nx.readwrite.pajek.write_pajek(G, path, encoding)
return nx.readwrite.pajek.write_pajek(G, path)


def hits(G, max_iter=100, tol=1.0e-8, nstart=None, normalized=True):

return nx.hits(G, max_iter, tol, nstart, normalized)
return nx.hits(G)


def node_link_data(G, attrs=None):

return nx.readwrite.json_graph.node_link_data(G, attrs)
return nx.readwrite.json_graph.node_link_data(G)
Loading

0 comments on commit eec9e0a

Please sign in to comment.