[Zope-Checkins] CVS: Zope/lib/python/Testing - README.txt:1.2.2.1 ZODButil.py:1.2.2.1 common.py:1.2.2.1 custom_zodb.py:1.2.2.1 __init__.py:1.2.40.1 unittest.py:NONE

Shane Hathaway shane@digicool.com
Thu, 9 Aug 2001 13:34:14 -0400


Update of /cvs-repository/Zope/lib/python/Testing
In directory cvs.zope.org:/tmp/cvs-serv29115/lib/python/Testing

Modified Files:
      Tag: NR-branch
	__init__.py 
Added Files:
      Tag: NR-branch
	README.txt ZODButil.py common.py custom_zodb.py 
Removed Files:
      Tag: NR-branch
	unittest.py 
Log Message:
Sync NR-branch with trunk.  Sorry about so many checkin messages...


=== Added File Zope/lib/python/Testing/README.txt ===
The Testing package is a set of shared routines for the Zope unit
testing framework.   To add a test suite to a Zope package:

1. Make a 'tests' subdirectory.

2. Copy 'framework.py' into 'tests' from any other package's 'tests'.

Once a test suite has been set up, you can add test modules:

1. Create a file with a name matching 'test*.py'.

2. Define one or more subclasses of 'unittest.TestCase'.  The unittest
   module is imported by the framework.

3. Define methods for the test classes.  Each method's name must start
   with 'test'.  It should test one small case, using a Python
   'assert' statement.  Here's a minimal example:

   class testClass1(unittest.TestCase):
       def testAddition(self):
           assert 1 + 1 == 2, 'Addition failed!'

4. You can add 'setUp' and 'tearDown' methods that are automatically
   called at the start and end of the test suite.

5. Follow the instructions in 'framework.py' about adding lines to the
   top and bottom of the file.

Now you can run the test as "python path/to/tests/testName.py", or
simply go to the 'tests' directory and type "python testName.py".


=== Added File Zope/lib/python/Testing/ZODButil.py ===
import os
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)
    


=== Added File Zope/lib/python/Testing/common.py ===
# Default test runner
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)


=== Added File Zope/lib/python/Testing/custom_zodb.py ===
import ZODB, os
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))


=== Zope/lib/python/Testing/__init__.py 1.2 => 1.2.40.1 ===
 $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'
 
 

=== Removed File Zope/lib/python/Testing/unittest.py ===