Back to index

plone3  3.1.7
framework.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # ZopeTestCase
00004 #
00005 # COPY THIS FILE TO YOUR 'tests' DIRECTORY.
00006 #
00007 # This version of framework.py will use the SOFTWARE_HOME
00008 # environment variable to locate Zope and the Testing package.
00009 #
00010 # If the tests are run in an INSTANCE_HOME installation of Zope,
00011 # Products.__path__ and sys.path with be adjusted to include the
00012 # instance's Products and lib/python directories respectively.
00013 #
00014 # If you explicitly set INSTANCE_HOME prior to running the tests,
00015 # auto-detection is disabled and the specified path will be used
00016 # instead.
00017 #
00018 # If the 'tests' directory contains a custom_zodb.py file, INSTANCE_HOME
00019 # will be adjusted to use it.
00020 #
00021 # If you set the ZEO_INSTANCE_HOME environment variable a ZEO setup
00022 # is assumed, and you can attach to a running ZEO server (via the
00023 # instance's custom_zodb.py).
00024 #
00025 ##############################################################################
00026 #
00027 # The following code should be at the top of every test module:
00028 #
00029 # import os, sys
00030 # if __name__ == '__main__':
00031 #     execfile(os.path.join(sys.path[0], 'framework.py'))
00032 #
00033 # ...and the following at the bottom:
00034 #
00035 # if __name__ == '__main__':
00036 #     framework()
00037 #
00038 ##############################################################################
00039 
00040 __version__ = '0.2.3'
00041 
00042 # Save start state
00043 #
00044 __SOFTWARE_HOME = os.environ.get('SOFTWARE_HOME', '')
00045 __INSTANCE_HOME = os.environ.get('INSTANCE_HOME', '')
00046 
00047 if __SOFTWARE_HOME.endswith(os.sep):
00048     __SOFTWARE_HOME = os.path.dirname(__SOFTWARE_HOME)
00049 
00050 if __INSTANCE_HOME.endswith(os.sep):
00051     __INSTANCE_HOME = os.path.dirname(__INSTANCE_HOME)
00052 
00053 # Find and import the Testing package
00054 #
00055 if not sys.modules.has_key('Testing'):
00056     p0 = sys.path[0]
00057     if p0 and __name__ == '__main__':
00058         os.chdir(p0)
00059         p0 = ''
00060     s = __SOFTWARE_HOME
00061     p = d = s and s or os.getcwd()
00062     while d:
00063         if os.path.isdir(os.path.join(p, 'Testing')):
00064             zope_home = os.path.dirname(os.path.dirname(p))
00065             sys.path[:1] = [p0, p, zope_home]
00066             break
00067         p, d = s and ('','') or os.path.split(p)
00068     else:
00069         print 'Unable to locate Testing package.',
00070         print 'You might need to set SOFTWARE_HOME.'
00071         sys.exit(1)
00072 
00073 import Testing, unittest
00074 execfile(os.path.join(os.path.dirname(Testing.__file__), 'common.py'))
00075 
00076 # Try to find the test.py testrunner from Zope 2.7
00077 # and if found, use it's ImmediateTestRunner
00078 __ZOPE_HOME = os.path.join(__SOFTWARE_HOME, '..', '..')
00079 __TESTRUNNER = os.path.join(__ZOPE_HOME, 'test.py')
00080 if os.path.isfile(__TESTRUNNER):
00081     global TestRunner
00082     GLB = {'__name__':None}
00083     execfile(__TESTRUNNER, GLB)
00084     def ImmediateTestRunner(*args):
00085         stream = sys.stdout
00086         descriptions = 0
00087         verbosity = 1
00088         if len(args) == 3:
00089             stream, descriptions, verbosity = args
00090         return GLB['ImmediateTestRunner'](stream=stream,
00091                                           descriptions=descriptions,
00092                                           verbosity=verbosity,
00093                                           progress=1)
00094     TestRunner = ImmediateTestRunner
00095 
00096 # Include ZopeTestCase support
00097 #
00098 if 1:   # Create a new scope
00099 
00100     p = os.path.join(os.path.dirname(Testing.__file__), 'ZopeTestCase')
00101 
00102     if not os.path.isdir(p):
00103         print 'Unable to locate ZopeTestCase package.',
00104         print 'You might need to install ZopeTestCase.'
00105         sys.exit(1)
00106 
00107     ztc_common = 'ztc_common.py'
00108     ztc_common_global = os.path.join(p, ztc_common)
00109 
00110     f = 0
00111     if os.path.exists(ztc_common_global):
00112         execfile(ztc_common_global)
00113         f = 1
00114     if os.path.exists(ztc_common):
00115         execfile(ztc_common)
00116         f = 1
00117 
00118     if not f:
00119         print 'Unable to locate %s.' % ztc_common
00120         sys.exit(1)
00121 
00122 # Debug
00123 #
00124 print 'SOFTWARE_HOME: %s' % os.environ.get('SOFTWARE_HOME', 'Not set')
00125 print 'INSTANCE_HOME: %s' % os.environ.get('INSTANCE_HOME', 'Not set')
00126 sys.stdout.flush()