[Zope-Coders] dodgy testtextIndex.py

Chris Withers chrisw@nipltd.com
Wed, 28 Aug 2002 15:31:53 +0100


Hi All,

Second or third time of asking I know, but I'm wondering if people could help me 
out on this.

There are a load of tests which seem to intermittently fail on Windows in:
lib/python/Products/PluginIndexes/TextIndex/tests

They all rely on what seems to me to be some pretty dodgy code that fiddles with 
FileStorages and ZODB's at a very low level. I suspect this is causing the 
failures. They also don't hold very well with Tres' idea of tests being able to 
work in a read-only environment (other than the temp store, which needs to be 
writable).

I've included the suspect code in a PS, could knowledgeable ZODB folks please 
comment? If suggestions are made, I'll attempt to get fixes in place.

cheers,

Chris

PS:
     def setUp(self):
         self.index=TextIndex.TextIndex('text')
         self.doc=Dummy(text='this is the time, when all good zopes')
         self.old_log_write = zLOG.log_write
         zLOG.log_write=log_write


     def dbopen(self):
         n = 'fs_tmp__%s' % os.getpid()
         s = ZODB.FileStorage.FileStorage(n)
         db=self.db=ZODB.DB(s)
         self.jar=db.open()
         if not self.jar.root().has_key('index'):
             self.jar.root()['index']=TextIndex.TextIndex('text')
             get_transaction().commit()
         return self.jar.root()['index']

     def dbclose(self):
         self.jar.close()
         self.db.close()
         del self.jar
         del self.db

     def tearDown(self):
         get_transaction().abort()
         if hasattr(self, 'jar'):
             self.dbclose()
             for path in glob('fs_tmp__*'):
                 os.remove(path)
         zLOG.log_write=self.old_log_write