Commit 46d79eae authored by Jeremy Hylton's avatar Jeremy Hylton

Refactor test cleanup to use removefs() helper function.

StorageTestBase.removefs() will attempt to remove files with all the
possible extensions that FileStorage will create.  It will raise
os.error for any error except ENOENT.

Remove many variants of removefs() implemented in the various test
suites.
parent ea06d610
......@@ -22,6 +22,8 @@ from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
from glob import glob
from ZODB.tests.StorageTestBase import removefs
class Base:
""" Tests common to all types: sets, buckets, and BTrees """
def tearDown(self):
......@@ -31,8 +33,8 @@ class Base:
def _getRoot(self):
from ZODB.FileStorage import FileStorage
from ZODB.DB import DB
n = 'fs_tmp__%s' % os.getpid()
s = FileStorage(n)
self._fsname = 'fs_tmp__%s' % os.getpid()
s = FileStorage(self._fsname)
db = DB(s)
root = db.open().root()
return root
......@@ -42,8 +44,7 @@ class Base:
root._p_jar._db.close()
def _delDB(self):
for file in glob('fs_tmp__*'):
os.remove(file)
removefs(self._fsname)
def testLoadAndStore(self):
for i in 0, 10, 1000:
......
......@@ -22,6 +22,7 @@ import unittest
import ZEO.start
from ZEO.ClientStorage import ClientStorage
from ZEO.util import Environment
from ZODB.tests.StorageTestBase import removefs
class StartTests(unittest.TestCase):
......@@ -38,12 +39,7 @@ class StartTests(unittest.TestCase):
self.stop_server()
self.shutdown()
finally:
for ext in "", ".index", ".tmp", ".lock", ".old":
f = "Data.fs" + ext
try:
os.remove(f)
except os.error:
pass
removefs("Data.fs")
try:
os.remove(self.env.zeo_pid)
except os.error:
......
......@@ -29,7 +29,7 @@ import ZEO.ClientStorage, ZEO.StorageServer
import ThreadedAsync, ZEO.trigger
from ZODB.FileStorage import FileStorage
from ZODB.Transaction import Transaction
from ZODB.tests.StorageTestBase import zodb_pickle, MinPO
from ZODB.tests.StorageTestBase import zodb_pickle, MinPO, removefs
import zLOG
from ZEO.tests import forker, Cache, CommitLockTests, ThreadTests
......@@ -149,13 +149,7 @@ class ZEOFileStorageTests(GenericTests):
return 'FileStorage', (self.__fs_base, '1')
def delStorage(self):
# file storage appears to create four files
for ext in '', '.index', '.lock', '.tmp', '.old':
path = self.__fs_base + ext
try:
os.remove(path)
except os.error:
pass
removefs(self.__fs_base)
class WindowsGenericTests(GenericTests):
"""Subclass to support server creation on Windows.
......@@ -192,13 +186,7 @@ class WindowsZEOFileStorageTests(WindowsGenericTests):
return 'FileStorage', (self.__fs_base, '1') # create=1
def delStorage(self):
# file storage appears to create four files
for ext in '', '.index', '.lock', '.tmp':
path = self.__fs_base + ext
try:
os.remove(path)
except os.error:
pass
removefs(self.__fs_base)
class ConnectionTests(StorageTestBase.StorageTestBase):
"""Tests that explicitly manage the server process.
......
......@@ -7,7 +7,7 @@ import tempfile
import unittest
import ZODB, ZODB.FileStorage
from StorageTestBase import StorageTestBase
from StorageTestBase import StorageTestBase, removefs
class FileStorageCorruptTests(StorageTestBase):
......@@ -17,10 +17,7 @@ class FileStorageCorruptTests(StorageTestBase):
def tearDown(self):
self._storage.close()
for ext in '', '.old', '.tmp', '.lock', '.index':
path = self.path + ext
if os.path.exists(path):
os.remove(path)
removefs(self.path)
def _do_stores(self):
oids = []
......
......@@ -6,6 +6,8 @@ method _dostore() which performs a complete store transaction for a
single object revision.
"""
import errno
import os
import pickle
import string
import sys
......@@ -105,6 +107,16 @@ def import_helper(name):
mod = __import__(name)
return sys.modules[name]
def removefs(base):
"""Remove all files created by FileStorage with path base."""
for ext in '', '.old', '.tmp', '.lock', '.index', '.pack':
path = base + ext
try:
os.remove(path)
except os.error, err:
if err[0] != errno.ENOENT:
raise
class StorageTestBase(unittest.TestCase):
......
......@@ -44,10 +44,7 @@ class FileStorageTests(
def tearDown(self):
self._storage.close()
for ext in '', '.old', '.tmp', '.lock', '.index':
path = 'FileStorageTests.fs' + ext
if os.path.exists(path):
os.remove(path)
StorageTestBase.removefs("FileStorageTests.fs")
def checkLongMetadata(self):
s = "X" * 75000
......@@ -76,13 +73,8 @@ class FileStorageRecoveryTest(
def tearDown(self):
self._storage.close()
self._dst.close()
for ext in '', '.old', '.tmp', '.lock', '.index':
for fs in 'Source', 'Dest':
path = fs + '.fs' + ext
try:
os.remove(path)
except OSError, e:
if e.errno <> errno.ENOENT: raise
StorageTestBase.removefs("Source.fs")
StorageTestBase.removefs("Dest.fs")
def checkSimpleRecovery(self):
oid = self._storage.new_oid()
......
......@@ -3,6 +3,7 @@ import sys, os
import ZODB
import ZODB.FileStorage
from ZODB.PersistentMapping import PersistentMapping
from ZODB.tests.StorageTestBase import removefs
import unittest
class ExportImportTests:
......@@ -76,8 +77,6 @@ class ExportImportTests:
class ZODBTests(unittest.TestCase, ExportImportTests):
def setUp(self):
try: os.remove('ZODBTests.fs')
except: pass
self._storage = ZODB.FileStorage.FileStorage(
'ZODBTests.fs', create=1)
self._db = ZODB.DB(self._storage)
......@@ -93,7 +92,7 @@ class ZODBTests(unittest.TestCase, ExportImportTests):
def tearDown(self):
self._storage.close()
os.remove('ZODBTests.fs')
removefs("ZODBTests.fs")
def test_suite():
return unittest.makeSuite(ZODBTests, 'check')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment