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