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/GrampsDbTestBase.py
|
|
|
|
# $Id$
|
|
|
|
|
2005-12-19 19:15:05 +05:30
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
import shutil
|
|
|
|
import time
|
|
|
|
import traceback
|
|
|
|
import sys
|
|
|
|
|
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('../gramps')
|
2005-12-19 19:15:05 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
set()
|
|
|
|
except NameError:
|
|
|
|
from sets import Set as set
|
|
|
|
|
2012-10-03 03:29:59 +05:30
|
|
|
from gramps.gen.db import DbBsddb
|
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
|
|
|
from gramps.cli.clidbman import CLIDbManager
|
|
|
|
import gramps.gen.const
|
|
|
|
import gramps.gen.lib
|
2005-12-19 19:15:05 +05:30
|
|
|
|
|
|
|
logger = logging.getLogger('Gramps.GrampsDbTestBase')
|
|
|
|
|
|
|
|
class GrampsDbBaseTest(unittest.TestCase):
|
|
|
|
"""Base class for unittest that need to be able to create
|
|
|
|
test databases."""
|
|
|
|
|
|
|
|
def setUp(self):
|
2006-11-12 03:16:22 +05:30
|
|
|
def dummy_callback(dummy):
|
|
|
|
pass
|
2005-12-19 19:15:05 +05:30
|
|
|
self._tmpdir = tempfile.mkdtemp()
|
2009-12-23 21:18:01 +05:30
|
|
|
#self._filename = os.path.join(self._tmpdir,'test.grdb')
|
2005-12-19 19:15:05 +05:30
|
|
|
|
2009-12-23 21:18:01 +05:30
|
|
|
self._db = DbBsddb()
|
|
|
|
dbman = CLIDbManager(None)
|
|
|
|
self._filename, title = dbman.create_new_db_cli(title="Test")
|
2006-11-12 03:16:22 +05:30
|
|
|
self._db.load(self._filename, dummy_callback, "w")
|
2005-12-19 19:15:05 +05:30
|
|
|
|
|
|
|
def tearDown(self):
|
2006-11-24 10:51:57 +05:30
|
|
|
self._db.close()
|
2005-12-19 19:15:05 +05:30
|
|
|
shutil.rmtree(self._tmpdir)
|
|
|
|
|
|
|
|
def _populate_database(self,
|
|
|
|
num_sources = 1,
|
|
|
|
num_persons = 0,
|
|
|
|
num_families = 0,
|
|
|
|
num_events = 0,
|
|
|
|
num_places = 0,
|
|
|
|
num_media_objects = 0,
|
|
|
|
num_links = 1):
|
|
|
|
|
|
|
|
# start with sources
|
|
|
|
sources = []
|
2008-02-24 19:25:55 +05:30
|
|
|
for i in xrange(0, num_sources):
|
2005-12-19 19:15:05 +05:30
|
|
|
sources.append(self._add_source())
|
|
|
|
|
|
|
|
# now for each of the other tables. Give each entry a link
|
|
|
|
# to num_link sources, sources are chosen on a round robin
|
|
|
|
# basis
|
|
|
|
|
|
|
|
for num, add_func in ((num_persons, self._add_person_with_sources),
|
|
|
|
(num_families, self._add_family_with_sources),
|
|
|
|
(num_events, self._add_event_with_sources),
|
|
|
|
(num_places, self._add_place_with_sources),
|
|
|
|
(num_media_objects, self._add_media_object_with_sources)):
|
|
|
|
|
|
|
|
source_idx = 1
|
2008-02-24 19:25:55 +05:30
|
|
|
for person_idx in xrange(0, num):
|
2005-12-19 19:15:05 +05:30
|
|
|
|
|
|
|
# Get the list of sources to link
|
|
|
|
lnk_sources = set()
|
2008-02-24 19:25:55 +05:30
|
|
|
for i in xrange(0, num_links):
|
2005-12-19 19:15:05 +05:30
|
|
|
lnk_sources.add(sources[source_idx-1])
|
|
|
|
source_idx = (source_idx+1) % len(sources)
|
|
|
|
|
|
|
|
try:
|
|
|
|
add_func(lnk_sources)
|
|
|
|
except:
|
|
|
|
print "person_idx = ", person_idx
|
|
|
|
print "lnk_sources = ", repr(lnk_sources)
|
|
|
|
raise
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2005-12-22 17:32:06 +05:30
|
|
|
def _add_source(self,repos=None):
|
2005-12-19 19:15:05 +05:30
|
|
|
# Add a Source
|
|
|
|
|
|
|
|
tran = self._db.transaction_begin()
|
2009-12-23 21:18:01 +05:30
|
|
|
source = gen.lib.Source()
|
2009-02-24 00:41:46 +05:30
|
|
|
if repos is not None:
|
2009-12-23 21:18:01 +05:30
|
|
|
repo_ref = gen.lib.RepoRef()
|
2005-12-22 17:32:06 +05:30
|
|
|
repo_ref.set_reference_handle(repos.get_handle())
|
|
|
|
source.add_repo_reference(repo_ref)
|
2005-12-19 19:15:05 +05:30
|
|
|
self._db.add_source(source,tran)
|
|
|
|
self._db.commit_source(source,tran)
|
|
|
|
self._db.transaction_commit(tran, "Add Source")
|
|
|
|
|
|
|
|
return source
|
|
|
|
|
2005-12-22 17:32:06 +05:30
|
|
|
def _add_repository(self):
|
|
|
|
# Add a Repository
|
|
|
|
|
|
|
|
tran = self._db.transaction_begin()
|
2009-12-23 21:18:01 +05:30
|
|
|
repos = gen.lib.Repository()
|
2005-12-22 17:32:06 +05:30
|
|
|
self._db.add_repository(repos,tran)
|
|
|
|
self._db.commit_repository(repos,tran)
|
|
|
|
self._db.transaction_commit(tran, "Add Repository")
|
|
|
|
|
|
|
|
return repos
|
|
|
|
|
2005-12-19 19:15:05 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def _add_object_with_source(self,sources, object_class,add_method,commit_method):
|
2005-12-19 19:15:05 +05:30
|
|
|
|
|
|
|
object = object_class()
|
|
|
|
|
|
|
|
for source in sources:
|
2009-12-23 21:18:01 +05:30
|
|
|
src_ref = gen.lib.SourceRef()
|
2006-11-16 09:32:28 +05:30
|
|
|
src_ref.set_reference_handle(source.get_handle())
|
2005-12-19 19:15:05 +05:30
|
|
|
object.add_source_reference(src_ref)
|
|
|
|
|
|
|
|
|
|
|
|
tran = self._db.transaction_begin()
|
|
|
|
add_method(object,tran)
|
|
|
|
commit_method(object,tran)
|
|
|
|
self._db.transaction_commit(tran, "Add Object")
|
|
|
|
|
|
|
|
return object
|
|
|
|
|
|
|
|
def _add_person_with_sources(self,sources):
|
|
|
|
|
|
|
|
return self._add_object_with_source(sources,
|
2009-12-23 21:18:01 +05:30
|
|
|
gen.lib.Person,
|
2005-12-19 19:15:05 +05:30
|
|
|
self._db.add_person,
|
|
|
|
self._db.commit_person)
|
|
|
|
|
|
|
|
def _add_family_with_sources(self,sources):
|
|
|
|
|
|
|
|
return self._add_object_with_source(sources,
|
2009-12-23 21:18:01 +05:30
|
|
|
gen.lib.Family,
|
2005-12-19 19:15:05 +05:30
|
|
|
self._db.add_family,
|
|
|
|
self._db.commit_family)
|
|
|
|
|
|
|
|
def _add_event_with_sources(self,sources):
|
|
|
|
|
|
|
|
return self._add_object_with_source(sources,
|
2009-12-23 21:18:01 +05:30
|
|
|
gen.lib.Event,
|
2005-12-19 19:15:05 +05:30
|
|
|
self._db.add_event,
|
|
|
|
self._db.commit_event)
|
|
|
|
|
|
|
|
def _add_place_with_sources(self,sources):
|
|
|
|
|
|
|
|
return self._add_object_with_source(sources,
|
2009-12-23 21:18:01 +05:30
|
|
|
gen.lib.Place,
|
2005-12-19 19:15:05 +05:30
|
|
|
self._db.add_place,
|
|
|
|
self._db.commit_place)
|
|
|
|
|
|
|
|
def _add_media_object_with_sources(self,sources):
|
|
|
|
|
|
|
|
return self._add_object_with_source(sources,
|
2009-12-23 21:18:01 +05:30
|
|
|
gen.lib.MediaObject,
|
2005-12-19 19:15:05 +05:30
|
|
|
self._db.add_object,
|
|
|
|
self._db.commit_media_object)
|