summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb/test/test_join.py
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2008-08-31 14:12:11 (GMT)
committerJesus Cea <jcea@jcea.es>2008-08-31 14:12:11 (GMT)
commit6ba3329c274e2c7876c61f2e98d4592310d26bae (patch)
tree6bb346e892269279fa2011c3e4bd4648b273a7ae /Lib/bsddb/test/test_join.py
parent73c96dbf34c70bbf1ef807b98d51cf9c0e9dc042 (diff)
downloadcpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.zip
cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.gz
cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.bz2
bsddb code updated to version 4.7.3pre2. This code is the same than
Python 2.6 one, since the intention is to keep an unified 2.x/3.x codebase. The Python code is automatically translated using "2to3". Please, do not update this code in Python 3.0 by hand. Update the 2.6 one and then do "2to3".
Diffstat (limited to 'Lib/bsddb/test/test_join.py')
-rw-r--r--Lib/bsddb/test/test_join.py43
1 files changed, 11 insertions, 32 deletions
diff --git a/Lib/bsddb/test/test_join.py b/Lib/bsddb/test/test_join.py
index 7addf40..e92a33c 100644
--- a/Lib/bsddb/test/test_join.py
+++ b/Lib/bsddb/test/test_join.py
@@ -1,27 +1,12 @@
"""TestCases for using the DB.join and DBCursor.join_item methods.
"""
-import shutil
-import sys, os
-import tempfile
-import time
-from pprint import pprint
-
-try:
- from threading import Thread, current_thread
- have_threads = 1
-except ImportError:
- have_threads = 0
+import os
import unittest
-from bsddb.test.test_all import verbose
-from bsddb import db, dbshelve, StringKeys
-
-try:
- from bsddb3 import test_support
-except ImportError:
- from test import support as test_support
+from .test_all import db, dbshelve, test_support, verbose, \
+ get_new_environment_path, get_new_database_path
#----------------------------------------------------------------------
@@ -44,18 +29,12 @@ ColorIndex = [
('black', "shotgun"),
]
-def ASCII(s):
- return s.encode("ascii")
-
class JoinTestCase(unittest.TestCase):
keytype = ''
def setUp(self):
self.filename = self.__class__.__name__ + '.db'
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
- self.homeDir = homeDir
- try: os.mkdir(homeDir)
- except os.error: pass
+ self.homeDir = get_new_environment_path()
self.env = db.DBEnv()
self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK )
@@ -72,13 +51,13 @@ class JoinTestCase(unittest.TestCase):
# create and populate primary index
priDB = db.DB(self.env)
priDB.open(self.filename, "primary", db.DB_BTREE, db.DB_CREATE)
- [priDB.put(ASCII(k),ASCII(v)) for k,v in ProductIndex]
+ list(map(lambda t, priDB=priDB: priDB.put(*t), ProductIndex))
# create and populate secondary index
secDB = db.DB(self.env)
secDB.set_flags(db.DB_DUP | db.DB_DUPSORT)
secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE)
- [secDB.put(ASCII(k),ASCII(v)) for k,v in ColorIndex]
+ list(map(lambda t, secDB=secDB: secDB.put(*t), ColorIndex))
sCursor = None
jCursor = None
@@ -87,19 +66,19 @@ class JoinTestCase(unittest.TestCase):
sCursor = secDB.cursor()
# Don't do the .set() in an assert, or you can get a bogus failure
# when running python -O
- tmp = sCursor.set(b'red')
- assert tmp
+ tmp = sCursor.set('red')
+ self.assert_(tmp)
# FIXME: jCursor doesn't properly hold a reference to its
# cursors, if they are closed before jcursor is used it
# can cause a crash.
jCursor = priDB.join([sCursor])
- if jCursor.get(0) != (b'apple', b"Convenience Store"):
+ if jCursor.get(0) != ('apple', "Convenience Store"):
self.fail("join cursor positioned wrong")
- if jCursor.join_item() != b'chainsaw':
+ if jCursor.join_item() != 'chainsaw':
self.fail("DBCursor.join_item returned wrong item")
- if jCursor.get(0)[0] != b'strawberry':
+ if jCursor.get(0)[0] != 'strawberry':
self.fail("join cursor returned wrong thing")
if jCursor.get(0): # there were only three red items to return
self.fail("join cursor returned too many items")