Back to index

plone3  3.1.7
framework.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 ## GroupUserFolder
00003 ## Copyright (C)2006 Ingeniweb
00004 
00005 ## This program is free software; you can redistribute it and/or modify
00006 ## it under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2 of the License, or
00008 ## (at your option) any later version.
00009 
00010 ## This program is distributed in the hope that it will be useful,
00011 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ## GNU General Public License for more details.
00014 
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with this program; see the file COPYING. If not, write to the
00017 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 """
00019 
00020 """
00021 __version__ = "$Revision:  $"
00022 # $Source:  $
00023 # $Id: framework.py 30098 2006-09-08 12:35:01Z encolpe $
00024 __docformat__ = 'restructuredtext'
00025 
00026 ##############################################################################
00027 #
00028 # ZopeTestCase
00029 #
00030 # COPY THIS FILE TO YOUR 'tests' DIRECTORY.
00031 #
00032 # This version of framework.py will use the SOFTWARE_HOME
00033 # environment variable to locate Zope and the Testing package.
00034 #
00035 # If the tests are run in an INSTANCE_HOME installation of Zope,
00036 # Products.__path__ and sys.path with be adjusted to include the
00037 # instance's Products and lib/python directories respectively.
00038 #
00039 # If you explicitly set INSTANCE_HOME prior to running the tests,
00040 # auto-detection is disabled and the specified path will be used
00041 # instead.
00042 #
00043 # If the 'tests' directory contains a custom_zodb.py file, INSTANCE_HOME
00044 # will be adjusted to use it.
00045 #
00046 # If you set the ZEO_INSTANCE_HOME environment variable a ZEO setup
00047 # is assumed, and you can attach to a running ZEO server (via the
00048 # instance's custom_zodb.py).
00049 #
00050 ##############################################################################
00051 #
00052 # The following code should be at the top of every test module:
00053 #
00054 # import os, sys
00055 # if __name__ == '__main__':
00056 #     execfile(os.path.join(sys.path[0], 'framework.py'))
00057 #
00058 # ...and the following at the bottom:
00059 #
00060 # if __name__ == '__main__':
00061 #     framework()
00062 #
00063 ##############################################################################
00064 
00065 __version__ = '0.2.3'
00066 
00067 # Save start state
00068 #
00069 __SOFTWARE_HOME = os.environ.get('SOFTWARE_HOME', '')
00070 __INSTANCE_HOME = os.environ.get('INSTANCE_HOME', '')
00071 
00072 if __SOFTWARE_HOME.endswith(os.sep):
00073     __SOFTWARE_HOME = os.path.dirname(__SOFTWARE_HOME)
00074 
00075 if __INSTANCE_HOME.endswith(os.sep):
00076     __INSTANCE_HOME = os.path.dirname(__INSTANCE_HOME)
00077 
00078 # Find and import the Testing package
00079 #
00080 if not sys.modules.has_key('Testing'):
00081     p0 = sys.path[0]
00082     if p0 and __name__ == '__main__':
00083         os.chdir(p0)
00084         p0 = ''
00085     s = __SOFTWARE_HOME
00086     p = d = s and s or os.getcwd()
00087     while d:
00088         if os.path.isdir(os.path.join(p, 'Testing')):
00089             zope_home = os.path.dirname(os.path.dirname(p))
00090             sys.path[:1] = [p0, p, zope_home]
00091             break
00092         p, d = s and ('','') or os.path.split(p)
00093     else:
00094         print 'Unable to locate Testing package.',
00095         print 'You might need to set SOFTWARE_HOME.'
00096         sys.exit(1)
00097 
00098 import Testing, unittest
00099 execfile(os.path.join(os.path.dirname(Testing.__file__), 'common.py'))
00100 
00101 # Include ZopeTestCase support
00102 #
00103 if 1:   # Create a new scope
00104 
00105     p = os.path.join(os.path.dirname(Testing.__file__), 'ZopeTestCase')
00106 
00107     if not os.path.isdir(p):
00108         print 'Unable to locate ZopeTestCase package.',
00109         print 'You might need to install ZopeTestCase.'
00110         sys.exit(1)
00111 
00112     ztc_common = 'ztc_common.py'
00113     ztc_common_global = os.path.join(p, ztc_common)
00114 
00115     f = 0
00116     if os.path.exists(ztc_common_global):
00117         execfile(ztc_common_global)
00118         f = 1
00119     if os.path.exists(ztc_common):
00120         execfile(ztc_common)
00121         f = 1
00122 
00123     if not f:
00124         print 'Unable to locate %s.' % ztc_common
00125         sys.exit(1)
00126 
00127 # Debug
00128 #
00129 print 'SOFTWARE_HOME: %s' % os.environ.get('SOFTWARE_HOME', 'Not set')
00130 print 'INSTANCE_HOME: %s' % os.environ.get('INSTANCE_HOME', 'Not set')
00131 sys.stdout.flush()