Unit test python3 fixes

svn: r22783
This commit is contained in:
Nick Hall 2013-07-30 22:07:28 +00:00
parent 0dc020e31f
commit 031bdb699b
4 changed files with 36 additions and 81 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):
@ -1546,34 +1546,13 @@ class SourceCheck(unittest.TestCase, PrivacyBaseTest, NoteBaseTest,
pass
def test_merge_datamap(self):
sattr = SrcAttribute()
sattr.set_type('A')
sattr.set_value('a')
self.phoenix.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('B')
sattr.set_value('b')
self.phoenix.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('B')
sattr.set_value('bb')
self.titanic.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('C')
sattr.set_value('c')
self.titanic.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('A')
sattr.set_value('a')
self.ref_obj.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('B')
sattr.set_value('b')
self.ref_obj.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('C')
sattr.set_value('c')
self.ref_obj.add_attribute(sattr)
self.phoenix.set_data_item('A', 'a')
self.phoenix.set_data_item('B', 'b')
self.titanic.set_data_item('B', 'bb')
self.titanic.set_data_item('C', 'c')
self.ref_obj.set_data_item('A', 'a')
self.ref_obj.set_data_item('B', 'b')
self.ref_obj.set_data_item('C', 'c')
self.phoenix.merge(self.titanic)
self.assertEqual(self.phoenix.serialize(), self.ref_obj.serialize())
@ -1757,34 +1736,13 @@ class CitationCheck(unittest.TestCase, PrivacyBaseTest, MediaBaseTest,
self.assertEqual(self.phoenix.serialize(), self.ref_obj.serialize())
def test_merge_datamap(self):
sattr = SrcAttribute()
sattr.set_type('A')
sattr.set_value('a')
self.phoenix.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('B')
sattr.set_value('b')
self.phoenix.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('B')
sattr.set_value('bb')
self.titanic.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('C')
sattr.set_value('c')
self.titanic.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('A')
sattr.set_value('a')
self.ref_obj.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('B')
sattr.set_value('b')
self.ref_obj.add_attribute(sattr)
sattr = SrcAttribute()
sattr.set_type('C')
sattr.set_value('c')
self.ref_obj.add_attribute(sattr)
self.phoenix.set_data_item('A', 'a')
self.phoenix.set_data_item('B', 'b')
self.titanic.set_data_item('B', 'bb')
self.titanic.set_data_item('C', 'c')
self.ref_obj.set_data_item('A', 'a')
self.ref_obj.set_data_item('B', 'b')
self.ref_obj.set_data_item('C', 'c')
self.phoenix.merge(self.titanic)
self.assertEqual(self.phoenix.serialize(), self.ref_obj.serialize())