Commits

Ronald Oussoren committed ca9fb20

Run reindent to remove trailing whitespace

  • Participants
  • Parent commits 7dafd85

Comments (0)

Files changed (12)

 To display the graphs or to generate image files the `graphviz <http://www.research.att.com/sw/tools/graphviz/>`_
 package needs to be installed on the system, moreover the :command:`dot` and :command:`dotty` programs must
 be accesible in the program path so that they can be ran from processes spawned
-within the module. 
+within the module.
 
 Example usage
 -------------
     dot.edge_style(4, 5, arrowsize=2, style='bold')
 
 
-.. note:: 
-  
+.. note::
+
    dotty (invoked via :py:func:`~altgraph.Dot.display`) may not be able to
    display all graphics styles. To verify the output save it to an image file
    and look at it that way.
         Initialization.
         '''
         self.name, self.attr = name, {}
-        
+
         assert graphtype in ['graph', 'digraph']
         self.type = graphtype
 

altgraph/Graph.py

 altgraph.Graph - Base Graph class
 =================================
 
-.. 
+..
   #--Version 2.1
   #--Bob Ippolito October, 2004
 
     def iterdata(self, start, end=None, forward=True, condition=None):
         """
         Perform a depth-first walk of the graph (as ``iterdfs``)
-        and yield the item data of every node where condition matches. The 
+        and yield the item data of every node where condition matches. The
         condition callback is only called when node_data is not None.
         """
 

altgraph/GraphUtil.py

     * removes: the list of nodes where the node
       data does not all *filters*
     * orphans: tuples of (last_good, node),
-      where node is not in removes, is directly 
-      reachable from a node in *removes* and 
+      where node is not in removes, is directly
+      reachable from a node in *removes* and
       *last_good* is the closest upstream node that is not
       in *removes*.
     """

altgraph/ObjectGraph.py

                     yield self.findNode(ident)
                     seen.add(ident)
         return iter_edges(outraw, 3), iter_edges(incraw, 2)
-    
+
     def filterStack(self, filters):
         """
         Filter the ObjectGraph in-place by removing all edges to nodes that

altgraph/__init__.py

 It has started out as an extension to the `graph_lib module <http://www.ece.arizona.edu/~denny/python_nest/graph_lib_1.0.1.html>`_
 written by Nathan Denny it has been significantly optimized and expanded.
 
-The :class:`altgraph.Graph.Graph` class is loosely modeled after the `LEDA <http://www.algorithmic-solutions.com/enleda.htm>`_ 
+The :class:`altgraph.Graph.Graph` class is loosely modeled after the `LEDA <http://www.algorithmic-solutions.com/enleda.htm>`_
 (Library of Efficient Datatypes)  representation. The library
 includes methods for constructing graphs, BFS and DFS traversals,
 topological sort, finding connected components, shortest paths as well as a number

altgraph_tests/test_altgraph.py

 
 class BasicTests (unittest.TestCase):
     def setUp(self):
-        self.edges = [ 
-            (1,2), (2,4), (1,3), (2,4), (3,4), (4,5), (6,5), (6,14), (14,15), 
-            (6, 15), (5,7), (7, 8), (7,13), (12,8), (8,13), (11,12), (11,9), 
-            (13,11), (9,13), (13,10) 
+        self.edges = [
+            (1,2), (2,4), (1,3), (2,4), (3,4), (4,5), (6,5), (6,14), (14,15),
+            (6, 15), (5,7), (7, 8), (7,13), (12,8), (8,13), (11,12), (11,9),
+            (13,11), (9,13), (13,10)
         ]
 
         # these are the edges
 
     def test_forw_bfs(self):
         # do a forward bfs
-        self.assertEqual( self.g.forw_bfs(1), 
+        self.assertEqual( self.g.forw_bfs(1),
                 [1, 2, 3, 4, 5, 7, 8, 13, 11, 10, 12, 9])
 
 
     def test_get_hops(self):
         # diplay the hops and hop numbers between nodes
-        self.assertEqual(self.g.get_hops(1, 8), 
+        self.assertEqual(self.g.get_hops(1, 8),
                 [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)])
 
     def test_shortest_path(self):
-        self.assertEqual(GraphAlgo.shortest_path(self.g, 1, 12), 
+        self.assertEqual(GraphAlgo.shortest_path(self.g, 1, 12),
                 [1, 2, 4, 5, 7, 13, 11, 12])
 
 

altgraph_tests/test_dot.py

         self.assertEqual(dot.edges, edges)
 
 
-        dot = Dot.Dot(g, nodes=[1,2], 
-                edgefn=lambda node: list(sorted(g.out_nbrs(node)))[:-1], 
+        dot = Dot.Dot(g, nodes=[1,2],
+                edgefn=lambda node: list(sorted(g.out_nbrs(node)))[:-1],
                 nodevisitor=lambda node: {'label': node},
                 edgevisitor=lambda head, tail: {'label': (head, tail) },
                 name="testgraph",
         self.assertFalse(6 in dot.edges[1])
         dot.edge_style(1,6, foo2='2bar')
         self.assertEqual(dot.edges[1][6], {'foo2': '2bar'})
-        
+
         self.assertRaises(GraphError, dot.edge_style, 1, 9, a=1)
         self.assertRaises(GraphError, dot.edge_style, 9, 1, a=1)
 
         dot.type = 'foo'
         self.assertRaises(GraphError, list, dot.iterdot())
         dot.type = 'digraph'
-    
+
         self.assertEqual(list(dot), [
             'digraph G {\n',
               'graph="foobar";',

altgraph_tests/test_graph.py

         self.assertEqual(graph.number_of_nodes(), 0)
         self.assertEqual(graph.number_of_hidden_nodes(), 3)
         self.assertEqual(list(sorted(graph.hidden_node_list())), [1, 2, 3])
-        
+
         self.assertFalse(1 in graph)
         self.assertFalse(2 in graph)
         self.assertFalse(3 in graph)
         self.assertRaises(GraphError, graph.edge_by_id, (e1+1)*(e2+1)+1)
 
         self.assertEqual(list(sorted(graph.edge_list())), [e1, e2])
-        
+
         self.assertEqual(graph.describe_edge(e1), (e1, 1, 1, 2))
         self.assertEqual(graph.describe_edge(e2), (e2, 'a', 4, 5))
 
 
         result = list(graph.iterdfs("1"))
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1', '1.1', '1.1.2', '1.1.1'
         ])
         result = list(graph.iterdfs("1", "1.2.1"))
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1'
         ])
 
         result = graph.forw_dfs("1")
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1', '1.1', '1.1.2', '1.1.1'
         ])
         result = graph.forw_dfs("1", "1.2.1")
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1'
         ])
 
 
         result = list(graph.iterdfs("1", forward=False))
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1', '1.1', '1.1.2', '1.1.1'
         ])
         result = list(graph.iterdfs("1", "1.2.1", forward=False))
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1'
         ])
         result = graph.back_dfs("1")
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1', '1.1', '1.1.2', '1.1.1'
         ])
         result = graph.back_dfs("1", "1.2.1")
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1'
         ])
 
-        
+
         # Introduce cyle:
         graph.add_edge("1", "1.2")
         result = list(graph.iterdfs("1", forward=False))
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1', '1.1', '1.1.2', '1.1.1'
         ])
 
         result = graph.back_dfs("1")
         self.assertEqual(result, [
-            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2', 
+            '1', '1.3', '1.2', '1.2.2', '1.2.2.3', '1.2.2.2',
             '1.2.2.1', '1.2.1', '1.1', '1.1.2', '1.1.1'
         ])
 
 
         result = list(graph.iterdata("1", forward=True))
         self.assertEqual(result, [
-            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II', 
+            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II',
             'I.II.II.I', 'I.II.I', 'I.I', 'I.I.II', 'I.I.I'
         ])
 
         result = list(graph.iterdata("1", end="1.2.1", forward=True))
         self.assertEqual(result, [
-            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II', 
+            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II',
             'I.II.II.I', 'I.II.I'
         ])
 
         result = list(graph.iterdata("1", condition=lambda n: len(n) < 6, forward=True))
         self.assertEqual(result, [
-            'I', 'I.III', 'I.II', 
+            'I', 'I.III', 'I.II',
             'I.I', 'I.I.I'
         ])
 
 
         result = list(graph.iterdata("1", forward=False))
         self.assertEqual(result, [
-            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II', 
+            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II',
             'I.II.II.I', 'I.II.I', 'I.I', 'I.I.II', 'I.I.I'
         ])
 
         result = list(graph.iterdata("1", end="1.2.1", forward=False))
         self.assertEqual(result, [
-            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II', 
+            'I', 'I.III', 'I.II', 'I.II.II', 'I.II.II.III', 'I.II.II.II',
             'I.II.II.I', 'I.II.I'
         ])
 
         result = list(graph.iterdata("1", condition=lambda n: len(n) < 6, forward=False))
         self.assertEqual(result, [
-            'I', 'I.III', 'I.II', 
+            'I', 'I.III', 'I.II',
             'I.I', 'I.I.I'
         ])
 
         graph.add_edge("1", "1.3")
         graph.add_edge("1.2", "1.2.1")
 
-        self.assertEqual(graph.forw_bfs("1"), 
+        self.assertEqual(graph.forw_bfs("1"),
                 ['1', '1.1', '1.2', '1.3', '1.1.1', '1.1.2', '1.2.1', '1.1.2.1', '1.1.2.2'])
-        self.assertEqual(graph.forw_bfs("1", "1.1.1"), 
+        self.assertEqual(graph.forw_bfs("1", "1.1.1"),
                 ['1', '1.1', '1.2', '1.3', '1.1.1'])
 
 
         graph.add_edge("1.3", "1")
         graph.add_edge("1.2.1", "1.2")
 
-        self.assertEqual(graph.back_bfs("1"), 
+        self.assertEqual(graph.back_bfs("1"),
                 ['1', '1.1', '1.2', '1.3', '1.1.1', '1.1.2', '1.2.1', '1.1.2.1', '1.1.2.2'])
-        self.assertEqual(graph.back_bfs("1", "1.1.1"), 
+        self.assertEqual(graph.back_bfs("1", "1.1.1"),
                 ['1', '1.1', '1.2', '1.3', '1.1.1'])
 
 
 
         # check cycle handling
         graph.add_edge("1", "1.2.1")
-        self.assertEqual(graph.back_bfs("1"), 
+        self.assertEqual(graph.back_bfs("1"),
                 ['1', '1.1', '1.2', '1.3', '1.1.1', '1.1.2', '1.2.1', '1.1.2.1', '1.1.2.2'])
 
 
         graph.add_edge(4, 5)
         graph.add_edge(5, 7)
         graph.add_edge(7, 8)
-        
-        self.assertEqual(graph.get_hops(1), 
+
+        self.assertEqual(graph.get_hops(1),
             [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)])
 
-        self.assertEqual(graph.get_hops(1, 5), 
+        self.assertEqual(graph.get_hops(1, 5),
             [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3)])
 
         graph.add_edge(5, 1)
         graph.add_edge(7, 1)
         graph.add_edge(7, 4)
 
-        self.assertEqual(graph.get_hops(1), 
+        self.assertEqual(graph.get_hops(1),
             [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)])
 
         # And the reverse graph
         graph.add_edge(5, 4)
         graph.add_edge(7, 5)
         graph.add_edge(8, 7)
-        
-        self.assertEqual(graph.get_hops(1, forward=False), 
+
+        self.assertEqual(graph.get_hops(1, forward=False),
             [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)])
 
-        self.assertEqual(graph.get_hops(1, 5, forward=False), 
+        self.assertEqual(graph.get_hops(1, 5, forward=False),
             [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3)])
 
         graph.add_edge(1, 5)
         graph.add_edge(1, 7)
         graph.add_edge(4, 7)
 
-        self.assertEqual(graph.get_hops(1, forward=False), 
+        self.assertEqual(graph.get_hops(1, forward=False),
             [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)])
 
 

altgraph_tests/test_graphstat.py

         for n in a:
             counts_inc.append(a.inc_degree(n))
             counts_out.append(a.out_degree(n))
-            
+
         self.assertEqual(GraphStat.degree_dist(a), GraphStat._binning(counts_out))
         self.assertEqual(GraphStat.degree_dist(a, mode='inc'), GraphStat._binning(counts_inc))
 

altgraph_tests/test_graphutil.py

         o.sort()
         self.assertEqual(o,
             [
-                ("1.1", "1.1.1.1"), 
+                ("1.1", "1.1.1.1"),
                 ("1.1", "1.1.1.2")
             ])
 
 
         self.assertEqual(o,
             [
-                ("1.1", "1.1.1.1"), 
+                ("1.1", "1.1.1.1"),
             ])
 
 

altgraph_tests/test_object_graph.py

         self.assertTrue(n3 in graph)
         graph.removeNode(n3)
         self.assertTrue(n3 not in graph)
-        graph.addNode(n3) 
+        graph.addNode(n3)
         self.assertTrue(n3 in graph)
 
         n = graph.createNode(SubNode, "n1")
 
 Additional functionality:
 
-* Section 'x-setup-stub': 
+* Section 'x-setup-stub':
 
     distribute-version: minimal distribute version
     setuptools-version: minimal setuptools version
         (for both: script will bail out when you have a too old
          version installed, and will install the version when
          it isn't installed)
-    prefer-distribute = 1  
+    prefer-distribute = 1
         If true install distribute when neither setuptools
         nor distribute is present, otherwise install setuptools
 
             if v:
                 result.append(v)
     return result
-            
+
 def _map_requirement(value):
     m = re.search(r'(\S+)\s*(?:\((.*)\))?', value)
     name = m.group(1)
 
         metadata['long_description'] = '\n\n'.join(parts)
 
-        
+
     try:
         v = cfg.get('metadata', 'zip-safe')
     except (NoOptionError, NoSectionError):
             # Collect sphinx output
             if not os.path.exists('dist'):
                 os.mkdir('dist')
-            zf = zipfile.ZipFile('dist/%s-docs.zip'%(name,), 'w', 
+            zf = zipfile.ZipFile('dist/%s-docs.zip'%(name,), 'w',
                     compression=zipfile.ZIP_DEFLATED)
 
             for toplevel, dirs, files in os.walk('doc/_build/html'):
             # Upload the results, this code is based on the distutils
             # 'upload' command.
             content = open('dist/%s-docs.zip'%(name,), 'rb').read()
-            
+
             data = {
                 ':action': 'doc_upload',
                 'name': name,
                 self.announce('Upload failed (%s): %s' % (r.status, r.reason),
                     log.ERROR)
 
-                print ('-'*75) 
+                print ('-'*75)
                 print (r.read())
                 print ('-'*75)
 
             if fnmatch(fn, pathPattern):
                 result.append(os.path.join(rootpath, fn))
     return result
-        
 
-def importExternalTestCases(unittest, 
+
+def importExternalTestCases(unittest,
         pathPattern="test_*.py", root=".", package=None):
     """
     Import all unittests in the PyObjC tree starting at 'root'
         testModules = [(package + '.' + m) for m in testModules]
 
     suites = []
-   
+
     for modName in testModules:
         try:
             module = __import__(modName)
         if nspkgs is not None:
             for nm in nspkgs:
                 del sys.modules[nm]
-        
+
         # Reset pkg_resources state:
         add_activation_listener(lambda dist: dist.activate())
         working_set.__init__()
             meta = self.distribution.metadata
             name = meta.get_name()
             test_pkg = name + "_tests"
-            suite = importExternalTestCases(unittest, 
+            suite = importExternalTestCases(unittest,
                     "test_*.py", test_pkg, test_pkg)
 
             runner = unittest.TextTestRunner(verbosity=self.verbosity)