Unit test python3 fixes

svn: r22782
This commit is contained in:
Nick Hall 2013-07-30 22:06:29 +00:00
parent adb63c0c5e
commit c8c0164038
4 changed files with 22 additions and 25 deletions

View File

@ -22,14 +22,16 @@
import unittest
import os
import sys
import tempfile
import shutil
from bsddb import dbshelve, db
try:
set()
except NameError:
from sets import Set as set
from ...constfunc import UNITYPE
from ...config import config
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
from bsddb3 import dbshelve, db
else:
from bsddb import dbshelve, db
class Data(object):
@ -81,7 +83,7 @@ class CursorTest(unittest.TestCase):
dbmap = dbshelve.DBShelf(self.env)
dbmap.db.set_pagesize(16384)
dbmap.open(self.full_name, 'person', db.DB_HASH,
db.DB_CREATE|db.DB_AUTO_COMMIT, 0666)
db.DB_CREATE|db.DB_AUTO_COMMIT, 0o666)
person_map = dbmap
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
@ -92,7 +94,10 @@ class CursorTest(unittest.TestCase):
flags=table_flags)
def find_surname(key,data):
return data.surname
val = data.surname
if isinstance(val, UNITYPE):
val = val.encode('utf-8')
return val
person_map.associate(surnames, find_surname, table_flags)
@ -104,7 +109,7 @@ class CursorTest(unittest.TestCase):
def test_simple_insert(self):
"""test insert and retrieve works."""
data = Data(str(1),'surname1','name1')
data = Data(b'1' ,'surname1', 'name1')
the_txn = self.env.txn_begin()
self.person_map.put(data.handle, data, txn=the_txn)
the_txn.commit()
@ -124,7 +129,7 @@ class CursorTest(unittest.TestCase):
cursor.close()
cursor_txn.commit()
data = Data(str(2), 'surname2', 'name2')
data = Data(b'2', 'surname2', 'name2')
the_txn = self.env.txn_begin()
self.person_map.put(data.handle, data, txn=the_txn)
the_txn.commit()
@ -142,7 +147,7 @@ class CursorTest(unittest.TestCase):
cursor.first()
cursor.next()
data = Data(str(2),'surname2', 'name2')
data = Data(b'2', 'surname2', 'name2')
the_txn = self.env.txn_begin()
self.person_map.put(data.handle, data, txn=the_txn)
the_txn.commit()
@ -165,7 +170,7 @@ class CursorTest(unittest.TestCase):
cursor.first()
cursor.next()
data = Data(str(2),'surname2', 'name2')
data = Data(b'2', 'surname2', 'name2')
the_txn = self.env.txn_begin()
self.person_map.put(data.handle, data, txn=the_txn)
the_txn.commit()

View File

@ -20,15 +20,12 @@
# $Id$
from __future__ import print_function
import unittest
import tempfile
import shutil
try:
set()
except NameError:
from sets import Set as set
from gramps.gen.db import DbBsddb, DbTxn
from gramps.cli.clidbman import CLIDbManager
from gramps.gen.lib import (Source, RepoRef, Citation, Repository, Person,
@ -88,8 +85,8 @@ class GrampsDbBaseTest(unittest.TestCase):
try:
add_func(lnk_sources)
except:
print "person_idx = ", person_idx
print "lnk_sources = ", repr(lnk_sources)
print ("person_idx = ", person_idx)
print ("lnk_sources = ", repr(lnk_sources))
raise
return

View File

@ -24,17 +24,12 @@ import unittest
import logging
import time
try:
set()
except NameError:
from sets import Set as set
from .. import DbTxn
from ...lib import Person, Event, Source, Citation
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
from grampsdbtestbase import GrampsDbBaseTest
from .grampsdbtestbase import GrampsDbBaseTest
class ReferenceMapTest(GrampsDbBaseTest):
"""Test methods on the GrampsDbBase class that are related to the reference_map

View File

@ -402,7 +402,7 @@ class EventRefCheck(unittest.TestCase, PrivacyBaseTest, NoteBaseTest,
self.phoenix.add_attribute(attr1)
self.ref_obj.add_attribute(attr2)
self.phoenix.replace_citation_references('234567','654321')
self.assert_(self.phoenix.is_equal(self.ref_obj))
self.assertTrue(self.phoenix.is_equal(self.ref_obj))
class FamilyCheck(unittest.TestCase, PrivacyBaseTest, NoteBaseTest,
CitationBaseTest, MediaBaseTest, AttrBaseTest):