[geneagrapher] 183/226: Changed Graph.seeds member to be set of Node IDs, rather than a set of Node objects.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:11:06 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 d6db17e1ff0052c9ea4cab0bc8b4998e0cde5701
Author: David Alber <alber.david at gmail.com>
Date:   Sun Nov 27 22:06:22 2011 -0800

    Changed Graph.seeds member to be set of Node IDs, rather than a
    set of Node objects.
    
    This closes #1.
---
 geneagrapher/graph/graph.py | 38 ++++++++++++++++++++------------------
 tests/test_graph_methods.py | 11 +++++------
 2 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/geneagrapher/graph/graph.py b/geneagrapher/graph/graph.py
index 7dafa70..9da8735 100644
--- a/geneagrapher/graph/graph.py
+++ b/geneagrapher/graph/graph.py
@@ -14,31 +14,33 @@ class Graph(dict):
     """
     Class storing the representation of a genealogy graph.
     """
-    def __init__(self, seeds=None):
+    def __init__(self, seed_nodes=None):
         """
         Graph class constructor.
 
         Parameters:
-            seeds: a set of Node objects representing the tree seed nodes
+            seed_nodes: a set of Node objects representing the tree seed nodes
                 (omit to create an empty graph)
         """
         dict.__init__(self)
-        self.seeds = seeds
-        if self.seeds is None:
-            self.seeds = set()
-        self.supp_id = -1
 
-        # Verify type of seeds is what we expect.
-        if not isinstance(self.seeds, set):
-            raise TypeError("Unexpected parameter type: expected set of \
-Node objects for 'seeds'")
-        for seed in self.seeds:
-            if not isinstance(seed, Node):
-                raise TypeError("Unexpected parameter type: expected set \
-of Node objects for 'seeds'")
+        # Verify type of seed_nodes is what we expect.
+        if seed_nodes is not None:
+            if not isinstance(seed_nodes, set):
+                raise TypeError("Unexpected argument type: expected set of \
+Node objects for 'seed_nodes'")
+            for seed in seed_nodes:
+                if not isinstance(seed, Node):
+                    raise TypeError("Unexpected parameter type: expected set \
+of Node objects for 'seed_nodes'")
+
+        if seed_nodes is None:
+            self.seeds = set()
+        else:
+            self.seeds = set([seed.get_id() for seed in seed_nodes])
+            self.update([(seed.get_id(), seed) for seed in seed_nodes])
 
-        if self.seeds != set():
-            self.update([(seed.get_id(), seed) for seed in self.seeds])
+        self.supp_id = -1
 
     def has_node(self, id):
         """
@@ -83,7 +85,7 @@ of Node objects for 'seeds'")
             self.supp_id -= 1
         self[node.get_id()] = node
         if self.seeds == set() or is_seed:
-            self.seeds.add(node)
+            self.seeds.add(node.get_id())
 
     def generate_dot_file(self, include_ancestors, include_descendants):
         """
@@ -95,7 +97,7 @@ of Node objects for 'seeds'")
 
         queue = []
         for seed in self.seeds:
-            queue.append(seed.get_id())
+            queue.append(seed)
         edges = ""
         dotfile = ""
 
diff --git a/tests/test_graph_methods.py b/tests/test_graph_methods.py
index 2846ee8..471f5e0 100644
--- a/tests/test_graph_methods.py
+++ b/tests/test_graph_methods.py
@@ -19,7 +19,7 @@ class TestGraphMethods(unittest.TestCase):
 
     def test002_init(self):
         # Test the constructor.
-        self.assert_(self.graph1.seeds == set([self.node1]))
+        self.assertEquals(self.graph1.seeds, set([18231]))
         self.assertEquals(self.graph1.keys(), [18231])
         self.assertEquals(self.graph1[18231], self.node1)
 
@@ -66,7 +66,7 @@ class TestGraphMethods(unittest.TestCase):
         self.graph1.add_node("Leonhard Euler", "Universitaet Basel", 1726,
                              38586, set(), set())
         self.assertEquals([38586, 18231], self.graph1.get_node_list())
-        self.assertEquals(self.graph1.seeds, set([self.node1]))
+        self.assertEquals(self.graph1.seeds, set([18231]))
 
     def test010_add_second_node_seed(self):
         # Test the add_node() method when adding a second node and
@@ -74,8 +74,7 @@ class TestGraphMethods(unittest.TestCase):
         self.graph1.add_node("Leonhard Euler", "Universitaet Basel", 1726,
                              38586, set(), set(), True)
         self.assertEquals([38586, 18231], self.graph1.get_node_list())
-        self.assertEquals(self.graph1.seeds, set([self.node1,
-                                              self.graph1[38586]]))
+        self.assertEquals(self.graph1.seeds, set([18231, 38586]))
 
     def test011_add_node_seed(self):
         # Test the add_node() method when no seeds exist.
@@ -83,7 +82,7 @@ class TestGraphMethods(unittest.TestCase):
         self.assertEquals(graph.seeds, set())
         graph.add_node("Leonhard Euler", "Universitaet Basel", 1726,
                        38586, set(), set())
-        self.assertEquals(graph.seeds, set([graph[38586]]))
+        self.assertEquals(graph.seeds, set([38586]))
 
     def test012_add_node_already_present(self):
         self.graph1.add_node("Leonhard Euler", "Universitaet Basel", 1726,
@@ -108,7 +107,7 @@ class TestGraphMethods(unittest.TestCase):
         node = Node(record, set(), set())
         self.graph1.add_node_object(node)
         self.assertEquals([38586, 18231], self.graph1.get_node_list())
-        self.assertEquals(self.graph1.seeds, set([self.node1]))
+        self.assertEquals(self.graph1.seeds, set([18231]))
 
     def test014_generate_dot_file(self):
         # Test the generate_dot_file() method.

-- 
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