From c8c0164038eb1ebc7c33251d7c259014b54ab857 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Tue, 30 Jul 2013 22:06:29 +0000 Subject: [PATCH] Unit test python3 fixes svn: r22782 --- gramps/gen/db/test/cursor_test.py | 27 ++++++++++++++---------- gramps/gen/db/test/grampsdbtestbase.py | 11 ++++------ gramps/gen/db/test/reference_map_test.py | 7 +----- gramps/gen/lib/test/merge_test.py | 2 +- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/gramps/gen/db/test/cursor_test.py b/gramps/gen/db/test/cursor_test.py index 290eaae15..c3da8d278 100644 --- a/gramps/gen/db/test/cursor_test.py +++ b/gramps/gen/db/test/cursor_test.py @@ -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() diff --git a/gramps/gen/db/test/grampsdbtestbase.py b/gramps/gen/db/test/grampsdbtestbase.py index 704f66100..2f17de4dc 100644 --- a/gramps/gen/db/test/grampsdbtestbase.py +++ b/gramps/gen/db/test/grampsdbtestbase.py @@ -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 diff --git a/gramps/gen/db/test/reference_map_test.py b/gramps/gen/db/test/reference_map_test.py index 2c99595f6..ebdbdfc80 100644 --- a/gramps/gen/db/test/reference_map_test.py +++ b/gramps/gen/db/test/reference_map_test.py @@ -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 diff --git a/gramps/gen/lib/test/merge_test.py b/gramps/gen/lib/test/merge_test.py index 5483f2fd6..8dc5a0e22 100644 --- a/gramps/gen/lib/test/merge_test.py +++ b/gramps/gen/lib/test/merge_test.py @@ -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):