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