mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
6a123cb782
commit
6057b2e645
17 changed files with 72 additions and 78 deletions
|
@ -91,7 +91,7 @@ musicdata = {
|
|||
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 @@ class AssociateErrorTestCase(unittest.TestCase):
|
|||
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 @@ class AssociateTestCase(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)
|
||||
|
|
|
@ -5,10 +5,10 @@ various DB flags, etc.
|
|||
|
||||
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 @@ class BasicTestCase(unittest.TestCase):
|
|||
|
||||
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 @@ class BasicTestCase(unittest.TestCase):
|
|||
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 @@ class BasicTestCase(unittest.TestCase):
|
|||
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.)
|
||||
|
|
|
@ -52,7 +52,7 @@ class AbstractBtreeKeyCompareTestCase (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)
|
||||
|
@ -70,8 +70,8 @@ class AbstractBtreeKeyCompareTestCase (unittest.TestCase):
|
|||
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
|
||||
|
|
|
@ -17,7 +17,7 @@ class pget_bugTestCase(unittest.TestCase):
|
|||
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 @@ class pget_bugTestCase(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
import os, string
|
||||
import unittest
|
||||
import glob
|
||||
import tempfile
|
||||
|
||||
try:
|
||||
|
@ -20,7 +19,7 @@ class dbobjTestCase(unittest.TestCase):
|
|||
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 @@ class dbobjTestCase(unittest.TestCase):
|
|||
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
|
||||
|
|
|
@ -245,7 +245,7 @@ class ThreadHashShelveTestCase(BasicShelveTestCase):
|
|||
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 @@ class BasicEnvShelveTestCase(DBShelveTestCase):
|
|||
|
||||
|
||||
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):
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
import os, re
|
||||
import tempfile
|
||||
import shutil
|
||||
try:
|
||||
import cPickle
|
||||
pickle = cPickle
|
||||
|
@ -58,7 +57,8 @@ class TableDBTestCase(unittest.TestCase):
|
|||
|
||||
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"
|
||||
|
|
|
@ -4,7 +4,6 @@ is closed before its DB objects.
|
|||
|
||||
import os
|
||||
import tempfile
|
||||
import glob
|
||||
import unittest
|
||||
|
||||
try:
|
||||
|
@ -32,7 +31,7 @@ else:
|
|||
|
||||
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 @@ class DBEnvClosedEarlyCrash(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
@ -47,7 +47,7 @@ class JoinTestCase(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)
|
||||
except os.error: pass
|
||||
|
@ -56,10 +56,8 @@ class JoinTestCase(unittest.TestCase):
|
|||
|
||||
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:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
TestCases for testing the locking sub-system.
|
||||
"""
|
||||
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
|
@ -37,7 +36,8 @@ class LockingTestCase(unittest.TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
self.env.close()
|
||||
shutil.rmtree(self.homeDir)
|
||||
from test import test_support
|
||||
test_support.rmtree(self.homeDir)
|
||||
|
||||
|
||||
def test01_simple(self):
|
||||
|
|
|
@ -17,7 +17,7 @@ except ImportError:
|
|||
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 @@ class MiscTestCase(unittest.TestCase):
|
|||
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)
|
||||
|
|
|
@ -7,7 +7,6 @@ except ImportError:
|
|||
cPickle = None
|
||||
import unittest
|
||||
import tempfile
|
||||
import glob
|
||||
|
||||
try:
|
||||
# For Pythons w/distutils pybsddb
|
||||
|
@ -25,7 +24,7 @@ class pickleTestCase(unittest.TestCase):
|
|||
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 @@ class pickleTestCase(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
@ -24,12 +24,13 @@ letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|||
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 @@ class SimpleRecnoTestCase(unittest.TestCase):
|
|||
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)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import unittest
|
||||
import os
|
||||
import tempfile
|
||||
import glob
|
||||
|
||||
try:
|
||||
# For Pythons w/distutils pybsddb
|
||||
|
@ -13,7 +12,7 @@ except ImportError:
|
|||
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 @@ class DBSequenceTest(unittest.TestCase):
|
|||
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)
|
||||
|
|
|
@ -5,7 +5,6 @@ import os
|
|||
import sys
|
||||
import time
|
||||
import errno
|
||||
import shutil
|
||||
import tempfile
|
||||
from random import random
|
||||
|
||||
|
@ -52,7 +51,7 @@ class BaseThreadedTestCase(unittest.TestCase):
|
|||
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 @@ class BaseThreadedTestCase(unittest.TestCase):
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue