[Zope-Checkins] CVS: Packages/Testing - ZODButil.py:1.2 common.py:1.2 custom_zodb.py:1.2 __init__.py:1.3

Evan Simpson evan@cvs.zope.org
Mon, 6 Aug 2001 13:20:31 -0400


Update of /cvs-repository/Packages/Testing
In directory cvs.zope.org:/tmp/cvs-serv1882

Modified Files:
	__init__.py 
Added Files:
	ZODButil.py common.py custom_zodb.py 
Log Message:
Merge unit test change from 2.4 branch


=== Packages/Testing/ZODButil.py 1.1 => 1.2 ===
+from glob import glob
+import ZODB
+from ZODB.FileStorage import FileStorage
+
+def makeDB():
+    s = FileStorage('fs_tmp__%s' % os.getpid())
+    return ZODB.DB(s)
+
+def cleanDB():
+    for fn in glob('fs_tmp__*'):
+        os.remove(fn)
+    


=== Packages/Testing/common.py 1.1 => 1.2 ===
+TestRunner = unittest.TextTestRunner
+
+def framework():
+    if __name__ != '__main__':
+        return
+    if len(sys.argv) > 1:
+        errs = globals()[sys.argv[1]]()
+    else:
+        errs = TestRunner().run(test_suite())
+    sys.exit(errs and 1 or 0)
+
+def debug():
+    test_suite().debug()
+
+def pdebug():
+    import pdb
+    pdb.run('debug()')
+
+def test_suite():
+    # The default test suite includes every subclass of TestCase in
+    # the module, with 'test' as the test method prefix.
+    ClassType = type(unittest.TestCase)
+    tests = []
+    for v in globals().values():
+        if isinstance(v, ClassType) and issubclass(v, unittest.TestCase):
+            tests.append(unittest.makeSuite(v))
+    if len(tests) > 1:
+        return unittest.TestSuite(tests)
+    if len(tests) == 1:
+        return tests[0]
+    return
+
+class Dummy:
+    '''Utility class for quick & dirty instances'''
+    def __init__(self, **kw):
+        self.__dict__.update(kw)
+
+    def __str__( self ):
+        return 'Dummy(%s)' % `self.__dict__`
+    
+    __repr__ = __str__
+
+def catch_log_errors():
+    import zLOG
+
+    if hasattr(zLOG, 'old_log_write'):
+        return
+
+    def log_write(subsystem, severity, summary, detail, error,
+                  PROBLEM=zLOG.PROBLEM):
+        if severity >= PROBLEM:
+            assert 0, "%s(%s): %s" % (subsystem, severity, summary)
+
+    zLOG.old_log_write = zLOG.log_write
+    zLOG.log_write = log_write
+
+def ignore_log_errors():
+    import zLOG
+
+    if hasattr(zLOG, 'old_log_write'):
+        zLOG.log_write = zLOG.old_log_write
+        del zLOG.old_log_write
+
+def Testing_file(*args):
+    dir = os.path.split(Testing.__file__)[0]
+    return apply(os.path.join, (dir,) + args)


=== Packages/Testing/custom_zodb.py 1.1 => 1.2 ===
+from ZODB.FileStorage import FileStorage
+from ZODB.DemoStorage import DemoStorage
+
+dfi = os.path.join(SOFTWARE_HOME, '..', '..', 'var', 'Data.fs.in')
+dfi = os.path.abspath(dfi)
+Storage = DemoStorage(base=FileStorage(dfi, read_only=1), quota=(1<<20))


=== Packages/Testing/__init__.py 1.2 => 1.3 ===
 $Id$
 """
-import os, sys
-startfrom = head = os.getcwd()
+import os
 
-while 1:
-    sys.path[0]=startfrom
-    try:
-        import ZODB
-    except ImportError:
-        head = os.path.split(startfrom)[0]
-        if head == '':
-            raise "Couldn't import ZODB"
-        startfrom = head
-        continue
-    else:
-        break
+def pdir(path):
+    return os.path.split(path)[0]
 
-os.environ['SOFTWARE_HOME']=os.environ.get('SOFTWARE_HOME', startfrom)
+# Set the INSTANCE_HOME to the Testing package directory
+os.environ['INSTANCE_HOME'] = INSTANCE_HOME = pdir(__file__)
 
-os.environ['INSTANCE_HOME']=os.environ.get(
-    'INSTANCE_HOME',
-    os.path.join(os.environ['SOFTWARE_HOME'],'..','..')
-    )
+# Set the SOFTWARE_HOME to the directory containing the Testing package
+os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME = pdir(INSTANCE_HOME)
+
+# Prevent useless initialization by pretending to be a ZEO client
+os.environ['ZEO_CLIENT'] = '1'