Commit b10c46b5 authored by Nicolas Delaby's avatar Nicolas Delaby

Move some constant definition from options of test execution, to

test modules.
because each test suite defined in a test module can not work
if the constant is False. ie Constant are not Optional.
As an example:
 runCloudOOoUnitTest --with-deamon conf_path testServer.py
can not work without --with-deamon option, so move this flag to testServer.py



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@42069 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 904b2c40
...@@ -30,30 +30,10 @@ def exit(msg): ...@@ -30,30 +30,10 @@ def exit(msg):
sys.stderr.write(msg) sys.stderr.write(msg)
sys.exit(0) sys.exit(0)
def run_test(test_name):
module = __import__(test_name)
if not hasattr(module, "test_suite"):
exit("No test suite to run, exiting immediately")
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
suite.addTest(module.test_suite())
TestRunner(verbosity=2).run(suite)
def run(): def run():
parser = ArgumentParser(description="Unit Test Runner for Cloudooo") parser = ArgumentParser(description="Unit Test Runner for Cloudooo")
parser.add_argument('server_cloudooo_conf') parser.add_argument('server_cloudooo_conf')
parser.add_argument('test_name') parser.add_argument('test_name')
parser.add_argument('--with-daemon', dest='DAEMON',
action='store_true',
help="it starts the cloudooo daemon")
parser.add_argument('--with-openoffice', dest='OPENOFFICE',
action='store_true',
help="it starts one Xvfb and one OpenOffice")
parser.add_argument('--with-xvfb', dest='XVFB',
action='store_true',
help="it starts one Xvfb only")
parser.add_argument('--timeout_limit', dest='timeout_limit', parser.add_argument('--timeout_limit', dest='timeout_limit',
type=long, default=30, type=long, default=30,
help="Timeout to waiting for the cloudooo stop") help="Timeout to waiting for the cloudooo stop")
...@@ -67,10 +47,7 @@ def run(): ...@@ -67,10 +47,7 @@ def run():
if server_cloudooo_conf.startswith(curdir): if server_cloudooo_conf.startswith(curdir):
server_cloudooo_conf = path.join(path.abspath(curdir), server_cloudooo_conf = path.join(path.abspath(curdir),
server_cloudooo_conf) server_cloudooo_conf)
environ['server_cloudooo_conf'] = server_cloudooo_conf
DAEMON = namespace.DAEMON
OPENOFFICE = namespace.OPENOFFICE
XVFB = namespace.XVFB
paster_path = namespace.paster_path paster_path = namespace.paster_path
python_extension = '.py' python_extension = '.py'
...@@ -92,15 +69,27 @@ def run(): ...@@ -92,15 +69,27 @@ def run():
hostname = config.get("app:main", "application_hostname") hostname = config.get("app:main", "application_hostname")
server_port = int(config.get("server:main", "port")) server_port = int(config.get("server:main", "port"))
run_dir = config.get('app:main', 'working_path') run_dir = config.get('app:main', 'working_path')
module = __import__(test_name)
if not hasattr(module, "test_suite"):
exit("No test suite to run, exiting immediately")
DAEMON = getattr(module, 'DAEMON', False)
OPENOFFICE = getattr(module, 'OPENOFFICE', False)
XVFB = getattr(module, 'XVFB', False)
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
suite.addTest(module.test_suite())
if DAEMON: if DAEMON:
loadConfig(server_cloudooo_conf)
command = [paster_path, "serve", server_cloudooo_conf] command = [paster_path, "serve", server_cloudooo_conf]
process = Popen(command) process = Popen(command)
wait_use_port(hostname, openoffice_port) wait_use_port(hostname, openoffice_port)
wait_use_port(hostname, server_port) wait_use_port(hostname, server_port)
chdir(ENVIRONMENT_PATH) chdir(ENVIRONMENT_PATH)
try: try:
run_test(test_name) TestRunner(verbosity=2).run(suite)
finally: finally:
process.send_signal(1) process.send_signal(1)
wait_liberate_port(hostname, server_port) wait_liberate_port(hostname, server_port)
...@@ -110,7 +99,7 @@ def run(): ...@@ -110,7 +99,7 @@ def run():
chdir(ENVIRONMENT_PATH) chdir(ENVIRONMENT_PATH)
openoffice, xvfb = startFakeEnvironment(conf_path=server_cloudooo_conf) openoffice, xvfb = startFakeEnvironment(conf_path=server_cloudooo_conf)
try: try:
run_test(test_name) TestRunner(verbosity=2).run(suite)
finally: finally:
stopFakeEnvironment() stopFakeEnvironment()
elif XVFB: elif XVFB:
...@@ -118,13 +107,12 @@ def run(): ...@@ -118,13 +107,12 @@ def run():
xvfb = startFakeEnvironment(start_openoffice=False, xvfb = startFakeEnvironment(start_openoffice=False,
conf_path=server_cloudooo_conf) conf_path=server_cloudooo_conf)
try: try:
run_test(test_name) TestRunner(verbosity=2).run(suite)
finally: finally:
stopFakeEnvironment(stop_openoffice=False) stopFakeEnvironment(stop_openoffice=False)
else: else:
chdir(ENVIRONMENT_PATH) chdir(ENVIRONMENT_PATH)
loadConfig(server_cloudooo_conf) TestRunner(verbosity=2).run(suite)
run_test(test_name)
if __name__ == "__main__": if __name__ == "__main__":
run() run()
...@@ -32,6 +32,7 @@ from subprocess import Popen, PIPE ...@@ -32,6 +32,7 @@ from subprocess import Popen, PIPE
from base64 import encodestring, decodestring from base64 import encodestring, decodestring
from cloudoooTestCase import CloudoooTestCase, make_suite from cloudoooTestCase import CloudoooTestCase, make_suite
DAEMON = True
class TestAllFormats(CloudoooTestCase): class TestAllFormats(CloudoooTestCase):
"""Test XmlRpc Server. Needs cloudooo server started""" """Test XmlRpc Server. Needs cloudooo server started"""
......
...@@ -34,6 +34,7 @@ from base64 import encodestring, decodestring ...@@ -34,6 +34,7 @@ from base64 import encodestring, decodestring
from multiprocessing import Process from multiprocessing import Process
from cloudoooTestCase import CloudoooTestCase, make_suite from cloudoooTestCase import CloudoooTestCase, make_suite
DAEMON = True
class TestHighLoad(CloudoooTestCase): class TestHighLoad(CloudoooTestCase):
"""Test with many simultaneous connection""" """Test with many simultaneous connection"""
......
...@@ -168,6 +168,7 @@ chart_expected_tuple = (('sds', 'StarChart 3.0'), ...@@ -168,6 +168,7 @@ chart_expected_tuple = (('sds', 'StarChart 3.0'),
('sxs', 'OpenOffice.org 1.0 Chart'), ('sxs', 'OpenOffice.org 1.0 Chart'),
('odc', 'ODF Chart')) ('odc', 'ODF Chart'))
OPENOFFICE = True
class TestMimeMapper(CloudoooTestCase): class TestMimeMapper(CloudoooTestCase):
"""Test if object load filters correctly of OOo.""" """Test if object load filters correctly of OOo."""
......
...@@ -32,6 +32,7 @@ from cloudoooTestCase import CloudoooTestCase, make_suite ...@@ -32,6 +32,7 @@ from cloudoooTestCase import CloudoooTestCase, make_suite
from cloudooo.handler.ooo.monitor.request import MonitorRequest from cloudooo.handler.ooo.monitor.request import MonitorRequest
from cloudooo.handler.ooo.monitor.memory import MonitorMemory from cloudooo.handler.ooo.monitor.memory import MonitorMemory
OPENOFFICE = True
class TestMonitorInit(CloudoooTestCase): class TestMonitorInit(CloudoooTestCase):
"""Test Case to test if the monitors are controlled correctly""" """Test Case to test if the monitors are controlled correctly"""
......
...@@ -34,6 +34,7 @@ from psutil import Process ...@@ -34,6 +34,7 @@ from psutil import Process
from types import IntType from types import IntType
from cloudoooTestCase import make_suite from cloudoooTestCase import make_suite
OPENOFFICE = True
class TestMonitorMemory(unittest.TestCase): class TestMonitorMemory(unittest.TestCase):
"""Test case to see if the MonitorMemory is properly managing the """Test case to see if the MonitorMemory is properly managing the
......
...@@ -32,6 +32,7 @@ from cloudooo.handler.ooo.monitor.request import MonitorRequest ...@@ -32,6 +32,7 @@ from cloudooo.handler.ooo.monitor.request import MonitorRequest
from cloudoooTestCase import CloudoooTestCase, make_suite from cloudoooTestCase import CloudoooTestCase, make_suite
from cloudooo.handler.ooo.application.openoffice import openoffice from cloudooo.handler.ooo.application.openoffice import openoffice
OPENOFFICE = True
class TestMonitorRequest(CloudoooTestCase): class TestMonitorRequest(CloudoooTestCase):
"""Test all features of a monitor following the interface""" """Test all features of a monitor following the interface"""
......
...@@ -32,6 +32,7 @@ from cloudooo.handler.ooo.application.openoffice import openoffice ...@@ -32,6 +32,7 @@ from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.monitor.timeout import MonitorTimeout from cloudooo.handler.ooo.monitor.timeout import MonitorTimeout
from cloudoooTestCase import make_suite from cloudoooTestCase import make_suite
OPENOFFICE = True
class TestMonitorTimeout(unittest.TestCase): class TestMonitorTimeout(unittest.TestCase):
"""Test all features of a monitor following the interface""" """Test all features of a monitor following the interface"""
......
...@@ -38,6 +38,7 @@ import os ...@@ -38,6 +38,7 @@ import os
from lxml import etree from lxml import etree
from zipfile import ZipFile from zipfile import ZipFile
OPENOFFICE = True
class TestOOHandler(CloudoooTestCase): class TestOOHandler(CloudoooTestCase):
"""Test OOHandler and manipulation of OOo Instance""" """Test OOHandler and manipulation of OOo Instance"""
......
...@@ -32,6 +32,7 @@ from cloudooo.handler.ooo.application.openoffice import OpenOffice ...@@ -32,6 +32,7 @@ from cloudooo.handler.ooo.application.openoffice import OpenOffice
from cloudoooTestCase import make_suite from cloudoooTestCase import make_suite
from cloudooo.handler.ooo.utils.utils import waitStopDaemon from cloudooo.handler.ooo.utils.utils import waitStopDaemon
OPENOFFICE = True
class TestOpenOffice(CloudoooTestCase): class TestOpenOffice(CloudoooTestCase):
"""Test OpenOffice object and manipulation of OOo Instance""" """Test OpenOffice object and manipulation of OOo Instance"""
......
...@@ -36,6 +36,7 @@ from cloudoooTestCase import CloudoooTestCase, make_suite ...@@ -36,6 +36,7 @@ from cloudoooTestCase import CloudoooTestCase, make_suite
from zipfile import ZipFile, is_zipfile from zipfile import ZipFile, is_zipfile
from types import DictType from types import DictType
DAEMON = True
class TestServer(CloudoooTestCase): class TestServer(CloudoooTestCase):
"""Test XmlRpc Server. Needs cloudooo server started""" """Test XmlRpc Server. Needs cloudooo server started"""
......
...@@ -35,6 +35,7 @@ from cloudoooTestCase import CloudoooTestCase, make_suite ...@@ -35,6 +35,7 @@ from cloudoooTestCase import CloudoooTestCase, make_suite
from cloudooo.handler.ooo.application.openoffice import openoffice from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.document import FileSystemDocument from cloudooo.handler.ooo.document import FileSystemDocument
OPENOFFICE = True
class TestUnoConverter(CloudoooTestCase): class TestUnoConverter(CloudoooTestCase):
"""Test case to test all features of the unoconverter script""" """Test case to test all features of the unoconverter script"""
......
...@@ -34,6 +34,7 @@ from subprocess import Popen, PIPE ...@@ -34,6 +34,7 @@ from subprocess import Popen, PIPE
from os import environ, path from os import environ, path
from cloudoooTestCase import CloudoooTestCase, make_suite from cloudoooTestCase import CloudoooTestCase, make_suite
OPENOFFICE = True
class TestUnoMimeMapper(CloudoooTestCase): class TestUnoMimeMapper(CloudoooTestCase):
"""Test Case to test all features of script unomimemapper""" """Test Case to test all features of script unomimemapper"""
......
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