fluxion.jsongraph.objects.graph module

class fluxion.jsongraph.objects.graph.Graph(nodes=[], edges=[], type=None, label=None, directed=True, metadata=None)

Bases: object

Graph class representing a single graph in the JSON Graph Format.

DIRECTED = 'directed'
EDGES = 'edges'
GRAPH = 'graph'
LABEL = 'label'
METADATA = 'metadata'
NODES = 'nodes'
TYPE = 'type'
add_edge(edge, force_direction=False)

Method to add one edge to the graph.

Parameters:
  • add (edge -- Edge the edge to)

  • bool (force_direction --)

add_node(node)

Method to add one node to the graph.

Parameters:

add (node -- Node the node to)

get_edges()

Method to get a list of the edges in the graph.

Returns:

[Edge] the list of all edges in the graph

get_label()

Method to get the label of the graph.

Returns:

string the label of the graph if set, else None

get_metadata()

"Get the metadata of the graph.

Returns:

dictionary the metadata of the graph if set, else None

get_nodes()

Method to get a list of the nodes in the graph.

Returns:

[Node] the list of all nodes in the graph

get_type()

Method to get the type of the graph.

Returns:

string the typename of the graph if set, else None

is_directed()

Method to see whether the graph is directed or not.

Returns:

bool True if the graph directed, else False

set_directed(directed=True)

Method to make the graph (un)directed.

Parameters:

bool (directed --)

set_edges(edges, force_direction=False)

Method to add a list of edges to the graph.

Parameters:
  • added (edges -- [edge] array of nodes that need to be)

  • bool (force_direction --)

set_label(label)

Method to set the label of the graph.

Parameters:

set (label -- string the labelname of the graph to)

set_metadata(metadata)

Method to set the metadata of the graph.

Parameters:

graph (metadata -- dictionary the metadata to set on the)

set_nodes(nodes)

Method to add a list of nodes to the graph.

Parameters:

added (nodes -- [Node] array of nodes that need to be)

set_type(type)

Method to set the type of the graph.

Parameters:

set (type -- string the typename of the graph to)

to_JSON(asString=False)

Convert the graph to JSON.

Creates a dictionary object of the graph conforming to the JSON Graph Format.

Parameters:

string (asString -- bool if set to True the method returns the JSON as)

Returns:

dictionary the graph as dictionary ready to serialize

class fluxion.jsongraph.objects.graph.TestGraphClass(methodName='runTest')

Bases: TestCase

test_base()
test_setters()
test_to_JSON()