2013-06-25 01:00:56 +05:30
|
|
|
#
|
|
|
|
# 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/GrampsDb/GrampsDbBase_Test.py
|
|
|
|
# $Id$
|
|
|
|
|
2005-12-16 17:29:13 +05:30
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
import shutil
|
2005-12-16 22:01:38 +05:30
|
|
|
import time
|
2005-12-18 02:43:45 +05:30
|
|
|
import traceback
|
2005-12-16 17:29:13 +05:30
|
|
|
import sys
|
2005-12-18 02:43:45 +05:30
|
|
|
|
Reviving RunAllTests.py on gramps40/trunk
Porting from gramps34 my fix for 6935, 6937, 6938.
Import with full "gramps." qualification from the tests,
to overcome the relative import problem (see bug# 6938 for context).
All testing code has been adjusted to the filename and paths
changes since gramps34.
Same as on gramps34, one test fails still, will investigate if
it is a test or a code bug:
ERROR: test_buffer_recall
(ErrorReportAssistant_Test.ErrorReportAssistantTest)
Test that simple recall of messages works.
----------------------------------------------------------------------
Traceback (most recent call last):
File "./GrampsLogger/ErrorReportAssistant_Test.py", line 60, in
test_buffer_recall
rotate_handler=rh)
File "../gramps/gui/logger/_errorreportassistant.py", line 81, in
__init__
self.build_page1()
File "../gramps/gui/logger/_errorreportassistant.py", line 267, in
build_page1
self._reset_error_details()
File "../gramps/gui/logger/_errorreportassistant.py", line 178, in
_reset_error_details
self._error_detail.get_record()))
AttributeError: 'str' object has no attribute 'get_record'
svn: r22729
2013-07-24 11:53:33 +05:30
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '../../gramps'))
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2005-12-18 02:43:45 +05:30
|
|
|
try:
|
|
|
|
set()
|
|
|
|
except NameError:
|
2005-12-18 02:49:41 +05:30
|
|
|
from sets import Set as set
|
2005-12-21 16:57:05 +05:30
|
|
|
|
Reviving RunAllTests.py on gramps40/trunk
Porting from gramps34 my fix for 6935, 6937, 6938.
Import with full "gramps." qualification from the tests,
to overcome the relative import problem (see bug# 6938 for context).
All testing code has been adjusted to the filename and paths
changes since gramps34.
Same as on gramps34, one test fails still, will investigate if
it is a test or a code bug:
ERROR: test_buffer_recall
(ErrorReportAssistant_Test.ErrorReportAssistantTest)
Test that simple recall of messages works.
----------------------------------------------------------------------
Traceback (most recent call last):
File "./GrampsLogger/ErrorReportAssistant_Test.py", line 60, in
test_buffer_recall
rotate_handler=rh)
File "../gramps/gui/logger/_errorreportassistant.py", line 81, in
__init__
self.build_page1()
File "../gramps/gui/logger/_errorreportassistant.py", line 267, in
build_page1
self._reset_error_details()
File "../gramps/gui/logger/_errorreportassistant.py", line 178, in
_reset_error_details
self._error_detail.get_record()))
AttributeError: 'str' object has no attribute 'get_record'
svn: r22729
2013-07-24 11:53:33 +05:30
|
|
|
import gramps.gen.lib
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
|
|
|
|
|
2005-12-19 19:15:05 +05:30
|
|
|
from GrampsDbTestBase import GrampsDbBaseTest
|
2005-12-21 16:57:05 +05:30
|
|
|
|
2005-12-19 19:15:05 +05:30
|
|
|
class ReferenceMapTest (GrampsDbBaseTest):
|
|
|
|
"""Test methods on the GrampsDbBase class that are related to the reference_map
|
|
|
|
index implementation."""
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
def test_simple_lookup(self):
|
|
|
|
"""insert a record and a reference and check that
|
|
|
|
a lookup for the reference returns the original
|
|
|
|
record."""
|
|
|
|
|
2005-12-16 22:01:38 +05:30
|
|
|
source = self._add_source()
|
|
|
|
person = self._add_person_with_sources([source])
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(source.get_handle()))
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
assert len(references) == 1
|
2009-12-23 21:18:01 +05:30
|
|
|
assert references[0] == (gen.lib.Person.__name__,person.get_handle())
|
2005-12-18 03:46:03 +05:30
|
|
|
|
2005-12-22 17:32:06 +05:30
|
|
|
def test_backlink_for_repository(self):
|
|
|
|
"""check that the source / repos backlink lookup works."""
|
|
|
|
|
|
|
|
repos = self._add_repository()
|
|
|
|
source = self._add_source(repos=repos)
|
|
|
|
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(repos.get_handle()))
|
2005-12-22 17:32:06 +05:30
|
|
|
|
|
|
|
assert len(references) == 1
|
2009-12-23 21:18:01 +05:30
|
|
|
assert references[0] == (gen.lib.Source.__name__,source.get_handle())
|
2005-12-22 17:32:06 +05:30
|
|
|
|
2005-12-18 03:46:03 +05:30
|
|
|
def test_class_limited_lookup(self):
|
|
|
|
"""check that class limited lookups work."""
|
|
|
|
|
|
|
|
source = self._add_source()
|
|
|
|
person = self._add_person_with_sources([source])
|
|
|
|
|
|
|
|
self._add_family_with_sources([source])
|
|
|
|
self._add_event_with_sources([source])
|
|
|
|
self._add_place_with_sources([source])
|
|
|
|
self._add_media_object_with_sources([source])
|
|
|
|
|
|
|
|
# make sure that we have the correct number of references (one for each object)
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(source.get_handle()))
|
2005-12-18 03:46:03 +05:30
|
|
|
|
|
|
|
assert len(references) == 5, "len(references) == %s " % str(len(references))
|
|
|
|
|
|
|
|
# should just return the person reference
|
2009-12-23 21:18:01 +05:30
|
|
|
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(gen.lib.Person.__name__,)) ]
|
2005-12-18 03:46:03 +05:30
|
|
|
assert len(references) == 1, "len(references) == %s " % str(len(references))
|
2009-12-23 21:18:01 +05:30
|
|
|
assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references)
|
2005-12-18 03:46:03 +05:30
|
|
|
|
|
|
|
# should just return the person and event reference
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(source.get_handle(),
|
|
|
|
(gen.lib.Person.__name__, gen.lib.Event.__name__)))
|
2005-12-18 03:46:03 +05:30
|
|
|
assert len(references) == 2, "len(references) == %s " % str(len(references))
|
2009-12-23 21:18:01 +05:30
|
|
|
assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references)
|
|
|
|
assert references[1][0] == gen.lib.Event.__name__, "references = %s" % repr(references)
|
2005-12-18 03:46:03 +05:30
|
|
|
|
|
|
|
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
def test_delete_primary(self):
|
|
|
|
"""check that deleting a primary will remove the backreferences
|
|
|
|
from the reference_map"""
|
|
|
|
|
2005-12-16 22:01:38 +05:30
|
|
|
source = self._add_source()
|
|
|
|
person = self._add_person_with_sources([source])
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
assert self._db.get_person_from_handle(person.get_handle()) is not None
|
|
|
|
|
|
|
|
tran = self._db.transaction_begin()
|
|
|
|
self._db.remove_person(person.get_handle(),tran)
|
|
|
|
self._db.transaction_commit(tran, "Del Person")
|
|
|
|
|
2009-02-24 00:41:46 +05:30
|
|
|
assert self._db.get_person_from_handle(person.get_handle()) is None
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(source.get_handle()))
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
assert len(references) == 0, "len(references) == %s " % str(len(references))
|
|
|
|
|
|
|
|
|
|
|
|
def test_reindex_reference_map(self):
|
|
|
|
"""Test that the reindex function works."""
|
|
|
|
|
2006-12-13 15:33:52 +05:30
|
|
|
def cb(count):
|
|
|
|
pass
|
|
|
|
|
2005-12-16 17:29:13 +05:30
|
|
|
# unhook the reference_map update function so that we
|
|
|
|
# can insert some records without the reference_map being updated.
|
2009-12-23 21:18:01 +05:30
|
|
|
update_method = self._db.update_reference_map
|
2006-11-24 11:09:14 +05:30
|
|
|
self._db._update_reference_map = lambda x,y: 1
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
# Insert a person/source pair.
|
2005-12-16 22:01:38 +05:30
|
|
|
source = self._add_source()
|
|
|
|
person = self._add_person_with_sources([source])
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
# Check that the reference map does not contain the reference.
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(source.get_handle()))
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
assert len(references) == 0, "len(references) == %s " % str(len(references))
|
|
|
|
|
|
|
|
# Reinstate the reference_map method and reindex the database
|
|
|
|
self._db._update_reference_map = update_method
|
2006-12-13 15:33:52 +05:30
|
|
|
self._db.reindex_reference_map(cb)
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
# Check that the reference now appears in the reference_map
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(source.get_handle()))
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
assert len(references) == 1, "len(references) == %s " % str(len(references))
|
|
|
|
|
|
|
|
|
2005-12-16 22:01:38 +05:30
|
|
|
|
2005-12-18 02:43:45 +05:30
|
|
|
def perf_simple_search_speed(self):
|
|
|
|
|
|
|
|
num_sources = 100
|
|
|
|
num_persons = 1000
|
|
|
|
num_families = 10
|
|
|
|
num_events = 10
|
|
|
|
num_places = 10
|
|
|
|
num_media_objects = 10
|
|
|
|
num_links = 10
|
2005-12-16 22:01:38 +05:30
|
|
|
|
2005-12-18 02:43:45 +05:30
|
|
|
self._populate_database(num_sources,
|
|
|
|
num_persons,
|
|
|
|
num_families,
|
|
|
|
num_events,
|
|
|
|
num_places,
|
|
|
|
num_media_objects,
|
|
|
|
num_links)
|
2005-12-16 22:01:38 +05:30
|
|
|
|
|
|
|
|
|
|
|
# time searching for source backrefs with and without reference_map
|
|
|
|
cur = self._db.get_source_cursor()
|
|
|
|
handle,data = cur.first()
|
|
|
|
cur.close()
|
|
|
|
|
|
|
|
start = time.time()
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(handle))
|
2005-12-16 22:01:38 +05:30
|
|
|
end = time.time()
|
|
|
|
|
|
|
|
with_reference_map = end - start
|
|
|
|
|
|
|
|
remember = self._db.__class__.find_backlink_handles
|
|
|
|
|
|
|
|
self._db.__class__.find_backlink_handles = self._db.__class__.__base__.find_backlink_handles
|
|
|
|
|
|
|
|
start = time.time()
|
2010-01-22 00:12:53 +05:30
|
|
|
references = list(self._db.find_backlink_handles(handle))
|
2005-12-16 22:01:38 +05:30
|
|
|
end = time.time()
|
|
|
|
|
|
|
|
without_reference_map = end - start
|
|
|
|
|
|
|
|
self._db.__class__.find_backlink_handles = remember
|
2005-12-18 02:43:45 +05:30
|
|
|
|
|
|
|
logger.info("search test with following data: \n"
|
|
|
|
"num_sources = %d \n"
|
|
|
|
"num_persons = %d \n"
|
|
|
|
"num_families = %d \n"
|
|
|
|
"num_events = %d \n"
|
|
|
|
"num_places = %d \n"
|
|
|
|
"num_media_objects = %d \n"
|
|
|
|
"num_links = %d" % (num_sources,
|
|
|
|
num_persons,
|
|
|
|
num_families,
|
|
|
|
num_events,
|
|
|
|
num_places,
|
|
|
|
num_media_objects,
|
|
|
|
num_links))
|
2005-12-16 22:01:38 +05:30
|
|
|
logger.info("with refs %s\n", str(with_reference_map))
|
|
|
|
logger.info("without refs %s\n", str(without_reference_map))
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2005-12-16 22:01:38 +05:30
|
|
|
assert with_reference_map < (without_reference_map / 10), "Reference_map should an order of magnitude faster."
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
def testSuite():
|
2005-12-19 19:15:05 +05:30
|
|
|
suite = unittest.makeSuite(ReferenceMapTest,'test')
|
|
|
|
return suite
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2005-12-18 02:43:45 +05:30
|
|
|
def perfSuite():
|
|
|
|
return unittest.makeSuite(ReferenceMapTest,'perf')
|
|
|
|
|
2005-12-16 17:29:13 +05:30
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.TextTestRunner().run(testSuite())
|