Commit a0e1ac20 authored by Julien Muchembled's avatar Julien Muchembled

Clean up runUnitTest

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41770 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 279562e4
......@@ -218,8 +218,8 @@ class TestManualDefaultSetup(ERP5TypeLiveTestCase):
'-c', self.slapgrid_buildout_cfg_file, 'buildout:directory=%s'%
self.slapgrid_buildout_directory]
self.callAndPrint(command_list, cwd=self.slapgrid_buildout_directory,
remove_from_env=['COPY_OF_SOFTWARE_HOME', 'SOFTWARE_HOME', 'PYTHONPATH',
'ZOPE_HOME', 'CLIENT_HOME'])
remove_from_env=['SOFTWARE_HOME', 'PYTHONPATH',
'ZOPE_HOME', 'CLIENT_HOME'])
def runSlapgridBuildout(self):
command_list = [self.python_binary, '-S', self.buildout_binary, '-U', '-c',
......@@ -227,7 +227,7 @@ class TestManualDefaultSetup(ERP5TypeLiveTestCase):
'buildout:directory=%s'% self.slapgrid_buildout_directory,
'buildout:find-links=%s' % 'https://nexedivifib1.dyn.majimoto.net:40443/'\
'erp5/web_site_module/erpypi/']
self.callAndPrint(command_list, remove_from_env=['COPY_OF_SOFTWARE_HOME',
self.callAndPrint(command_list, remove_from_env=[
'SOFTWARE_HOME', 'PYTHONPATH', 'ZOPE_HOME', 'CLIENT_HOME'])
def shutdownSupervisor(self):
......@@ -255,7 +255,7 @@ class TestManualDefaultSetup(ERP5TypeLiveTestCase):
'--master-url', self.portal.portal_slap.absolute_url(),
'--computer-id', sequence.get('computer').getReference(),
'--supervisord-socket', self.supervisor_socket]
self.callAndPrint(command_list, remove_from_env=['COPY_OF_SOFTWARE_HOME',
self.callAndPrint(command_list, remove_from_env=[
'SOFTWARE_HOME', 'PYTHONPATH', 'ZOPE_HOME', 'CLIENT_HOME'])
def stepRunSlapgridWithoutAssert(self, sequence=None):
......@@ -277,7 +277,7 @@ class TestManualDefaultSetup(ERP5TypeLiveTestCase):
'--computer-id', sequence.get('computer').getReference(),
'--supervisord-socket', self.supervisor_socket]
return self.callAndPrint(command_list, remove_from_env=[
'COPY_OF_SOFTWARE_HOME', 'SOFTWARE_HOME', 'PYTHONPATH', 'ZOPE_HOME',
'SOFTWARE_HOME', 'PYTHONPATH', 'ZOPE_HOME',
'CLIENT_HOME'], asserts=False)
def stepPrepareTestingEnvironment(self, sequence=None):
......
306
\ No newline at end of file
307
\ No newline at end of file
......@@ -292,11 +292,11 @@ class ERP5TypeTestCase(ProcessingNodeTestCase, PortalTestCase):
'with --update_business_templates or without --load')
def getRevision(self):
erp5_path = os.path.join(instancehome, 'Products', 'ERP5')
try:
import pysvn
return pysvn.Client().info('%s/Products/ERP5'
% os.environ['INSTANCE_HOME']).revision.number
except:
return pysvn.Client().info(erp5_path).revision.number
except Exception:
return None
def getTitle(self):
......@@ -417,7 +417,7 @@ class ERP5TypeTestCase(ProcessingNodeTestCase, PortalTestCase):
if bt5_path:
bt5_path_list = bt5_path.split(',')
else:
bt5_path = os.path.join(os.environ['INSTANCE_HOME'], 'bt5')
bt5_path = os.path.join(instancehome, 'bt5')
bt5_path_list = bt5_path, os.path.join(bt5_path, '*')
def search(path, template):
......@@ -485,23 +485,6 @@ class ERP5TypeTestCase(ProcessingNodeTestCase, PortalTestCase):
'''Sets up the fixture. Do not override,
use the hooks instead.
'''
# This is a workaround for the overwriting problem in Testing/__init__.py
# in Zope. So this overwrites them again to revert the changes made by
# Testing.
# XXX: Leo: Is this still true? We need to reevaluate how we get
# information from our environment.
try:
import App.config
except ImportError:
os.environ['INSTANCE_HOME'] = INSTANCE_HOME =\
os.environ['COPY_OF_INSTANCE_HOME']
os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME =\
os.environ['COPY_OF_SOFTWARE_HOME']
else:
cfg = App.config.getConfiguration()
cfg.instancehome = os.environ['COPY_OF_INSTANCE_HOME']
App.config.setConfiguration(cfg)
use_dummy_mail_host = os.environ.get('use_dummy_mail_host', 0)
template_list = self.getBusinessTemplateList()
erp5_catalog_storage = os.environ.get('erp5_catalog_storage',
......
......@@ -8,7 +8,6 @@ from Testing import ZopeTestCase
from zLOG import LOG, ERROR
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
from Products.ERP5Type.tests import backportUnittest
from Products.ERP5Type.tests.runUnitTest import tests_home
from Products.ERP5Type.tests.utils import createZServer
......@@ -91,6 +90,7 @@ class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase):
"""Start HTTP ZServer in background"""
utils = ZopeTestCase.utils
if utils._Z2HOST is None:
from Products.ERP5Type.tests.runUnitTest import tests_home
log = os.path.join(tests_home, "Z2.log")
_print = lambda hs: verbose and ZopeTestCase._print(
"Running %s server at %s:%s\n" % (
......
......@@ -146,6 +146,9 @@ def getUnitTestFile():
def initializeInstanceHome(tests_framework_home,
real_instance_home,
instance_home):
assert (os.path.isabs(tests_framework_home)
and os.path.isabs(real_instance_home)
and os.path.isabs(instance_home))
if not os.path.exists(instance_home):
os.mkdir(instance_home)
if not WIN:
......@@ -223,23 +226,20 @@ else:
'/usr/lib/zope2.8/lib/python',
'/usr/lib/zope/lib/python',
]
if WIN:
erp5_home = os.path.sep.join(tests_framework_home.split(os.path.sep)[:-4])
common_paths = [os.path.join(erp5_home, 'Zope', 'lib', 'python')]
# maybe SOFTWARE_HOME is already in sys.path
try:
import Zope2
except ImportError:
pass
else:
common_paths.insert(0, os.path.dirname(os.path.dirname(Zope2.__file__)))
if WIN:
erp5_home = os.path.sep.join(
tests_framework_home.split(os.path.sep)[:-4])
common_paths.insert(0, os.path.join(erp5_home, 'Zope', 'lib', 'python'))
for software_home in common_paths:
if os.path.isdir(software_home):
break
for software_home in common_paths:
if os.path.isdir(software_home):
break
else:
raise
else:
sys.exit('No Zope2 software_home found')
software_home = os.path.dirname(os.path.dirname(Zope2.__file__))
os.environ['SOFTWARE_HOME'] = software_home
# software_home is zope_home/lib/python, remove lib/python
......@@ -254,22 +254,15 @@ if software_home not in sys.path:
if WIN:
real_instance_home = os.path.join(erp5_home, 'ERP5Instance')
elif tests_framework_home.startswith('/usr/lib'):
if os.path.isdir('/var/lib/erp5'):
real_instance_home = '/var/lib/erp5'
else:
real_instance_home = '/var/lib/erp5'
if not os.path.isdir(real_instance_home):
real_instance_home = '/var/lib/zope'
elif os.environ.get('REAL_INSTANCE_HOME', None) is not None:
# The user Defined where is the REAL INSTANCE HOME
# So we should use it
real_instance_home = os.environ.get('REAL_INSTANCE_HOME')
elif 'REAL_INSTANCE_HOME' in os.environ:
real_instance_home = os.path.abspath(os.environ['REAL_INSTANCE_HOME'])
else:
real_instance_home = os.path.sep.join(
tests_framework_home.split(os.path.sep)[:-3])
instance_home = os.path.join(real_instance_home, 'unit_test')
real_tests_home = os.path.join(real_instance_home, 'tests')
tests_home = os.path.join(instance_home, 'tests')
class ERP5TypeTestLoader(unittest.TestLoader):
"""Load test cases from the name passed on the command line.
......@@ -356,11 +349,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
if "zeo_client" in os.environ and "zeo_server" in os.environ:
_print("conflicting options: --zeo_client and --zeo_server")
sys.exit(1)
os.environ.setdefault('INSTANCE_HOME', instance_home)
os.environ.setdefault('SOFTWARE_HOME', software_home)
os.environ.setdefault('COPY_OF_INSTANCE_HOME', instance_home)
os.environ.setdefault('COPY_OF_SOFTWARE_HOME', software_home)
instance_home = os.environ['INSTANCE_HOME']
os.environ.setdefault('EVENT_LOG_FILE', os.path.join(tests_home, 'zLOG.log'))
os.environ.setdefault('EVENT_LOG_SEVERITY', '-300')
......@@ -388,8 +377,6 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
# On Zope 2.12, import_products() is called by ERP5TestCase before it is
# patched by the layer.setUp() call.
import OFS.Application
if os.environ.get('products_path'):
OFS.Application.Products.__path__ = os.environ.get('products_path').split(',')
import_products = OFS.Application.import_products
from Testing import ZopeTestCase # Zope 2.8: this will import custom_zodb.py
OFS.Application.import_products = import_products
......@@ -435,7 +422,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
sys.path.extend(bt5_test_list)
sys.path.extend(project_bt5_test_list)
sys.path.extend((real_tests_home, tests_home))
sys.path.extend((os.path.join(real_instance_home, 'tests'), tests_home))
# Make sure that locally overridden python modules are used
sys.path.insert(0, os.path.join(real_instance_home, 'lib', 'python'))
......@@ -615,7 +602,7 @@ def main():
"zeo_server=",
"zserver=",
"products_path=",
"sys_path="
"sys_path=",
])
except getopt.GetoptError, msg:
usage(sys.stderr, msg)
......@@ -627,6 +614,7 @@ def main():
os.environ["erp5_tests_recreate_catalog"] = "0"
verbosity = 1
debug = 0
instance_home = os.path.join(real_instance_home, 'unit_test')
for opt, arg in opts:
if opt in ("-v", "--verbose"):
......@@ -706,11 +694,16 @@ def main():
elif opt == "--zserver":
os.environ["zserver"] = arg
elif opt == "--products_path":
os.environ["products_path"] = arg
os.environ["PRODUCTS_PATH"] = arg
elif opt == "--sys_path":
sys.path.extend(arg.split(','))
initializeInstanceHome(tests_framework_home, real_instance_home, instance_home)
global tests_home
os.environ['INSTANCE_HOME'] = instance_home
tests_home = os.path.join(instance_home, 'tests')
initializeInstanceHome(tests_framework_home,
real_instance_home,
instance_home)
result = runUnitTestList(test_list=args,
verbosity=verbosity,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment