Commit a820bf49 authored by Julien Muchembled's avatar Julien Muchembled

Unit test: print first line to stderr (this fixes ouput of testPerformance)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30459 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4ea0ac28
import os
import shutil
import sys
import glob
import ZODB
from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage import FileStorage
from Products.ERP5Type.tests.utils import getMySQLArguments
_print = sys.stderr.write
instance_home = os.environ.get('INSTANCE_HOME')
data_fs_path = os.environ.get('erp5_tests_data_fs_path',
os.path.join(instance_home, 'Data.fs'))
......@@ -15,12 +18,12 @@ save = int(os.environ.get('erp5_save_data_fs', 0))
if load:
dump_sql = os.path.join(instance_home, 'dump.sql')
if os.path.exists(dump_sql):
print "Restoring MySQL database ...",
_print("Restoring MySQL database ... ")
ret = os.system("mysql %s < %s" % (getMySQLArguments(), dump_sql))
assert not ret
else:
os.environ['erp5_tests_recreate_catalog'] = '1'
print "Restoring static files ...",
_print("Restoring static files ... ")
for dir in ('Constraint', 'Document', 'PropertySheet', 'Extensions'):
if os.path.exists(os.path.join(instance_home, '%s.bak' % dir)):
full_path = os.path.join(instance_home, dir)
......@@ -28,7 +31,7 @@ if load:
shutil.copytree(os.path.join(instance_home, '%s.bak' % dir),
full_path, symlinks=True)
else:
print "Cleaning static files ...",
_print("Cleaning static files ... ")
for dir in ('Constraint', 'Document', 'PropertySheet', 'Extensions'):
full_path = os.path.join(instance_home, dir)
if os.path.exists(full_path):
......@@ -45,4 +48,4 @@ elif load:
else:
Storage = DemoStorage()
print "Instance at %r loaded ..." % instance_home,
_print("Instance at %r loaded ... " % instance_home)
......@@ -291,10 +291,11 @@ class DebugTestResult:
def __getattr__(self, attr):
return getattr(self.result, attr)
_print = sys.stderr.write
def runUnitTestList(test_list, verbosity=1, debug=0):
if not test_list:
print "No test to run, exiting immediately."
_print("No test to run, exiting immediately.\n")
return
os.environ.setdefault('INSTANCE_HOME', instance_home)
os.environ.setdefault('SOFTWARE_HOME', software_home)
......@@ -303,7 +304,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
os.environ.setdefault('EVENT_LOG_FILE', os.path.join(tests_home, 'zLOG.log'))
os.environ.setdefault('EVENT_LOG_SEVERITY', '-300')
print "Loading Zope ...",
_print("Loading Zope ... ")
_start = time.time()
import Testing
......@@ -431,7 +432,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
# ourselves
layer.ZopeLite.setUp()
print 'done (%.3fs)' % (time.time() - _start),
_print('done (%.3fs)' % (time.time() - _start))
result = TestRunner(verbosity=verbosity).run(suite)
if save:
......@@ -442,10 +443,10 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
command = 'mysqldump %s > %s' % (getMySQLArguments(),
os.path.join(instance_home, 'dump.sql'))
if verbosity:
print('Dumping MySQL database with %s... ' % command)
_print('Dumping MySQL database with %s...\n' % command)
os.system(command)
if verbosity:
print('Dumping static files... ')
_print('Dumping static files...\n')
for static_dir in 'Constraint', 'Document', 'Extensions', 'PropertySheet':
static_dir = os.path.join(instance_home, static_dir)
try:
......@@ -538,7 +539,7 @@ def main():
test_list = args
if not test_list:
print "No test to run, exiting immediately."
_print("No test to run, exiting immediately.\n")
sys.exit(1)
result = runUnitTestList(test_list=test_list,
......@@ -548,7 +549,7 @@ def main():
from Testing.ZopeTestCase import profiler
except ImportError:
if os.environ.get('PROFILE_TESTS') == '1':
print "Profiler support is not available from ZopeTestCase in Zope 2.12"
_print("Profiler support is not available from ZopeTestCase in Zope 2.12\n")
else:
profiler.print_stats()
sys.exit(len(result.failures) + len(result.errors))
......
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