[geneagrapher] 144/226: Renaming Record, Node, and Graph methods to follow conventions.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:10:56 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository geneagrapher.

commit 2b532885071f0de4412bf78cb936e8eface6a71c
Author: David Alber <alber.david at gmail.com>
Date:   Sun Oct 30 09:46:59 2011 -0700

    Renaming Record, Node, and Graph methods to follow conventions.
---
 geneagrapher/GGraph.py       |  54 ++++++++++----------
 geneagrapher/geneagrapher.py |  14 ++---
 tests/tests.py               | 118 +++++++++++++++++++++----------------------
 3 files changed, 93 insertions(+), 93 deletions(-)

diff --git a/geneagrapher/GGraph.py b/geneagrapher/GGraph.py
index b61d1c5..1fdddca 100644
--- a/geneagrapher/GGraph.py
+++ b/geneagrapher/GGraph.py
@@ -42,14 +42,14 @@ class Record:
         """
         return self.id.__cmp__(r2.id)
     
-    def hasInstitution(self):
+    def has_institution(self):
         """
         Return True if this record has an institution associated with it,
         else False.
         """
         return self.institution is not None
     
-    def hasYear(self):
+    def has_year(self):
         """
         Return True if this record has a year associated with it, else
         False.
@@ -85,15 +85,15 @@ class Node:
             raise TypeError("Unexpected parameter type: expected list object for 'ancestors'")
         if not isinstance(self.descendants, list):
             raise TypeError("Unexpected parameter type: expected list object for 'descendants'")
-        
+
     def __str__(self):
-        if self.record.hasInstitution():
-            if self.record.hasYear():
+        if self.record.has_institution():
+            if self.record.has_year():
                 return self.record.name.encode('utf-8', 'replace') + ' \\n' + self.record.institution.encode('utf-8', 'replace') + ' (' + str(self.record.year) + ')'
             else:
                 return self.record.name.encode('utf-8', 'replace') + ' \\n' + self.record.institution.encode('utf-8', 'replace')
         else:
-            if self.record.hasYear():
+            if self.record.has_year():
                 return self.record.name.encode('utf-8', 'replace') + ' \\n(' + str(self.record.year) + ')'
             else:
                 return self.record.name.encode('utf-8', 'replace')
@@ -101,7 +101,7 @@ class Node:
     def __cmp__(self, n2):
         return self.record.__cmp__(n2.record)
 
-    def addAncestor(self, ancestor):
+    def add_ancestor(self, ancestor):  # NOTE: is this used?
         """
         Append an ancestor id to the ancestor list.
         """
@@ -110,13 +110,13 @@ class Node:
             raise TypeError("Unexpected parameter type: expected int for 'ancestor'")
         self.ancestors.append(ancestor)
 
-    def id(self):
+    def get_id(self):
         """
         Accessor method to retrieve the id of this node's record.
         """
         return self.record.id
 
-    def setId(self, id):
+    def set_id(self, id):
         """
         Sets the record id.
         """
@@ -149,58 +149,58 @@ class Graph:
         self.nodes = {}
         if self.heads is not None:
             for head in self.heads:
-                self.nodes[head.id()] = head
+                self.nodes[head.get_id()] = head
 
-    def hasNode(self, id):
+    def has_node(self, id):
         """
         Check if the graph contains a node with the given id.
         """
         return self.nodes.has_key(id)
 
-    def getNode(self, id):
+    def get_node(self, id):
         """
         Return the node in the graph with given id. Returns
         None if no such node exists.
         """
-        if self.hasNode(id):
+        if self.has_node(id):
             return self.nodes[id]
         else:
             return None
 
-    def getNodeList(self):
+    def get_node_list(self): # NOTE: this method is unused
         """
         Return a list of the nodes in the graph.
         """
         return self.nodes.keys()
 
-    def addNode(self, name, institution, year, id, ancestors, descendants, isHead=False):
+    def add_node(self, name, institution, year, id, ancestors, descendants, isHead=False):
         """
         Add a new node to the graph if a matching node is not already
         present.
         """
         record = Record(name, institution, year, id)
         node = Node(record, ancestors, descendants)
-        self.addNodeObject(node, isHead)
+        self.add_node_object(node, isHead)
 
-    def addNodeObject(self, node, isHead=False):
+    def add_node_object(self, node, isHead=False):
         """
         Add a new node object to the graph if a node with the same id
         is not already present.
         """
-        if node.id() is not None and self.hasNode(node.id()):
-            msg = "node with id {} already exists".format(node.id())
+        if node.get_id() is not None and self.has_node(node.get_id()):
+            msg = "node with id {} already exists".format(node.get_id())
             raise DuplicateNodeError(msg)
-        if node.id() is None:
+        if node.get_id() is None:
             # Assign a "dummy" id.
-            node.setId(self.supp_id)
+            node.set_id(self.supp_id)
             self.supp_id -= 1
-        self.nodes[node.id()] = node
+        self.nodes[node.get_id()] = node
         if self.heads is None:
             self.heads = [node]
         elif isHead:
             self.heads.append(node)
 
-    def generateDotFile(self, include_ancestors, include_descendants):
+    def generate_dot_file(self, include_ancestors, include_descendants):
         """
         Return a string that contains the content of the Graphviz dotfile
         format for this graph.
@@ -210,7 +210,7 @@ class Graph:
 
         queue = []
         for head in self.heads:
-            queue.append(head.id())
+            queue.append(head.get_id())
         edges = ""
         dotfile = ""
         
@@ -221,10 +221,10 @@ class Graph:
 
         while len(queue) > 0:
             node_id = queue.pop()
-            if not self.hasNode(node_id):
+            if not self.has_node(node_id):
                 # Skip this id if a corresponding node is not present.
                 continue
-            node = self.getNode(node_id)
+            node = self.get_node(node_id)
 
             if node.already_printed:
                 continue
@@ -245,7 +245,7 @@ class Graph:
 
             # Store the connection information for this node.
             for advisor in node.ancestors:
-                if self.hasNode(advisor):
+                if self.has_node(advisor):
                     edgestr = "\n    {} -> {};".format(advisor, node_id)
                     edges += edgestr
                 
diff --git a/geneagrapher/geneagrapher.py b/geneagrapher/geneagrapher.py
index 667329c..af1b990 100644
--- a/geneagrapher/geneagrapher.py
+++ b/geneagrapher/geneagrapher.py
@@ -63,7 +63,7 @@ class Geneagrapher:
         # Grab "leaf" nodes.
         while len(leaf_grab_queue) != 0:
             id = leaf_grab_queue.pop()
-            if not self.graph.hasNode(id):
+            if not self.graph.has_node(id):
                 # Then this information has not yet been grabbed.
                 grabber = Grabber(id)
                 if self.verbose:
@@ -73,7 +73,7 @@ class Geneagrapher:
                 except ValueError:
                     # The given id does not exist in the Math Genealogy Project's database.
                     raise
-                self.graph.addNode(name, institution, year, id, advisors, descendants, True)
+                self.graph.add_node(name, institution, year, id, advisors, descendants, True)
                 if self.get_ancestors:
                     ancestor_grab_queue += advisors
                 if self.get_descendants:
@@ -83,7 +83,7 @@ class Geneagrapher:
         if self.get_ancestors:
             while len(ancestor_grab_queue) != 0:
                 id = ancestor_grab_queue.pop()
-                if not self.graph.hasNode(id):
+                if not self.graph.has_node(id):
                     # Then this information has not yet been grabbed.
                     grabber = Grabber(id)
                     if self.verbose:
@@ -93,14 +93,14 @@ class Geneagrapher:
                     except ValueError:
                         # The given id does not exist in the Math Genealogy Project's database.
                         raise
-                    self.graph.addNode(name, institution, year, id, advisors, descendants)
+                    self.graph.add_node(name, institution, year, id, advisors, descendants)
                     ancestor_grab_queue += advisors
                         
         # Grab descendants of leaf nodes.
         if self.get_descendants:
             while len(descendant_grab_queue) != 0:
                 id = descendant_grab_queue.pop()
-                if not self.graph.hasNode(id):
+                if not self.graph.has_node(id):
                     # Then this information has not yet been grabbed.
                     grabber = Grabber(id)
                     if self.verbose:
@@ -110,11 +110,11 @@ class Geneagrapher:
                     except ValueError:
                         # The given id does not exist in the Math Genealogy Project's database.
                         raise
-                    self.graph.addNode(name, institution, year, id, advisors, descendants)
+                    self.graph.add_node(name, institution, year, id, advisors, descendants)
                     descendant_grab_queue += descendants
                     
     def generate_dot_file(self):
-        dotfile = self.graph.generateDotFile(self.get_ancestors, self.get_descendants)
+        dotfile = self.graph.generate_dot_file(self.get_ancestors, self.get_descendants)
         if self.write_filename is not None:
             outfile = open(self.write_filename, "w")
             outfile.write(dotfile)
diff --git a/tests/tests.py b/tests/tests.py
index d061c76..8450c1c 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -46,25 +46,25 @@ class TestRecordMethods(unittest.TestCase):
         record2 = GGraph.Record("Leonhard Euler", "Universitaet Basel", 1726, 38586)
         self.assert_(record1 < record2)
 
-    def test008_hasInstitution_yes(self):
-        # Verify hasInstitution() method returns True when the conditions are right.
+    def test008_has_institution_yes(self):
+        # Verify has_institution() method returns True when the conditions are right.
         record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
-        self.assert_(record.hasInstitution())
+        self.assert_(record.has_institution())
 
-    def test009_hasInstitution_no(self):
-        # Verify hasInstitution() method returns False when the conditions are right.
+    def test009_has_institution_no(self):
+        # Verify has_institution() method returns False when the conditions are right.
         record = GGraph.Record("Carl Friedrich Gauss", None, 1799, 18231)
-        self.assert_(not record.hasInstitution())
+        self.assert_(not record.has_institution())
 
-    def test010_hasYear_yes(self):
-        # Verify hasYear() method returns True when the conditions are right.
+    def test010_has_year_yes(self):
+        # Verify has_year() method returns True when the conditions are right.
         record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
-        self.assert_(record.hasYear())
+        self.assert_(record.has_year())
 
-    def test011_hasYear_no(self):
-        # Verify hasYear() method returns False when the conditions are right.
+    def test011_has_year_no(self):
+        # Verify has_year() method returns False when the conditions are right.
         record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", None, 18231)
-        self.assert_(not record.hasYear())
+        self.assert_(not record.has_year())
 
 class TestNodeMethods(unittest.TestCase):
     """
@@ -140,26 +140,26 @@ class TestNodeMethods(unittest.TestCase):
         self.assert_(node1 < node2)
 
     def test010_add_ancestor(self):
-        # Test the addAncestor() method.
+        # Test the add_ancestor() method.
         node = GGraph.Node(self.record, [], [])
-        node.addAncestor(5)
+        node.add_ancestor(5)
         self.assertEquals(node.ancestors, [5])
 
     def test011_add_ancestor_bad_type(self):
-        # Test the addAncestor() method for a case where the parameter type is incorrect.
+        # Test the add_ancestor() method for a case where the parameter type is incorrect.
         node = GGraph.Node(self.record, [], [])
-        self.assertRaises(TypeError, node.addAncestor, '5')
+        self.assertRaises(TypeError, node.add_ancestor, '5')
         
     def test012_get_id(self):
         node = GGraph.Node(self.record, [], [])
-        self.assertEquals(node.id(), 18231)
+        self.assertEquals(node.get_id(), 18231)
 
     def test013_set_id(self):
-        # Test the setId() method.
+        # Test the set_id() method.
         node = GGraph.Node(self.record, [], [])
-        self.assertEquals(node.id(), 18231)
-        node.setId(15)
-        self.assertEquals(node.id(), 15)
+        self.assertEquals(node.get_id(), 18231)
+        node.set_id(15)
+        self.assertEquals(node.get_id(), 15)
         
 
 class TestGraphMethods(unittest.TestCase):
@@ -187,67 +187,67 @@ class TestGraphMethods(unittest.TestCase):
         self.assertRaises(TypeError, GGraph.Graph, 3)
         
     def test004_has_node_true(self):
-        # Test the hasNode() method for a True case.
-        self.assertEquals(self.graph1.hasNode(18231), True)
+        # Test the has_node() method for a True case.
+        self.assertEquals(self.graph1.has_node(18231), True)
         
     def test005_has_node_false(self):
-        # Test the hasNode() method for a False case.
-        self.assertEquals(self.graph1.hasNode(1), False)
+        # Test the has_node() method for a False case.
+        self.assertEquals(self.graph1.has_node(1), False)
         
     def test006_get_node(self):
-        # Test the getNode() method.
-        node = self.graph1.getNode(18231)
+        # Test the get_node() method.
+        node = self.graph1.get_node(18231)
         self.assert_(node == self.node1)
         
     def test007_get_node_not_found(self):
-        # Test the getNode() method for a case where the node does not exist.
-        node = self.graph1.getNode(1)
+        # Test the get_node() method for a case where the node does not exist.
+        node = self.graph1.get_node(1)
         self.assertEquals(node, None)
         
     def test008_get_node_list(self):
-        # Test the getNodeList() method.
-        self.assertEquals(self.graph1.getNodeList(), [18231])
+        # Test the get_node_list() method.
+        self.assertEquals(self.graph1.get_node_list(), [18231])
         
     def test008_get_node_list_empty(self):
-        # Test the getNodeList() method for an empty graph.
+        # Test the get_node_list() method for an empty graph.
         graph = GGraph.Graph()
-        self.assertEquals(graph.getNodeList(), [])
+        self.assertEquals(graph.get_node_list(), [])
         
     def test009_add_node(self):
-        # Test the addNode() method.
-        self.graph1.addNode("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
-        self.assertEquals([38586, 18231], self.graph1.getNodeList())
+        # Test the add_node() method.
+        self.graph1.add_node("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
+        self.assertEquals([38586, 18231], self.graph1.get_node_list())
         self.assertEquals(self.graph1.heads, [self.node1])
 
     def test010_add_second_node_head(self):
-        # Test the addNode() method when adding a second node and
+        # Test the add_node() method when adding a second node and
         # marking it as a head node.
-        self.graph1.addNode("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [], True)
-        self.assertEquals([38586, 18231], self.graph1.getNodeList())
-        self.assertEquals(self.graph1.heads, [self.node1, self.graph1.getNode(38586)])
+        self.graph1.add_node("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [], True)
+        self.assertEquals([38586, 18231], self.graph1.get_node_list())
+        self.assertEquals(self.graph1.heads, [self.node1, self.graph1.get_node(38586)])
 
     def test011_add_node_head(self):
-        # Test the addNode() method when no heads exist.
+        # Test the add_node() method when no heads exist.
         graph = GGraph.Graph()
         self.assertEquals(graph.heads, None)
-        graph.addNode("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
-        self.assertEquals(graph.heads, [graph.getNode(38586)])
+        graph.add_node("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
+        self.assertEquals(graph.heads, [graph.get_node(38586)])
 
     def test012_add_node_already_present(self):
-        self.graph1.addNode("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
-        self.assertEquals([38586, 18231], self.graph1.getNodeList())
-        self.assertRaises(GGraph.DuplicateNodeError, self.graph1.addNode, "Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
+        self.graph1.add_node("Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
+        self.assertEquals([38586, 18231], self.graph1.get_node_list())
+        self.assertRaises(GGraph.DuplicateNodeError, self.graph1.add_node, "Leonhard Euler", "Universitaet Basel", 1726, 38586, [], [])
 
     def test013_add_node_object(self):
-        # Test the addNodeObject() method.
+        # Test the add_node_object() method.
         record = GGraph.Record("Leonhard Euler", "Universitaet Basel", 1726, 38586)
         node = GGraph.Node(record, [], [])
-        self.graph1.addNodeObject(node)
-        self.assertEquals([38586, 18231], self.graph1.getNodeList())
+        self.graph1.add_node_object(node)
+        self.assertEquals([38586, 18231], self.graph1.get_node_list())
         self.assertEquals(self.graph1.heads, [self.node1])
 
     def test014_generate_dot_file(self):
-        # Test the generateDotFile() method.
+        # Test the generate_dot_file() method.
         dotfileexpt = """digraph genealogy {
     graph [charset="utf-8"];
     node [shape=plaintext];
@@ -257,18 +257,18 @@ class TestGraphMethods(unittest.TestCase):
 
 }
 """    
-        dotfile = self.graph1.generateDotFile(True, False)
+        dotfile = self.graph1.generate_dot_file(True, False)
         self.assertEquals(dotfile, dotfileexpt)
         
     def test015_generate_dot_file(self):
-        # Test the generateDotFile() method.
+        # Test the generate_dot_file() method.
         graph = GGraph.Graph()
-        graph.addNode("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231, [18230], [])
-        graph.addNode("Johann Friedrich Pfaff", "Georg-August-Universitaet Goettingen", 1786, 18230, [66476], [])
-        graph.addNode("Abraham Gotthelf Kaestner", "Universitaet Leipzig", 1739, 66476, [57670], [])
-        graph.addNode("Christian August Hausen", "Martin-Luther-Universitaet Halle-Wittenberg", 1713, 57670, [72669], [])
-        graph.addNode("Johann Christoph Wichmannshausen", "Universitaet Leipzig", 1685, 72669, [21235], [])
-        graph.addNode("Otto Mencke", "Universitaet Leipzig", 1665, 21235, [], [])
+        graph.add_node("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231, [18230], [])
+        graph.add_node("Johann Friedrich Pfaff", "Georg-August-Universitaet Goettingen", 1786, 18230, [66476], [])
+        graph.add_node("Abraham Gotthelf Kaestner", "Universitaet Leipzig", 1739, 66476, [57670], [])
+        graph.add_node("Christian August Hausen", "Martin-Luther-Universitaet Halle-Wittenberg", 1713, 57670, [72669], [])
+        graph.add_node("Johann Christoph Wichmannshausen", "Universitaet Leipzig", 1685, 72669, [21235], [])
+        graph.add_node("Otto Mencke", "Universitaet Leipzig", 1665, 21235, [], [])
         
         dotfileexpt = """digraph genealogy {
     graph [charset="utf-8"];
@@ -289,7 +289,7 @@ class TestGraphMethods(unittest.TestCase):
     21235 -> 72669;
 }
 """
-        dotfile = graph.generateDotFile(True, False)
+        dotfile = graph.generate_dot_file(True, False)
         self.assertEquals(dotfile, dotfileexpt)
 
 class TestGrabberMethods(unittest.TestCase):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/geneagrapher.git



More information about the debian-science-commits mailing list