7034: probably_alive() failing when no birth-death
Preparing to fix the bug: refactor cut-n-paste traces in probably_alive, proper proxy access minor bug with return_range handling add testing ground svn: r23005
This commit is contained in:
parent
1424d3d20f
commit
ef159eb6f1
13
src/Utils.py
13
src/Utils.py
@ -970,19 +970,14 @@ def probably_alive(person, db,
|
||||
:param max_age_prob_alive: maximum age of a person, in years
|
||||
:param avg_generation_gap: average generation gap, in years
|
||||
"""
|
||||
# First, get the real database to use all people
|
||||
# for determining alive status:
|
||||
basedb = db.basedb
|
||||
# Now, we create a wrapper for doing work:
|
||||
pb = ProbablyAlive(basedb, max_sib_age_diff,
|
||||
max_age_prob_alive,
|
||||
avg_generation_gap)
|
||||
birth, death, explain, relative = pb.probably_alive_range(person)
|
||||
birth, death, explain, relative = probably_alive_range(person, db,
|
||||
max_sib_age_diff, max_age_prob_alive, avg_generation_gap)
|
||||
if current_date is None:
|
||||
current_date = gen.lib.date.Today()
|
||||
if not birth or not death:
|
||||
# no evidence, must consider alive
|
||||
return (True, None, None, _("no evidence"), None)
|
||||
return (True, None, None, _("no evidence"), None) if return_range \
|
||||
else True
|
||||
# must have dates from here:
|
||||
if limit:
|
||||
death += limit # add these years to death
|
||||
|
72
src/test/alive_test.py
Normal file
72
src/test/alive_test.py
Normal file
@ -0,0 +1,72 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2013 Vassilii Khachaturov
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id$
|
||||
|
||||
""" Unittest for Utils.probably_alive ... """
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
try:
|
||||
if sys.version_info < (3,3):
|
||||
from mock import Mock, patch
|
||||
else:
|
||||
from unittest.mock import Mock, patch
|
||||
MOCKING = True
|
||||
except:
|
||||
MOCKING = False
|
||||
print ("Mocking disabled", sys.exc_info()[0:2])
|
||||
|
||||
from test import test_util
|
||||
test_util.path_append_parent()
|
||||
import Utils
|
||||
from gen.lib import Person, Name, Date, Event, EventRef
|
||||
|
||||
class Test_probably_alive(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.db = Mock()
|
||||
def tearDown(self):
|
||||
self.db.assert_has_calls([])
|
||||
|
||||
def testAliveWithoutEvidence(self):
|
||||
person = Mock()
|
||||
with patch('Utils.probably_alive_range',
|
||||
# birth, death, explain, relative
|
||||
Mock(return_value=(None, None, None, None)),
|
||||
) as MockPAR:
|
||||
result = Utils.probably_alive(person, self.db)
|
||||
self.assertFalse(isinstance(result, tuple))
|
||||
self.assertTrue(result)
|
||||
MockPAR.assert_called_once()
|
||||
|
||||
def testAliveWithoutEvidenceRange(self):
|
||||
person = Mock()
|
||||
with patch('Utils.probably_alive_range',
|
||||
# birth, death, explain, relative
|
||||
Mock(return_value=(None, None, None, None)),
|
||||
) as MockPAR:
|
||||
result = Utils.probably_alive(person, self.db, return_range=True)
|
||||
self.assertTrue(isinstance(result, tuple))
|
||||
self.assertEqual(len(result), 5)
|
||||
self.assertTrue(result[0])
|
||||
MockPAR.assert_called_once()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,82 +0,0 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# test/test/gedread_util_test.py
|
||||
# $Id$
|
||||
|
||||
"""test for test/gedread_util.py
|
||||
|
||||
also illustrates basic use
|
||||
"""
|
||||
|
||||
import os
|
||||
import unittest as U
|
||||
import logging
|
||||
|
||||
from test import test_util as tu
|
||||
from test import gedread_util as gr
|
||||
|
||||
|
||||
class Test(U.TestCase):
|
||||
def setUp(self):
|
||||
# make a dir to hold an input gedcom file
|
||||
self.tdir = tu.make_subdir("gr_test")
|
||||
|
||||
def test1(self):
|
||||
prec="""
|
||||
0 @I1@ INDI
|
||||
1 NAME GedRead TEST /Person/
|
||||
"""
|
||||
|
||||
# create a gedcom input file
|
||||
# from canned head/tail -- see gedread_util
|
||||
infil = os.path.join(self.tdir,"test_in.ged")
|
||||
gr.make_gedcom_input(infil, prec)
|
||||
self.assertTrue(os.path.isfile(infil),
|
||||
"create input file %s" % infil)
|
||||
|
||||
# create an empty database
|
||||
dbpath = os.path.join(self.tdir,"test_db")
|
||||
db = gr.create_empty_db(dbpath)
|
||||
self.assertTrue(os.path.isdir(dbpath),
|
||||
"create database (dir) %s" % dbpath)
|
||||
|
||||
# create logfile to test for read log-messages
|
||||
# (note: uses recently added test_util
|
||||
log = os.path.join(self.tdir, "test_log")
|
||||
tl = tu.TestLogger()
|
||||
tl.logfile_init(log)
|
||||
# now read the gedcom
|
||||
gr.gread(db, infil)
|
||||
logging.warn("nothing here")
|
||||
loglines = tl.logfile_getlines()
|
||||
#NB incorrect SUBM handling causes one extraneous warning
|
||||
xWarns = 1
|
||||
self.assertEquals(len(loglines),1 + xWarns,
|
||||
"log has no unexpected content")
|
||||
# verify one person in database
|
||||
np = db.get_number_of_people()
|
||||
self.assertEquals(np,1,
|
||||
tu.msg(np,1, "db has exactly one person"))
|
||||
db.close()
|
||||
del tl
|
||||
|
||||
if __name__ == "__main__":
|
||||
U.main()
|
@ -60,5 +60,6 @@ def suite1():
|
||||
suite.addTest(TestCase('translation-%04d', 'translation', upper, keyword.upper()))
|
||||
return suite
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.TextTestRunner().run(suite1())
|
||||
|
Loading…
Reference in New Issue
Block a user