Unit test python3 fixes
svn: r22782
This commit is contained in:
parent
adb63c0c5e
commit
c8c0164038
@ -22,14 +22,16 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
from bsddb import dbshelve, db
|
|
||||||
|
|
||||||
try:
|
from ...constfunc import UNITYPE
|
||||||
set()
|
from ...config import config
|
||||||
except NameError:
|
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
|
||||||
from sets import Set as set
|
from bsddb3 import dbshelve, db
|
||||||
|
else:
|
||||||
|
from bsddb import dbshelve, db
|
||||||
|
|
||||||
class Data(object):
|
class Data(object):
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ class CursorTest(unittest.TestCase):
|
|||||||
dbmap = dbshelve.DBShelf(self.env)
|
dbmap = dbshelve.DBShelf(self.env)
|
||||||
dbmap.db.set_pagesize(16384)
|
dbmap.db.set_pagesize(16384)
|
||||||
dbmap.open(self.full_name, 'person', db.DB_HASH,
|
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
|
person_map = dbmap
|
||||||
|
|
||||||
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
||||||
@ -92,7 +94,10 @@ class CursorTest(unittest.TestCase):
|
|||||||
flags=table_flags)
|
flags=table_flags)
|
||||||
|
|
||||||
def find_surname(key,data):
|
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)
|
person_map.associate(surnames, find_surname, table_flags)
|
||||||
|
|
||||||
@ -104,7 +109,7 @@ class CursorTest(unittest.TestCase):
|
|||||||
def test_simple_insert(self):
|
def test_simple_insert(self):
|
||||||
"""test insert and retrieve works."""
|
"""test insert and retrieve works."""
|
||||||
|
|
||||||
data = Data(str(1),'surname1','name1')
|
data = Data(b'1' ,'surname1', 'name1')
|
||||||
the_txn = self.env.txn_begin()
|
the_txn = self.env.txn_begin()
|
||||||
self.person_map.put(data.handle, data, txn=the_txn)
|
self.person_map.put(data.handle, data, txn=the_txn)
|
||||||
the_txn.commit()
|
the_txn.commit()
|
||||||
@ -124,7 +129,7 @@ class CursorTest(unittest.TestCase):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
cursor_txn.commit()
|
cursor_txn.commit()
|
||||||
|
|
||||||
data = Data(str(2), 'surname2', 'name2')
|
data = Data(b'2', 'surname2', 'name2')
|
||||||
the_txn = self.env.txn_begin()
|
the_txn = self.env.txn_begin()
|
||||||
self.person_map.put(data.handle, data, txn=the_txn)
|
self.person_map.put(data.handle, data, txn=the_txn)
|
||||||
the_txn.commit()
|
the_txn.commit()
|
||||||
@ -142,7 +147,7 @@ class CursorTest(unittest.TestCase):
|
|||||||
cursor.first()
|
cursor.first()
|
||||||
cursor.next()
|
cursor.next()
|
||||||
|
|
||||||
data = Data(str(2),'surname2', 'name2')
|
data = Data(b'2', 'surname2', 'name2')
|
||||||
the_txn = self.env.txn_begin()
|
the_txn = self.env.txn_begin()
|
||||||
self.person_map.put(data.handle, data, txn=the_txn)
|
self.person_map.put(data.handle, data, txn=the_txn)
|
||||||
the_txn.commit()
|
the_txn.commit()
|
||||||
@ -165,7 +170,7 @@ class CursorTest(unittest.TestCase):
|
|||||||
cursor.first()
|
cursor.first()
|
||||||
cursor.next()
|
cursor.next()
|
||||||
|
|
||||||
data = Data(str(2),'surname2', 'name2')
|
data = Data(b'2', 'surname2', 'name2')
|
||||||
the_txn = self.env.txn_begin()
|
the_txn = self.env.txn_begin()
|
||||||
self.person_map.put(data.handle, data, txn=the_txn)
|
self.person_map.put(data.handle, data, txn=the_txn)
|
||||||
the_txn.commit()
|
the_txn.commit()
|
||||||
|
@ -20,15 +20,12 @@
|
|||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
try:
|
|
||||||
set()
|
|
||||||
except NameError:
|
|
||||||
from sets import Set as set
|
|
||||||
|
|
||||||
from gramps.gen.db import DbBsddb, DbTxn
|
from gramps.gen.db import DbBsddb, DbTxn
|
||||||
from gramps.cli.clidbman import CLIDbManager
|
from gramps.cli.clidbman import CLIDbManager
|
||||||
from gramps.gen.lib import (Source, RepoRef, Citation, Repository, Person,
|
from gramps.gen.lib import (Source, RepoRef, Citation, Repository, Person,
|
||||||
@ -88,8 +85,8 @@ class GrampsDbBaseTest(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
add_func(lnk_sources)
|
add_func(lnk_sources)
|
||||||
except:
|
except:
|
||||||
print "person_idx = ", person_idx
|
print ("person_idx = ", person_idx)
|
||||||
print "lnk_sources = ", repr(lnk_sources)
|
print ("lnk_sources = ", repr(lnk_sources))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -24,17 +24,12 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
|
||||||
set()
|
|
||||||
except NameError:
|
|
||||||
from sets import Set as set
|
|
||||||
|
|
||||||
from .. import DbTxn
|
from .. import DbTxn
|
||||||
from ...lib import Person, Event, Source, Citation
|
from ...lib import Person, Event, Source, Citation
|
||||||
|
|
||||||
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
|
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
|
||||||
|
|
||||||
from grampsdbtestbase import GrampsDbBaseTest
|
from .grampsdbtestbase import GrampsDbBaseTest
|
||||||
|
|
||||||
class ReferenceMapTest(GrampsDbBaseTest):
|
class ReferenceMapTest(GrampsDbBaseTest):
|
||||||
"""Test methods on the GrampsDbBase class that are related to the reference_map
|
"""Test methods on the GrampsDbBase class that are related to the reference_map
|
||||||
|
@ -402,7 +402,7 @@ class EventRefCheck(unittest.TestCase, PrivacyBaseTest, NoteBaseTest,
|
|||||||
self.phoenix.add_attribute(attr1)
|
self.phoenix.add_attribute(attr1)
|
||||||
self.ref_obj.add_attribute(attr2)
|
self.ref_obj.add_attribute(attr2)
|
||||||
self.phoenix.replace_citation_references('234567','654321')
|
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,
|
class FamilyCheck(unittest.TestCase, PrivacyBaseTest, NoteBaseTest,
|
||||||
CitationBaseTest, MediaBaseTest, AttrBaseTest):
|
CitationBaseTest, MediaBaseTest, AttrBaseTest):
|
||||||
|
Loading…
Reference in New Issue
Block a user