Back to index

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