Commit b7a2fe76 authored by Julien Muchembled's avatar Julien Muchembled

Simplify code by changing current directory and try to use relative symlinks

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34971 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 854a576d
...@@ -6,18 +6,17 @@ import ZODB ...@@ -6,18 +6,17 @@ 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
from runUnitTest import instance_home, static_dir_list
def _print(message): def _print(message):
sys.stderr.write(message + "\n") sys.stderr.write(message + "\n")
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'))
load = int(os.environ.get('erp5_load_data_fs', 0)) load = int(os.environ.get('erp5_load_data_fs', 0))
save = int(os.environ.get('erp5_save_data_fs', 0)) save = int(os.environ.get('erp5_save_data_fs', 0))
_print("Cleaning static files ... ") _print("Cleaning static files ... ")
static_dir_list = 'Constraint', 'Document', 'PropertySheet', 'Extensions'
for dir in static_dir_list: for dir in static_dir_list:
for f in glob.glob(os.path.join(instance_home, dir, '*')): for f in glob.glob(os.path.join(instance_home, dir, '*')):
os.remove(f) os.remove(f)
......
...@@ -9,6 +9,7 @@ import unittest ...@@ -9,6 +9,7 @@ import unittest
import shutil import shutil
import errno import errno
import random import random
from glob import glob
import backportUnittest import backportUnittest
...@@ -105,6 +106,8 @@ Options: ...@@ -105,6 +106,8 @@ Options:
""" """
static_dir_list = 'Constraint', 'Document', 'Extensions', 'PropertySheet'
def getUnitTestFile(): def getUnitTestFile():
"""returns the absolute path of this script. """returns the absolute path of this script.
This is used by template tool to run unit tests.""" This is used by template tool to run unit tests."""
...@@ -122,43 +125,52 @@ def initializeInstanceHome(tests_framework_home, ...@@ -122,43 +125,52 @@ def initializeInstanceHome(tests_framework_home,
instance_home): 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:
# Before r23751, Extensions dir was initialized to be a symlink to real # Try to use relative symlinks
# instance home Extensions folder, now it's initialized as an independant if tests_framework_home.startswith(os.path.join(real_instance_home,
# folder. If this test instance still have a symlink for Extensions, change 'Products', '')):
# it in a foler. tests_framework_home = tests_framework_home[len(real_instance_home)+1:]
extensions_path = os.path.join(instance_home, 'Extensions') if real_instance_home == os.path.dirname(instance_home):
if os.path.islink(extensions_path): real_instance_home = 'real_instance'
os.unlink(extensions_path) os.symlink('..', os.path.join(instance_home, real_instance_home))
old_pwd = os.getcwd()
for d in ('Extensions', 'Constraint', 'Document', 'PropertySheet', 'bin', 'etc', 'tests', 'var', 'log'): try:
path = os.path.join(instance_home, d) os.chdir(instance_home)
if not os.path.exists(path): # Before r23751, Extensions dir was initialized to be a symlink to real
os.mkdir(path) # instance home Extensions folder, now it's initialized as an independant
for d in ('Products', 'bt5', 'svn', 'lib'): # folder. If this test instance still have a symlink for Extensions, change
src = os.path.join(real_instance_home, d) # it in a folder.
dst = os.path.join(instance_home, d) if os.path.islink('Extensions'):
if not os.path.exists(dst): os.remove('Extensions')
if os.path.islink(dst):
os.unlink(dst) for d in static_dir_list + ('bin', 'etc', 'tests', 'var', 'log'):
if WIN: if not os.path.exists(d):
if d in ('Products', 'bt5', 'svn'): os.mkdir(d)
os.mkdir(dst) for d in ('Products', 'bt5', 'svn', 'lib'):
if not os.path.exists(d):
src = os.path.join(real_instance_home, d)
if os.path.islink(d):
os.remove(d)
if WIN:
if d in ('Products', 'bt5', 'svn'):
os.mkdir(d)
else:
shutil.copytree(src, d)
else: else:
shutil.copytree(src, dst) os.symlink(src, d)
d = 'custom_zodb.py'
if not os.path.exists(d):
src = os.path.join(tests_framework_home, d)
if os.path.islink(d):
os.remove(d)
if WIN:
shutil.copy(src, d)
else: else:
os.symlink(src, dst) os.symlink(src, d)
src = os.path.join(tests_framework_home, 'custom_zodb.py') finally:
dst = os.path.join(instance_home, 'custom_zodb.py') os.chdir(old_pwd)
if not os.path.exists(dst):
if os.path.islink(dst):
os.unlink(dst)
if WIN:
shutil.copy(src, dst)
else:
os.symlink(src, dst)
kw = { kw = {
"PYTHON":sys.executable, "PYTHON": sys.executable,
"INSTANCE_HOME": instance_home, "INSTANCE_HOME": instance_home,
"SOFTWARE_HOME": software_home, "SOFTWARE_HOME": software_home,
} }
...@@ -175,7 +187,7 @@ def initializeInstanceHome(tests_framework_home, ...@@ -175,7 +187,7 @@ def initializeInstanceHome(tests_framework_home,
import copyzopeskel import copyzopeskel
kw['ZOPE_HOME'] = zope_home kw['ZOPE_HOME'] = zope_home
skeldir = 'skel' skeldir = 'skel'
skelsrc = os.path.abspath(os.path.join(os.path.dirname(__file__), skeldir)) skelsrc = os.path.abspath(os.path.join(tests_framework_home, skeldir))
copyzopeskel.copyskel(skelsrc, instance_home, None, None, **kw) copyzopeskel.copyskel(skelsrc, instance_home, None, None, **kw)
# site specific variables # site specific variables
...@@ -240,9 +252,6 @@ tests_home = os.path.join(instance_home, 'tests') ...@@ -240,9 +252,6 @@ tests_home = os.path.join(instance_home, 'tests')
initializeInstanceHome(tests_framework_home, real_instance_home, instance_home) initializeInstanceHome(tests_framework_home, real_instance_home, instance_home)
if '__INSTANCE_HOME' not in globals().keys() :
__INSTANCE_HOME = instance_home
class FilteredTestSuite(unittest.TestSuite): class FilteredTestSuite(unittest.TestSuite):
"""Marker class to identify TestSuites that we have already filtered""" """Marker class to identify TestSuites that we have already filtered"""
...@@ -404,9 +413,8 @@ def runUnitTestList(test_list, verbosity=1, debug=0): ...@@ -404,9 +413,8 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
eventlog() eventlog()
except ImportError: except ImportError:
pass pass
# allow unit tests of our Products or business templates to be reached. # allow unit tests of our Products or business templates to be reached.
from glob import glob
product_test_list = glob(os.path.join(products_home, '*', 'tests')) product_test_list = glob(os.path.join(products_home, '*', 'tests'))
sys.path.extend(product_test_list) sys.path.extend(product_test_list)
erp5_tests_bt5_path = os.environ.get('erp5_tests_bt5_path', erp5_tests_bt5_path = os.environ.get('erp5_tests_bt5_path',
...@@ -488,19 +496,18 @@ def runUnitTestList(test_list, verbosity=1, debug=0): ...@@ -488,19 +496,18 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
result = TestRunner(verbosity=verbosity).run(suite) result = TestRunner(verbosity=verbosity).run(suite)
if save: if save:
os.chdir(instance_home)
from Products.ERP5Type.tests.utils import getMySQLArguments from Products.ERP5Type.tests.utils import getMySQLArguments
# The output of mysqldump needs to merge many lines at a time # The output of mysqldump needs to merge many lines at a time
# for performance reasons (merging lines is at most 10 times # for performance reasons (merging lines is at most 10 times
# faster, so this produce somewhat not nice to read sql # faster, so this produce somewhat not nice to read sql
command = 'mysqldump %s > %s' % (getMySQLArguments(), command = 'mysqldump %s > dump.sql' % getMySQLArguments()
os.path.join(instance_home, 'dump.sql'))
if verbosity: if verbosity:
_print('Dumping MySQL database with %s...\n' % command) _print('Dumping MySQL database with %s...\n' % command)
os.system(command) os.system(command)
if verbosity: if verbosity:
_print('Dumping static files...\n') _print('Dumping static files...\n')
for static_dir in 'Constraint', 'Document', 'Extensions', 'PropertySheet': for static_dir in static_dir_list:
static_dir = os.path.join(instance_home, static_dir)
try: try:
shutil.rmtree(static_dir + '.bak') shutil.rmtree(static_dir + '.bak')
except OSError, e: except OSError, e:
......
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