[Erp5-report] r30343 - in /erp5/trunk/products/ERP5Type/tests: framework.py runUnitTest.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Nov 5 17:09:42 CET 2009


Author: leonardo
Date: Thu Nov  5 17:09:40 2009
New Revision: 30343

URL: http://svn.erp5.org?rev=30343&view=rev
Log:
Stop depending on ERP5Type/tests/framework.py

It breaks on Zope 2.12, it is horribly confusing, and does not actually help us much.

Removed:
    erp5/trunk/products/ERP5Type/tests/framework.py
Modified:
    erp5/trunk/products/ERP5Type/tests/runUnitTest.py

Removed: erp5/trunk/products/ERP5Type/tests/framework.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/framework.py?rev=30342&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/framework.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/framework.py (removed)
@@ -1,110 +1,0 @@
-##############################################################################
-#
-# ZopeTestCase 
-#
-# COPY THIS FILE TO YOUR 'tests' DIRECTORY.
-#
-# This version of framework.py will use the SOFTWARE_HOME
-# environment variable to locate Zope and the Testing package.
-#
-# If the tests are run in an INSTANCE_HOME installation of Zope,
-# Products.__path__ and sys.path with be adjusted to include the
-# instance's Products and lib/python directories respectively.
-#
-# If you explicitly set INSTANCE_HOME prior to running the tests,
-# auto-detection is disabled and the specified path will be used 
-# instead.
-#
-# If the 'tests' directory contains a custom_zodb.py file, INSTANCE_HOME
-# will be adjusted to use it.
-#
-# If you set the ZEO_INSTANCE_HOME environment variable a ZEO setup 
-# is assumed, and you can attach to a running ZEO server (via the 
-# instance's custom_zodb.py).
-#
-##############################################################################
-#
-# The following code should be at the top of every test module:
-#
-# import os, sys
-# if __name__ == '__main__':
-#     execfile(os.path.join(sys.path[0], 'framework.py'))
-#
-# ...and the following at the bottom:
-#
-# if __name__ == '__main__':
-#     framework()
-#
-##############################################################################
-
-import os
-import sys
-
-__version__ = '0.2.3'
-
-# Save start state
-#
-__SOFTWARE_HOME = os.environ.get('SOFTWARE_HOME', '')
-__INSTANCE_HOME = os.environ.get('INSTANCE_HOME', '')
-
-if __SOFTWARE_HOME.endswith(os.sep):
-    __SOFTWARE_HOME = os.path.dirname(__SOFTWARE_HOME)
-
-if __INSTANCE_HOME.endswith(os.sep):
-    __INSTANCE_HOME = os.path.dirname(__INSTANCE_HOME)
-
-# Find and import the Testing package
-#
-if not sys.modules.has_key('Testing'):
-    p0 = sys.path[0]
-    if p0 and __name__ == '__main__':
-        os.chdir(p0)
-        p0 = ''
-    s = __SOFTWARE_HOME
-    p = d = s and s or os.getcwd()
-    while d:
-        if os.path.isdir(os.path.join(p, 'Testing')):
-            zope_home = os.path.dirname(os.path.dirname(p))
-            sys.path[:1] = [p0, p, zope_home]
-            break
-        p, d = s and ('','') or os.path.split(p)
-    else:
-        print 'Unable to locate Testing package.',
-        print 'You might need to set SOFTWARE_HOME.'
-        sys.exit(1)
-
-import Testing, unittest
-execfile(os.path.join(os.path.dirname(Testing.__file__), 'common.py'))
-
-# Include ZopeTestCase support
-#
-if 1:   # Create a new scope
-
-    p = os.path.join(os.path.dirname(Testing.__file__), 'ZopeTestCase')
-
-    if not os.path.isdir(p):
-        print 'Unable to locate ZopeTestCase package.',
-        print 'You might need to install ZopeTestCase.'
-        sys.exit(1)
-
-    ztc_common = 'ztc_common.py'
-    ztc_common_global = os.path.join(p, ztc_common) 
-
-    f = 0
-    if os.path.exists(ztc_common_global):
-        execfile(ztc_common_global)
-        f = 1
-    if os.path.exists(ztc_common):
-        execfile(ztc_common)
-        f = 1
-
-    if not f:
-        print 'Unable to locate %s.' % ztc_common
-        sys.exit(1)
-
-# Debug
-#
-print 'SOFTWARE_HOME: %s' % os.environ.get('SOFTWARE_HOME', 'Not set')
-print 'INSTANCE_HOME: %s' % os.environ.get('INSTANCE_HOME', 'Not set')
-sys.stdout.flush()
-

Modified: erp5/trunk/products/ERP5Type/tests/runUnitTest.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/runUnitTest.py?rev=30343&r1=30342&r2=30343&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/runUnitTest.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/runUnitTest.py [utf8] Thu Nov  5 17:09:40 2009
@@ -160,6 +160,12 @@
   else:
     zope_home = '/usr/lib/zope'
   software_home = os.path.join(zope_home, 'lib', 'python')
+  os.environ['SOFTWARE_HOME'] = software_home
+
+# SOFTWARE_HOME must be early in sys.path, otherwise some products will
+# import ImageFile from PIL instead of from Zope!
+if software_home not in sys.path:
+  sys.path.insert(0, software_home)
 
 # handle 'system global' instance and windows
 if WIN:
@@ -288,9 +294,15 @@
   os.environ.setdefault('EVENT_LOG_FILE', os.path.join(tests_home, 'zLOG.log'))
   os.environ.setdefault('EVENT_LOG_SEVERITY', '-300')
 
-  execfile(os.path.join(tests_framework_home, 'framework.py'),
-              dict(__name__='__main__'))
-  
+  import Testing
+  # the above import changes cfg.testinghome. Reset it to where our
+  # custom_zodb.py can be found. This must be done before importing
+  # ZopeTestCase below (Leo: I hate import side-effects with a passion).
+  import App.config
+  cfg = App.config.getConfiguration()
+  cfg.testinghome = instance_home
+  App.config.setConfiguration(cfg)
+
   if WIN:
     products_home = os.path.join(real_instance_home, 'Products')
     import Products




More information about the Erp5-report mailing list