[geneagrapher] 118/226: Added test for multiple advisors case, and modified code in grab.py to correctly handle the multiple advisors case.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:10:52 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 c49f206473fa114eb480b129c8dbf8cd0145d1c6
Author: David Alber <alber.david at gmail.com>
Date:   Sat Aug 29 16:42:01 2009 +0000

    Added test for multiple advisors case, and modified code in grab.py to correctly handle the multiple advisors case.
---
 geneagrapher/grab.py | 15 +++++++++++----
 tests/tests.py       | 10 ++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/geneagrapher/grab.py b/geneagrapher/grab.py
index 4e4aa3e..c344111 100644
--- a/geneagrapher/grab.py
+++ b/geneagrapher/grab.py
@@ -86,10 +86,17 @@ class Grabber:
                     self.year = int(inst_year[1].split(',')[0].strip())
 
             if 'Advisor' in line:
-                if 'a href=\"id.php?id=' in line:
-                    # Extract link to advisor page.
-                    advisor_id = int(line.split('a href=\"id.php?id=')[1].split('\">')[0])
-                    self.advisors.append(advisor_id)
+                advisorLine = line
+                while 'Advisor' in advisorLine:
+                    if 'a href=\"id.php?id=' in line:
+                        # Extract link to advisor page.
+                        advisor_id = int(advisorLine.split('a href=\"id.php?id=')[1].split('\">')[0])
+                        self.advisors.append(advisor_id)
+                        advisorLine = advisorLine.split(str(advisor_id))[1]
+                    else:
+                        # We are done. Adjust string to break the loop.
+                        # (Without this records with no advisor enter an infinite loop.)
+                        advisorLine = ""
 
             if '<tr ' in line:
                 descendant_id = int(line.split('a href=\"id.php?id=')[1].split('\">')[0])
diff --git a/tests/tests.py b/tests/tests.py
index a9d1cc2..2c742f4 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -388,6 +388,16 @@ class TestGrabberMethods(unittest.TestCase):
         self.assertEquals(advisors, [7298])
         self.assertEquals(descendents, [12681, 28292, 10275, 79297, 36991, 17851, 51907, 15165, 89841, 84016])
 
+    def test009_multiple_advisors(self):
+        # Test for multiple advisors.
+        grabber = grab.Grabber(7401)
+        [name, institution, year, advisors, descendents] = grabber.extractNodeInformation()
+        self.assertEquals(name, u"C. Felix (Christian) Klein")
+        self.assertEquals(institution, u"Rheinische Friedrich-Wilhelms-Universit\xe4t Bonn")
+        self.assertEquals(year, 1868)
+        self.assertEquals(advisors, [7402, 19964])
+        #self.assertEquals(descendents, [18603, 18233, 62547, 29642, 55175, 29458, 19953, 18232])
+
 class TestGeneagrapherMethods(unittest.TestCase):
     """
     Unit tests for the geneagrapher.Geneagrapher class.

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