[Zodb-checkins]
SVN: ZODB/branches/jim-zeo-blob/src/ZODB/Blobs/tests/test_undo.py
Simplified some temporary-file management.
Jim Fulton
jim at zope.com
Thu May 17 18:23:15 EDT 2007
Log message for revision 75823:
Simplified some temporary-file management.
Fixed a test that was failing on windows because of consumed files
were left open.
Added missing database closes.
Changed:
U ZODB/branches/jim-zeo-blob/src/ZODB/Blobs/tests/test_undo.py
-=-
Modified: ZODB/branches/jim-zeo-blob/src/ZODB/Blobs/tests/test_undo.py
===================================================================
--- ZODB/branches/jim-zeo-blob/src/ZODB/Blobs/tests/test_undo.py 2007-05-17 21:27:11 UTC (rev 75822)
+++ ZODB/branches/jim-zeo-blob/src/ZODB/Blobs/tests/test_undo.py 2007-05-17 22:23:14 UTC (rev 75823)
@@ -28,15 +28,16 @@
class BlobUndoTests(unittest.TestCase):
def setUp(self):
- self.storagefile = tempfile.mktemp()
- self.blob_dir = tempfile.mkdtemp()
+ self.test_dir = tempfile.mkdtemp()
+ self.here = os.getcwd()
+ os.chdir(self.test_dir)
+ self.storagefile = 'Data.fs'
+ os.mkdir('blobs')
+ self.blob_dir = 'blobs'
def tearDown(self):
- try:
- os.unlink(self.storagefile)
- except (OSError, IOError):
- pass
- shutil.rmtree(self.blob_dir)
+ os.chdir(self.here)
+ shutil.rmtree(self.test_dir)
def testUndoWithoutPreviousVersion(self):
base_storage = FileStorage(self.storagefile)
@@ -60,7 +61,8 @@
root = connection.root()
# the blob footprint object should exist no longer
self.assertRaises(KeyError, root.__getitem__, 'blob')
-
+ database.close()
+
def testUndo(self):
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
@@ -93,6 +95,7 @@
blob = root['blob']
self.assertEqual(blob.open('r').read(), 'this is state 1')
transaction.abort()
+ database.close()
def testUndoAfterConsumption(self):
base_storage = FileStorage(self.storagefile)
@@ -101,22 +104,16 @@
connection = database.open()
root = connection.root()
transaction.begin()
- to_consume = tempfile.NamedTemporaryFile()
- to_consume.write('this is state 1')
- to_consume.flush()
-
+ open('consume1', 'w').write('this is state 1')
blob = Blob()
- blob.consumeFile(to_consume.name)
-
+ blob.consumeFile('consume1')
root['blob'] = blob
transaction.commit()
-
+
transaction.begin()
blob = root['blob']
- to_consume = tempfile.NamedTemporaryFile()
- to_consume.write('this is state 2')
- to_consume.flush()
- blob.consumeFile(to_consume.name)
+ open('consume2', 'w').write('this is state 2')
+ blob.consumeFile('consume2')
transaction.commit()
transaction.begin()
@@ -135,6 +132,8 @@
self.assertEqual(blob.open('r').read(), 'this is state 1')
transaction.abort()
+ database.close()
+
def testRedo(self):
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
@@ -174,7 +173,9 @@
blob = root['blob']
self.assertEqual(blob.open('r').read(), 'this is state 2')
transaction.abort()
-
+
+ database.close()
+
def testRedoOfCreation(self):
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
@@ -207,6 +208,7 @@
self.assertEqual(blob.open('r').read(), 'this is state 1')
transaction.abort()
+ database.close()
def test_suite():
suite = unittest.TestSuite()
More information about the Zodb-checkins
mailing list