[Zope3-checkins] CVS: Zope3/lib/python/Zope/StartUp/tests - testStartupDirectives.py:1.3

Jim Fulton jim@zope.com
Thu, 17 Oct 2002 09:31:59 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/StartUp/tests
In directory cvs.zope.org:/tmp/cvs-serv20668/lib/python/Zope/StartUp/tests

Modified Files:
	testStartupDirectives.py 
Log Message:

Fixed a test that was opening the main database. This was bad, as the
tests should not touch this. Also, you couldn't run the tests while
the application was running.

Fixed a number of tests that created temporary files and didn't clean
them up. *Hopefully*, there aren't any leaked files that would cause
this to fail on windows.



=== Zope3/lib/python/Zope/StartUp/tests/testStartupDirectives.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/StartUp/tests/testStartupDirectives.py:1.2	Mon Jun 10 19:29:43 2002
+++ Zope3/lib/python/Zope/StartUp/tests/testStartupDirectives.py	Thu Oct 17 09:31:58 2002
@@ -16,11 +16,13 @@
 $Id$
 """
 
-import unittest, sys, tempfile
+import unittest, sys, tempfile, os
 from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
 from Zope.StartUp.metaConfigure import SiteDefinition
 from Zope.Configuration.name import resolve
 
+_fsname = tempfile.mktemp()+'.fs'
+
 class ContextStub:
 
     def resolve(self, dottedname):
@@ -29,6 +31,14 @@
 
 class Test(CleanUp, unittest.TestCase):
 
+    def tearDown(self):
+
+        CleanUp.tearDown(self)
+
+        for ext in '', '.lock', '.index', '.tmp':
+            try: os.remove(_fsname + ext)
+            except: pass
+        
 
     def _createBlankSiteDefinition(self):
         """ """
@@ -38,16 +48,10 @@
     def testStorageMethods(self):
         """ """
         sd = self._createBlankSiteDefinition()
-
-        self.assertEqual(sd.useFileStorage(ContextStub()), [])
-        self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
-        self.assertEqual(sd._zodb._storage._file_name, 'Data.fs')
-        sd._zodb.close()
         
-        filename = tempfile.mktemp()
-        self.assertEqual(sd.useFileStorage(ContextStub(), file=filename), [])
+        self.assertEqual(sd.useFileStorage(ContextStub(), file=_fsname), [])
         self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
-        self.assertEqual(sd._zodb._storage._file_name, filename)
+        self.assertEqual(sd._zodb._storage._file_name, _fsname)
         sd._zodb.close()
 
         self.assertEqual(sd.useMappingStorage(ContextStub()), [])
@@ -65,10 +69,9 @@
         self.assertEqual(sd.useLog(ContextStub()), [])
         self.assertEqual(_log_dest, sys.stderr)
 
-        filename = tempfile.mktemp()
-        self.assertEqual(sd.useLog(ContextStub(), filename), [])
+        self.assertEqual(sd.useLog(ContextStub(), _fsname), [])
         from zLOG.MinimalLogger import _log_dest
-        self.assertEqual(_log_dest.name, open(filename, 'w').name)
+        self.assertEqual(_log_dest.name, open(_fsname, 'w').name)
 
 
     def testAddServer(self):
@@ -97,8 +100,7 @@
         from Zope.App.OFS.Content.Folder.RootFolder import IRootFolder
         from Zope.App.ZopePublication.ZopePublication import ZopePublication
 
-        filename = tempfile.mktemp()
-        sd.useFileStorage(ContextStub(), file=filename)
+        sd.useFileStorage(ContextStub(), file=_fsname)
 
         connection = sd._zodb.open()
         root = connection.root()