Fix top level test files so they at least compile and don't interfere

with nosetests. Add these files to nosetests.
This commit is contained in:
kulath 2016-08-19 21:10:07 +01:00
parent 022eefd7e8
commit fbb884b6ea
5 changed files with 191 additions and 134 deletions

View File

@ -61,7 +61,7 @@ install:
# by the automatic git checkout.
# Download Sean Ross-Ross's Pure Python module containing a framework to
# manipulate and analyze python astÕs and bytecode. This is loaded to
# manipulate and analyze python ast<EFBFBD>s and bytecode. This is loaded to
# /home/travis/build/gramps-project/gramps/meta
# FIXME: This should be loaded from the release directory at
# https://pypi.python.org/pypi/meta
@ -88,7 +88,8 @@ script:
# Ignore the virtualenv entirely. Use nosetests3, python3 (3.4.0) and coverage
# from /usr/bin. Use libraries from /usr/lib/python3.4,
# /usr/local/lib/python3.4/dist-packages and /usr/lib/python3/dist-packages
- nosetests3 --nologcapture --with-coverage --cover-package=gramps $EXCLUDE gramps
- nosetests3 --nologcapture --with-coverage --cover-package=gramps $EXCLUDE
gramps test test/GrampsLogger
# FIXME: This should have run from the current directory, rather than from
# gramps, because there is some test code in that directory.

View File

@ -56,13 +56,14 @@ class GtkHandlerTest(unittest.TestCase):
l.warn("A warn message")
l.debug("A debug message")
log_message = "Debug message"
try:
wibble
except:
l.error(log_message,exc_info=True)
while Gtk.events_pending():
Gtk.main_iteration()
# Comment this out because there is noone to close the dialogue
# try:
# wibble
# except:
# l.error(log_message,exc_info=True)
#
# while Gtk.events_pending():
# Gtk.main_iteration()

View File

@ -20,14 +20,15 @@
# test/LosHawlos_bsddbtest.py
from bsddb import dbshelve, db
from bsddb3 import dbshelve, db
import os
import sys
sys.path.append('../gramps')
import const
import gramps.gen.const as const
env_name = os.path.expanduser(const.bsddbenv_dir)
print("Test that db.DBEnv().open() works")
env_name = os.path.expanduser(os.path.join(const.HOME_DIR, "test"))
if not os.path.isdir(env_name):
os.mkdir(env_name)
@ -35,14 +36,32 @@ env = db.DBEnv()
env.set_cachesize(0,0x2000000)
env.set_lk_max_locks(25000)
env.set_lk_max_objects(25000)
env.set_flags(db.DB_LOG_AUTOREMOVE,1)
# env.set_flags(db.DB_LOG_AUTOREMOVE,1)
"""
BSDDB change log settings using new method with renamed attributes
"""
autoremove_flag = None
autoremove_method = None
for flag in ["DB_LOG_AUTO_REMOVE", "DB_LOG_AUTOREMOVE"]:
if hasattr(db, flag):
autoremove_flag = getattr(db, flag)
break
for method in ["log_set_config", "set_flags"]:
if hasattr(env, method):
autoremove_method = getattr(env, method)
break
if autoremove_method and autoremove_flag:
autoremove_method(autoremove_flag, 1)
else:
print("Failed to set autoremove flag")
env_flags = db.DB_CREATE|db.DB_RECOVER|db.DB_PRIVATE|\
db.DB_INIT_MPOOL|db.DB_INIT_LOCK|\
db.DB_INIT_LOG|db.DB_INIT_TXN|db.DB_THREAD
try:
env.open(env_name,env_flags)
except db.DBRunRecoveryError, e:
print "Exception: "
print e
except db.DBRunRecoveryError as e:
print("Exception: ")
print(e)
env.remove(env_name)
env.open(env_name,env_flags)
print("OK")

154
test/LosHawlos_db_test.py Normal file
View File

@ -0,0 +1,154 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2016 Tim G L Lyons
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# test/LosHawlos_dbtest.py
"""
Simple test for bsdbd. Minimal adaptations made (2016) from original version to
make the code compile and run under nosetests (unittest). This runs from the
root github directory with a command line like:
nosetests gramps test
where gramps is the directory containing most of the Gramps code, and this file
is in the directory 'test'
"""
import os
import tempfile
import shutil
import sys
from gramps.gen.dbstate import DbState
from gramps.cli.clidbman import CLIDbManager
from gramps.gen.db.base import DbTxn
from gramps.gen.errors import DbError, HandleError
import gramps.gen.const as const
import gramps.gen.lib as RelLib
print(sys.path)
tran = None
def dummy_callback(dummy):
pass
def add_source( db,title,commit=True,fail=False):
global tran
if tran is None:
tran = db.transaction_begin(DbTxn("add source", db))
db.disable_signals()
s = RelLib.Source()
db.add_source(s,tran)
s.set_title(title)
if fail:
return # Fail here
db.commit_source(s,tran)
db.enable_signals()
if commit:
db.transaction_commit(tran)
tran = None
def add_person( db,firstname,lastname,commit=True,fail=False):
global tran
if tran is None:
tran = db.transaction_begin(DbTxn("add person", db))
db.disable_signals()
p = RelLib.Person()
db.add_person(p,tran)
n = RelLib.Name()
n.set_first_name(firstname)
s = RelLib.Surname()
s.set_surname(lastname)
n.add_surname(s)
p.set_primary_name(n)
if fail:
return # Fail here
db.commit_person(p,tran)
db.enable_signals()
if commit:
db.transaction_commit(tran)
tran = None
def print_db_content(db):
for h in db.get_person_handles():
print("DB contains: person %s" % h)
for h in db.get_source_handles():
print("DB contains: source %s" % h)
tmpdir = tempfile.mkdtemp()
try:
filename1 = os.path.join(tmpdir,'test1.grdb')
filename2 = os.path.join(tmpdir,'test2.grdb')
print("\nUsing Database file: %s" % filename1)
dbstate = DbState()
dbman = CLIDbManager(dbstate)
dirpath, name = dbman.create_new_db_cli(filename1, dbid="bsddb")
db = dbstate.make_database("bsddb")
db.load(dirpath, None)
print("Add person 1")
add_person( db,"Anton", "Albers",True,False)
print("Add source")
add_source( db,"A short test",True,False)
print("Add person 2 without commit")
add_person( db,"Bernd","Beta",False,False)
print("Add source")
add_source( db,"A short test",True,False)
print("Add person 3")
add_person( db,"Chris","Connor",True,False)
print_db_content( db)
print("Closing Database file: %s" % filename1)
db.close()
tran = None
print("\nUsing Database file: %s" % filename1)
dbstate = DbState()
dbman = CLIDbManager(dbstate)
dirpath, name = dbman.create_new_db_cli(filename1, dbid="bsddb")
db = dbstate.make_database("bsddb")
db.load(dirpath, None)
print("Add person 4")
add_person( db,"Felix", "Fowler",True,False)
print ("Add person 4")
add_person( db,"Felix", "Fowler",False,False)
print_db_content( db)
print("Closing Database file: %s" % filename1)
db.close()
tran = None
print("\nUsing Database file: %s" % filename2)
dbstate = DbState()
dbman = CLIDbManager(dbstate)
dirpath, name = dbman.create_new_db_cli(filename2, dbid="bsddb")
db = dbstate.make_database("bsddb")
db.load(dirpath, None)
print("Add source")
add_source( db,"A short test",False,False)
# actually, adding a second source while the first transaction is not
# committed will just add the second source to the first transaction, so
# nothing special will fail.
print("Add source 2 will fail; but I don't see why it should")
add_source( db,"Bang bang bang",True,True)
print_db_content( db)
print("Closing Database file: %s" % filename2)
db.close()
finally:
print("Exit. Cleaning up.")
shutil.rmtree(tmpdir)

View File

@ -1,118 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# test/LosHawlos_dbtest.py
import os
import tempfile
import shutil
import sys
sys.path.append('../gramps')
import GrampsDb
import const
import RelLib
def dummy_callback(dummy):
pass
def add_source( db,title,commit=True,fail=False):
tran = db.transaction_begin()
db.disable_signals()
s = RelLib.Source()
db.add_source(s,tran)
s.set_title(title)
if fail:
return # Fail here
db.commit_source(s,tran)
db.enable_signals()
if commit:
db.transaction_commit(tran, "Add Source")
def add_person( db,firstname,lastname,commit=True,fail=False):
tran = db.transaction_begin()
db.disable_signals()
p = RelLib.Person()
db.add_person(p,tran)
n = RelLib.Name()
n.set_first_name(firstname)
n.set_surname(lastname)
p.set_primary_name(n)
if fail:
return # Fail here
db.commit_person(p,tran)
db.enable_signals()
if commit:
db.transaction_commit(tran, "Add Person")
def print_db_content(db):
for h in db.get_person_handles():
print "DB contains: person %s" % h
for h in db.get_source_handles():
print "DB contains: source %s" % h
tmpdir = tempfile.mkdtemp()
try:
filename1 = os.path.join(tmpdir,'test1.grdb')
filename2 = os.path.join(tmpdir,'test2.grdb')
print "\nUsing Database file: %s" % filename1
db = GrampsDb.gramps_db_factory(const.app_gramps)()
db.load( filename1, dummy_callback, "w")
print "Add person 1"
add_person( db,"Anton", "Albers",True,False)
print "Add source"
add_source( db,"A short test",True,False)
print "Add person 2 without commit"
add_person( db,"Bernd","Beta",False,False)
print "Add source"
add_source( db,"A short test",True,False)
print "Add person 3"
add_person( db,"Chris","Connor",True,False)
print_db_content( db)
print "Closing Database file: %s" % filename1
#db.close()
print "\nUsing Database file: %s" % filename1
db = GrampsDb.gramps_db_factory(const.app_gramps)()
db.load( filename1, dummy_callback, "w")
print "Add person 4"
add_person( db,"Felix", "Fowler",True,False)
print "Add person 4"
add_person( db,"Felix", "Fowler",False,False)
print_db_content( db)
print "Closing Database file: %s" % filename1
#db.close()
print "\nUsing Database file: %s" % filename2
db = GrampsDb.gramps_db_factory(const.app_gramps)()
db.load( filename2, dummy_callback, "w")
print "Add source"
add_source( db,"A short test",False,False)
print "Add source 2 will fail"
add_source( db,"Bang bang bang",True,True)
print_db_content( db)
print "Closing Database file: %s" % filename2
#db.close()
finally:
print "Exit. Cleaning up."
shutil.rmtree(tmpdir)