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