[ONOS-7039] [ONOS-7044] Fix PEP8 Warnings in TestON
Change-Id: Ied79ff9caff5487a6df50466307f757468d7ca3a
diff --git a/TestON/core/graph.py b/TestON/core/graph.py
index b1cbdb2..b5bf9f6 100644
--- a/TestON/core/graph.py
+++ b/TestON/core/graph.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
-'''
-Copyright 2016 Open Networking Foundation (ONF)
+"""
+Copyright 2016 Open Networking Foundation ( ONF )
Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
@@ -10,7 +10,7 @@
TestON is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
+ ( at your option ) any later version.
TestON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,29 +20,28 @@
You should have received a copy of the GNU General Public License
along with TestON. If not, see <http://www.gnu.org/licenses/>.
-'''
-
-
+"""
import time
import random
+
class Graph:
+
"""
Graph class provides implementations of graph algorithms.
The functions currently supported include:
- Comparing two graphs with specified attributes for vertices and edges
- - Getting DFI (Depth First Index) and back edges during a DFS
+ - Getting DFI ( Depth First Index ) and back edges during a DFS
- Chain decomposition of a graph
- - Finding (non-)cut-edges and vertices
+ - Finding ( non- )cut-edges and vertices
"""
-
def __init__( self ):
# We use a dictionary to store all information about the graph
self.graphDict = {}
# Depth-first index of each vertex
self.DFI = {}
self.currentDFI = 0
- # Parent vertex (and edge to that vertex) of each vertex in depth-first search tree
+ # Parent vertex ( and edge to that vertex ) of each vertex in depth-first search tree
self.parentVertexInDFS = {}
self.parentEdgeInDFS = {}
# Back edges of the graph generated during DFS
@@ -60,7 +59,7 @@
vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } }
Each vertex should at least have an 'edges' attribute which describes the
adjacency information. The value of 'edges' attribute is also represented by
- a dictionary, which maps each edge (identified by the neighbor vertex) to a
+ a dictionary, which maps each edge ( identified by the neighbor vertex ) to a
list of attributes.
An example of the edges dictionary:
'edges': { vertex2: { 'port': ..., 'type': ... },
@@ -69,7 +68,7 @@
self.graphDict = graphDict
return main.TRUE
- def compareGraphs( self, graphDictA, graphDictB, vertexAttributes=['edges'], edgeAttributes=['port'] ):
+ def compareGraphs( self, graphDictA, graphDictB, vertexAttributes=[ 'edges' ], edgeAttributes=[ 'port' ] ):
"""
Compare two graphs.
By default only the adjacency relationship, i.e. 'port' attribute in
@@ -103,7 +102,7 @@
# Compare two attributes
attributeValueA = graphDictA[ vertex ][ vertexAttribute ]
attributeValueB = graphDictB[ vertex ][ vertexAttribute ]
- # FIXME: the comparison may not work for (sub)attribute values that are of list type
+ # FIXME: the comparison may not work for ( sub )attribute values that are of list type
# For attributes except for 'edges', we just rely on '==' for comparison
if not vertexAttribute == 'edges':
if not attributeValueA == attributeValueB:
@@ -150,8 +149,8 @@
attributeValueA,
attributeValueB ) )
if not result:
- #main.log.debug( "Graph: graphDictA: {}".format( graphDictA ) )
- #main.log.debug( "Graph: graphDictB: {}".format( graphDictB ) )
+ # main.log.debug( "Graph: graphDictA: {}".format( graphDictA ) )
+ # main.log.debug( "Graph: graphDictB: {}".format( graphDictB ) )
pass
return result
except TypeError:
@@ -166,8 +165,8 @@
def getNonCutEdges( self ):
"""
- Get a list of non-cut-edges (non-bridges).
- The definition of a cut-edge (bridge) is: the deletion of a cut-edge will
+ Get a list of non-cut-edges ( non-bridges ).
+ The definition of a cut-edge ( bridge ) is: the deletion of a cut-edge will
increase the number of connected component of a graph.
The function is realized by impelementing Schmidt's algorithm based on
chain decomposition.
@@ -183,7 +182,7 @@
for chain in self.chains:
for edge in chain:
nonCutEdges.append( edge )
- #main.log.debug( 'Non-cut-edges: {}'.format( nonCutEdges ) )
+ # main.log.debug( 'Non-cut-edges: {}'.format( nonCutEdges ) )
return nonCutEdges
except Exception:
main.log.exception( "Graph: Uncaught exception" )
@@ -207,16 +206,16 @@
# chain, the chain is a cycle chain
if chain[ 0 ][ 0 ] == chain[ -1 ][ 1 ]:
cycleChains.append( chain )
- #main.log.debug( 'Cycle chains: {}'.format( cycleChains ) )
+ # main.log.debug( 'Cycle chains: {}'.format( cycleChains ) )
# Get a set of vertices which are the first vertices of a cycle chain (excluding the first
# cycle chain), and these vertices are a subset of all cut-vertices
subsetOfCutVertices = []
if len( cycleChains ) > 1:
for cycleChain in cycleChains[ 1: ]:
subsetOfCutVertices.append( cycleChain[ 0 ][ 0 ] )
- #main.log.debug( 'Subset of cut vertices: {}'.format( subsetOfCutVertices ) )
+ # main.log.debug( 'Subset of cut vertices: {}'.format( subsetOfCutVertices ) )
nonCutVertices = []
- assert nonCutEdges != None
+ assert nonCutEdges is not None
for vertex in self.graphDict.keys():
if vertex in subsetOfCutVertices:
continue
@@ -224,12 +223,12 @@
for neighbor in self.graphDict[ vertex ][ 'edges' ].keys():
edge = [ vertex, neighbor ]
backwardEdge = [ neighbor, vertex ]
- if not edge in nonCutEdges and not backwardEdge in nonCutEdges:
+ if edge not in nonCutEdges and backwardEdge not in nonCutEdges:
vertexIsNonCut = False
break
if vertexIsNonCut:
nonCutVertices.append( vertex )
- #main.log.debug( 'Non-cut-vertices: {}'.format( nonCutVertices ) )
+ # main.log.debug( 'Non-cut-vertices: {}'.format( nonCutVertices ) )
return nonCutVertices
except KeyError:
main.log.exception( "Graph: KeyError exception found" )
@@ -247,7 +246,7 @@
as generates the back edges
"""
try:
- assert self.graphDict != None and len( self.graphDict ) != 0
+ assert self.graphDict is not None and len( self.graphDict ) != 0
for vertex in self.graphDict.keys():
self.DFI[ vertex ] = -1
self.parentVertexInDFS[ vertex ] = ''
@@ -288,14 +287,14 @@
else:
key = self.DFI[ neighbor ]
if key in self.backEdges.keys():
- if not edge in self.backEdges[ key ] and\
- not backwardEdge in self.backEdges[ key ]:
+ if edge not in self.backEdges[ key ] and\
+ backwardEdge not in self.backEdges[ key ]:
self.backEdges[ key ].append( backwardEdge )
else:
tempKey = self.DFI[ vertex ]
if tempKey in self.backEdges.keys():
- if not edge in self.backEdges[ tempKey ] and\
- not backwardEdge in self.backEdges[ tempKey ]:
+ if edge not in self.backEdges[ tempKey ] and\
+ backwardEdge not in self.backEdges[ tempKey ]:
self.backEdges[ key ] = [ backwardEdge ]
else:
self.backEdges[ key ] = [ backwardEdge ]
@@ -311,8 +310,7 @@
"""
This function finds all the chains in chain-decomposition algorithm
"""
- keyList = self.backEdges.keys()
- keyList.sort()
+ keyList = sorted( self.backEdges.keys() )
vertexIsVisited = {}
self.chains = []
for vertex in self.graphDict.keys():
@@ -329,7 +327,7 @@
nextVertex = currentEdge[ 1 ]
vertexIsVisited[ currentVertex ] = True
chain.append( currentEdge )
- if nextVertex == sourceVertex or vertexIsVisited[ nextVertex ] == True:
+ if nextVertex == sourceVertex or vertexIsVisited[ nextVertex ]:
break
currentEdge = self.parentEdgeInDFS[ nextVertex ]
self.chains.append( chain )