[Python-checkins] r61052 - in python/trunk/Lib: bsddb/test/test_associate.py bsddb/test/test_basics.py bsddb/test/test_compare.py bsddb/test/test_cursor_pget_bug.py bsddb/test/test_dbobj.py bsddb/test/test_dbshelve.py bsddb/test/test_dbtables.py bsddb/test/test_env_close.py bsddb/test/test_join.py bsddb/test/test_lock.py bsddb/test/test_misc.py bsddb/test/test_pickle.py bsddb/test/test_recno.py bsddb/test/test_sequence.py bsddb/test/test_thread.py test/test_bsddb3.py test/test_support.py
neal.norwitz
python-checkins at python.org
Sun Feb 24 19:47:04 CET 2008
Author: neal.norwitz
Date: Sun Feb 24 19:47:03 2008
New Revision: 61052
Modified:
python/trunk/Lib/bsddb/test/test_associate.py
python/trunk/Lib/bsddb/test/test_basics.py
python/trunk/Lib/bsddb/test/test_compare.py
python/trunk/Lib/bsddb/test/test_cursor_pget_bug.py
python/trunk/Lib/bsddb/test/test_dbobj.py
python/trunk/Lib/bsddb/test/test_dbshelve.py
python/trunk/Lib/bsddb/test/test_dbtables.py
python/trunk/Lib/bsddb/test/test_env_close.py
python/trunk/Lib/bsddb/test/test_join.py
python/trunk/Lib/bsddb/test/test_lock.py
python/trunk/Lib/bsddb/test/test_misc.py
python/trunk/Lib/bsddb/test/test_pickle.py
python/trunk/Lib/bsddb/test/test_recno.py
python/trunk/Lib/bsddb/test/test_sequence.py
python/trunk/Lib/bsddb/test/test_thread.py
python/trunk/Lib/test/test_bsddb3.py
python/trunk/Lib/test/test_support.py
Log:
Create a db_home directory with a unique name so multiple users can
run the test simultaneously. The simplest thing I found that worked
on both Windows and Unix was to use the PID. It's unique so should be
sufficient. This should prevent many of the spurious failures of
the automated tests since they run as different users.
Also cleanup the directory consistenly in the tearDown methods.
It would be nice if someone ensured that the directories are always
created with a consistent name.
Modified: python/trunk/Lib/bsddb/test/test_associate.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_associate.py (original)
+++ python/trunk/Lib/bsddb/test/test_associate.py Sun Feb 24 19:47:03 2008
@@ -91,7 +91,7 @@
class AssociateErrorTestCase(unittest.TestCase):
def setUp(self):
self.filename = self.__class__.__name__ + '.db'
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try:
os.mkdir(homeDir)
@@ -106,11 +106,8 @@
def tearDown(self):
self.env.close()
self.env = None
- import glob
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
-
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test00_associateDBError(self):
if verbose:
@@ -151,7 +148,7 @@
def setUp(self):
self.filename = self.__class__.__name__ + '.db'
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try:
os.mkdir(homeDir)
Modified: python/trunk/Lib/bsddb/test/test_basics.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_basics.py (original)
+++ python/trunk/Lib/bsddb/test/test_basics.py Sun Feb 24 19:47:03 2008
@@ -5,10 +5,10 @@
import os
import errno
-import shutil
import string
import tempfile
from pprint import pprint
+from test import test_support
import unittest
import time
@@ -53,13 +53,9 @@
def setUp(self):
if self.useEnv:
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
- try:
- shutil.rmtree(homeDir)
- except OSError, e:
- # unix returns ENOENT, windows returns ESRCH
- if e.errno not in (errno.ENOENT, errno.ESRCH): raise
+ test_support.rmtree(homeDir)
os.mkdir(homeDir)
try:
self.env = db.DBEnv()
@@ -73,7 +69,7 @@
tempfile.tempdir = None
# Yes, a bare except is intended, since we're re-raising the exc.
except:
- shutil.rmtree(homeDir)
+ test_support.rmtree(homeDir)
raise
else:
self.env = None
@@ -97,8 +93,8 @@
def tearDown(self):
self.d.close()
if self.env is not None:
+ test_support.rmtree(self.homeDir)
self.env.close()
- shutil.rmtree(self.homeDir)
## Make a new DBEnv to remove the env files from the home dir.
## (It can't be done while the env is open, nor after it has been
## closed, so we make a new one to do it.)
Modified: python/trunk/Lib/bsddb/test/test_compare.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_compare.py (original)
+++ python/trunk/Lib/bsddb/test/test_compare.py Sun Feb 24 19:47:03 2008
@@ -52,7 +52,7 @@
def setUp (self):
self.filename = self.__class__.__name__ + '.db'
- homeDir = os.path.join (tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join (tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try:
os.mkdir (homeDir)
@@ -70,8 +70,8 @@
if self.env is not None:
self.env.close ()
self.env = None
- import glob
- map (os.remove, glob.glob (os.path.join (self.homeDir, '*')))
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def addDataToDB (self, data):
i = 0
Modified: python/trunk/Lib/bsddb/test/test_cursor_pget_bug.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_cursor_pget_bug.py (original)
+++ python/trunk/Lib/bsddb/test/test_cursor_pget_bug.py Sun Feb 24 19:47:03 2008
@@ -17,7 +17,7 @@
db_name = 'test-cursor_pget.db'
def setUp(self):
- self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
try:
os.mkdir(self.homeDir)
except os.error:
@@ -42,9 +42,8 @@
del self.secondary_db
del self.primary_db
del self.env
- for file in glob.glob(os.path.join(self.homeDir, '*')):
- os.remove(file)
- os.removedirs(self.homeDir)
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test_pget(self):
cursor = self.secondary_db.cursor()
Modified: python/trunk/Lib/bsddb/test/test_dbobj.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_dbobj.py (original)
+++ python/trunk/Lib/bsddb/test/test_dbobj.py Sun Feb 24 19:47:03 2008
@@ -1,7 +1,6 @@
import os, string
import unittest
-import glob
import tempfile
try:
@@ -20,7 +19,7 @@
db_name = 'test-dbobj.db'
def setUp(self):
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try: os.mkdir(homeDir)
except os.error: pass
@@ -30,9 +29,8 @@
del self.db
if hasattr(self, 'env'):
del self.env
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test01_both(self):
class TestDBEnv(dbobj.DBEnv): pass
Modified: python/trunk/Lib/bsddb/test/test_dbshelve.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_dbshelve.py (original)
+++ python/trunk/Lib/bsddb/test/test_dbshelve.py Sun Feb 24 19:47:03 2008
@@ -245,7 +245,7 @@
class BasicEnvShelveTestCase(DBShelveTestCase):
def do_open(self):
self.homeDir = homeDir = os.path.join(
- tempfile.gettempdir(), 'db_home')
+ tempfile.gettempdir(), 'db_home%d'%os.getpid())
try: os.mkdir(homeDir)
except os.error: pass
self.env = db.DBEnv()
@@ -262,12 +262,9 @@
def tearDown(self):
+ from test import test_support
+ test_support.rmtree(self.homeDir)
self.do_close()
- import glob
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
-
class EnvBTreeShelveTestCase(BasicEnvShelveTestCase):
Modified: python/trunk/Lib/bsddb/test/test_dbtables.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_dbtables.py (original)
+++ python/trunk/Lib/bsddb/test/test_dbtables.py Sun Feb 24 19:47:03 2008
@@ -22,7 +22,6 @@
import os, re
import tempfile
-import shutil
try:
import cPickle
pickle = cPickle
@@ -58,7 +57,8 @@
def tearDown(self):
self.tdb.close()
- shutil.rmtree(self.testHomeDir)
+ from test import test_support
+ test_support.rmtree(self.testHomeDir)
def test01(self):
tabname = "test01"
Modified: python/trunk/Lib/bsddb/test/test_env_close.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_env_close.py (original)
+++ python/trunk/Lib/bsddb/test/test_env_close.py Sun Feb 24 19:47:03 2008
@@ -4,7 +4,6 @@
import os
import tempfile
-import glob
import unittest
try:
@@ -32,7 +31,7 @@
class DBEnvClosedEarlyCrash(unittest.TestCase):
def setUp(self):
- self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
try: os.mkdir(self.homeDir)
except os.error: pass
tempfile.tempdir = self.homeDir
@@ -40,10 +39,8 @@
tempfile.tempdir = None
def tearDown(self):
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
-
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test01_close_dbenv_before_db(self):
dbenv = db.DBEnv()
Modified: python/trunk/Lib/bsddb/test/test_join.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_join.py (original)
+++ python/trunk/Lib/bsddb/test/test_join.py Sun Feb 24 19:47:03 2008
@@ -47,7 +47,7 @@
def setUp(self):
self.filename = self.__class__.__name__ + '.db'
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try: os.mkdir(homeDir)
except os.error: pass
@@ -56,10 +56,8 @@
def tearDown(self):
self.env.close()
- import glob
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test01_join(self):
if verbose:
Modified: python/trunk/Lib/bsddb/test/test_lock.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_lock.py (original)
+++ python/trunk/Lib/bsddb/test/test_lock.py Sun Feb 24 19:47:03 2008
@@ -2,7 +2,6 @@
TestCases for testing the locking sub-system.
"""
-import shutil
import tempfile
import time
@@ -37,7 +36,8 @@
def tearDown(self):
self.env.close()
- shutil.rmtree(self.homeDir)
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test01_simple(self):
Modified: python/trunk/Lib/bsddb/test/test_misc.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_misc.py (original)
+++ python/trunk/Lib/bsddb/test/test_misc.py Sun Feb 24 19:47:03 2008
@@ -17,7 +17,7 @@
class MiscTestCase(unittest.TestCase):
def setUp(self):
self.filename = self.__class__.__name__ + '.db'
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try:
os.mkdir(homeDir)
@@ -25,12 +25,9 @@
pass
def tearDown(self):
- try:
- os.remove(self.filename)
- except OSError:
- pass
- import shutil
- shutil.rmtree(self.homeDir)
+ from test import test_support
+ test_support.unlink(self.filename)
+ test_support.rmtree(self.homeDir)
def test01_badpointer(self):
dbs = dbshelve.open(self.filename)
Modified: python/trunk/Lib/bsddb/test/test_pickle.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_pickle.py (original)
+++ python/trunk/Lib/bsddb/test/test_pickle.py Sun Feb 24 19:47:03 2008
@@ -7,7 +7,6 @@
cPickle = None
import unittest
import tempfile
-import glob
try:
# For Pythons w/distutils pybsddb
@@ -25,7 +24,7 @@
db_name = 'test-dbobj.db'
def setUp(self):
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try: os.mkdir(homeDir)
except os.error: pass
@@ -35,9 +34,8 @@
del self.db
if hasattr(self, 'env'):
del self.env
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def _base_test_pickle_DBError(self, pickle):
self.env = db.DBEnv()
Modified: python/trunk/Lib/bsddb/test/test_recno.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_recno.py (original)
+++ python/trunk/Lib/bsddb/test/test_recno.py Sun Feb 24 19:47:03 2008
@@ -24,12 +24,13 @@
class SimpleRecnoTestCase(unittest.TestCase):
def setUp(self):
self.filename = tempfile.mktemp()
+ self.homeDir = None
def tearDown(self):
- try:
- os.remove(self.filename)
- except OSError, e:
- if e.errno <> errno.EEXIST: raise
+ from test import test_support
+ test_support.unlink(self.filename)
+ if self.homeDir:
+ test_support.rmtree(self.homeDir)
def test01_basic(self):
d = db.DB()
@@ -202,7 +203,8 @@
just a line in the file, but you can set a different record delimiter
if needed.
"""
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+ self.homeDir = homeDir
source = os.path.join(homeDir, 'test_recno.txt')
if not os.path.isdir(homeDir):
os.mkdir(homeDir)
Modified: python/trunk/Lib/bsddb/test/test_sequence.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_sequence.py (original)
+++ python/trunk/Lib/bsddb/test/test_sequence.py Sun Feb 24 19:47:03 2008
@@ -1,7 +1,6 @@
import unittest
import os
import tempfile
-import glob
try:
# For Pythons w/distutils pybsddb
@@ -13,7 +12,7 @@
class DBSequenceTest(unittest.TestCase):
def setUp(self):
self.int_32_max = 0x100000000
- self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
try:
os.mkdir(self.homeDir)
except os.error:
@@ -38,9 +37,8 @@
self.dbenv.close()
del self.dbenv
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
+ from test import test_support
+ test_support.rmtree(self.homeDir)
def test_get(self):
self.seq = db.DBSequence(self.d, flags=0)
Modified: python/trunk/Lib/bsddb/test/test_thread.py
==============================================================================
--- python/trunk/Lib/bsddb/test/test_thread.py (original)
+++ python/trunk/Lib/bsddb/test/test_thread.py Sun Feb 24 19:47:03 2008
@@ -5,7 +5,6 @@
import sys
import time
import errno
-import shutil
import tempfile
from random import random
@@ -52,7 +51,7 @@
if verbose:
dbutils._deadlock_VerboseFile = sys.stdout
- homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
+ homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
self.homeDir = homeDir
try:
os.mkdir(homeDir)
@@ -69,12 +68,10 @@
self.d.open(self.filename, self.dbtype, self.dbopenflags|db.DB_CREATE)
def tearDown(self):
+ from test import test_support
+ test_support.rmtree(self.homeDir)
self.d.close()
self.env.close()
- try:
- shutil.rmtree(self.homeDir)
- except OSError, e:
- if e.errno != errno.EEXIST: raise
def setEnvOpts(self):
pass
Modified: python/trunk/Lib/test/test_bsddb3.py
==============================================================================
--- python/trunk/Lib/test/test_bsddb3.py (original)
+++ python/trunk/Lib/test/test_bsddb3.py Sun Feb 24 19:47:03 2008
@@ -2,10 +2,12 @@
"""
Run all test cases.
"""
+import os
import sys
+import tempfile
import time
import unittest
-from test.test_support import requires, verbose, run_unittest, unlink
+from test.test_support import requires, verbose, run_unittest, unlink, rmtree
# When running as a script instead of within the regrtest framework, skip the
# requires test, since it's obvious we want to run them.
@@ -85,6 +87,15 @@
# For invocation through regrtest
def test_main():
run_unittest(suite())
+ db_home = os.path.join(tempfile.gettempdir(), 'db_home')
+ # The only reason to remove db_home is in case if there is an old
+ # one lying around. This might be by a different user, so just
+ # ignore errors. We should always make a unique name now.
+ try:
+ rmtree(db_home)
+ except:
+ pass
+ rmtree('db_home%d' % os.getpid())
# For invocation as a script
if __name__ == '__main__':
Modified: python/trunk/Lib/test/test_support.py
==============================================================================
--- python/trunk/Lib/test/test_support.py (original)
+++ python/trunk/Lib/test/test_support.py Sun Feb 24 19:47:03 2008
@@ -9,6 +9,7 @@
import sys
import os
import os.path
+import shutil
import warnings
import unittest
@@ -64,6 +65,14 @@
except OSError:
pass
+def rmtree(path):
+ try:
+ shutil.rmtree(path)
+ except OSError, e:
+ # Unix returns ENOENT, Windows returns ESRCH.
+ if e.errno not in (errno.ENOENT, errno.ESRCH):
+ raise
+
def forget(modname):
'''"Forget" a module was ever imported by removing it from sys.modules and
deleting any .pyc and .pyo files.'''
More information about the Python-checkins
mailing list