Commit 46a05a84 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor and removed the duplicated code in handler test cases.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43560 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 300422d5
#!/usr/bin/env python
##############################################################################
#
# Copyright (c) 2009-2011 Nexedi SA and Contributors. All Rights Reserved.
# Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from cloudooo.handler.tests import runHandlerUnitTest
import sys
import unittest
from argparse import ArgumentParser
from os import path, curdir, environ, chdir
ENVIRONMENT_PATH = path.abspath(path.dirname(__file__))
def exit(msg):
sys.stderr.write(msg)
sys.exit(0)
# XXX - Duplicated function. This function must be generic to be used by all handlers
def run():
parser = ArgumentParser(description="Unit Test Runner for Cloudooo")
parser.add_argument('server_cloudooo_conf')
parser.add_argument('test_name')
parser.add_argument('--paster_path', dest='paster_path',
default='paster',
help="Path to Paster script")
namespace = parser.parse_args()
server_cloudooo_conf = namespace.server_cloudooo_conf
test_name = namespace.test_name
if server_cloudooo_conf.startswith(curdir):
server_cloudooo_conf = path.join(path.abspath(curdir),
server_cloudooo_conf)
environ['server_cloudooo_conf'] = server_cloudooo_conf
python_extension = '.py'
if test_name[-3:] == python_extension:
test_name = test_name[:-3]
if not path.exists(path.join(ENVIRONMENT_PATH,
'%s%s' % (test_name, python_extension))):
exit("%s not exists\n" % test_name)
sys.path.append(ENVIRONMENT_PATH)
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())
chdir(ENVIRONMENT_PATH)
TestRunner(verbosity=2).run(suite)
if __name__ == "__main__":
run()
runHandlerUnitTest.run("ffmpeg")
......@@ -195,8 +195,6 @@ class OOHandler:
if metadata.get("Data"):
self.document.reload(metadata['Data'])
metadata['Data'] = self.document.getContent()
else:
metadata['Data'] = ''
self.document.trash()
return metadata
......
##############################################################################
#
# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
# Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
import sys
from os import path
from os import environ, putenv
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.mimemapper import mimemapper
from cloudooo.handler.tests.handlerTestCase import config, check_folder
testcase_path = path.dirname(__file__)
def make_suite(test_case):
"""Function is used to run all tests together"""
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(test_case))
return suite
def startFakeEnvironment(start_openoffice=True, conf_path=None):
"""Create a fake environment"""
config.read(conf_path)
uno_path = config.get("app:main", "uno_path")
working_path = config.get("app:main", "working_path")
hostname = config.get("server:main", "host")
openoffice_port = int(config.get("app:main", "openoffice_port"))
office_binary_path = config.get("app:main", "office_binary_path")
tmp_dir = path.join(working_path, 'tmp')
check_folder(working_path, tmp_dir)
if not environ.get('uno_path'):
environ['uno_path'] = uno_path
office_binary_path = config.get("app:main", "office_binary_path")
if not environ.get('office_binary_path'):
environ['office_binary_path'] = office_binary_path
if uno_path not in sys.path:
sys.path.append(uno_path)
fundamentalrc_file = '%s/fundamentalrc' % office_binary_path
if path.exists(fundamentalrc_file) and \
'URE_BOOTSTRAP' not in environ:
putenv('URE_BOOTSTRAP', 'vnd.sun.star.pathname:%s' % fundamentalrc_file)
if start_openoffice:
default_language = config.get('app:main',
'openoffice_user_interface_language', False,
{'openoffice_user_interface_language': 'en'})
openoffice.loadSettings(hostname,
openoffice_port,
working_path,
office_binary_path,
uno_path,
default_language)
openoffice.start()
openoffice.acquire()
hostname, port = openoffice.getAddress()
kw = dict(uno_path=config.get("app:main", "uno_path"),
office_binary_path=config.get("app:main", "office_binary_path"))
if not mimemapper.isLoaded():
mimemapper.loadFilterList(hostname, port, **kw)
openoffice.release()
return openoffice
def stopFakeEnvironment(stop_openoffice=True):
"""Stop Openoffice """
if stop_openoffice:
openoffice.stop()
return True
#!/usr/bin/env python
import sys
import unittest
from argparse import ArgumentParser
from time import sleep
from subprocess import Popen
from ConfigParser import ConfigParser
from os import chdir, path, environ, curdir, remove
from psutil import Process
from signal import SIGQUIT
ENVIRONMENT_PATH = path.abspath(path.dirname(__file__))
def wait_use_port(pid, timeout_limit=30):
process = Process(pid)
for n in range(timeout_limit):
if len(process.get_connections()) > 0:
return True
sleep(1)
return False
def exit(msg):
sys.stderr.write(msg)
sys.exit(0)
##############################################################################
#
# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
# Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from cloudooo.handler.tests import runHandlerUnitTest
def run():
parser = ArgumentParser(description="Unit Test Runner for Cloudooo")
parser.add_argument('server_cloudooo_conf')
parser.add_argument('test_name')
parser.add_argument('--timeout_limit', dest='timeout_limit',
type=long, default=30,
help="Timeout to waiting for the cloudooo stop")
parser.add_argument('--paster_path', dest='paster_path',
default='paster',
help="Path to Paster script")
namespace = parser.parse_args()
server_cloudooo_conf = namespace.server_cloudooo_conf
test_name = namespace.test_name
if server_cloudooo_conf.startswith(curdir):
server_cloudooo_conf = path.join(path.abspath(curdir),
server_cloudooo_conf)
environ['server_cloudooo_conf'] = server_cloudooo_conf
paster_path = namespace.paster_path
python_extension = '.py'
if test_name[-3:] == python_extension:
test_name = test_name[:-3]
if not path.exists(path.join(ENVIRONMENT_PATH,
'%s%s' % (test_name, python_extension))):
exit("%s not exists\n" % test_name)
from cloudoooTestCase import startFakeEnvironment, stopFakeEnvironment
sys.path.append(ENVIRONMENT_PATH)
config = ConfigParser()
config.read(server_cloudooo_conf)
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)
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
suite.addTest(module.test_suite())
if DAEMON:
log_file = '%s/cloudooo_test.log' % config.get('app:main',
'working_path')
if path.exists(log_file):
remove(log_file)
command = [paster_path, 'serve', '--log-file', log_file,
server_cloudooo_conf]
process = Popen(command)
wait_use_port(process.pid)
chdir(ENVIRONMENT_PATH)
try:
TestRunner(verbosity=2).run(suite)
finally:
process.send_signal(SIGQUIT)
process.wait()
elif OPENOFFICE:
chdir(ENVIRONMENT_PATH)
startFakeEnvironment(conf_path=server_cloudooo_conf)
try:
TestRunner(verbosity=2).run(suite)
finally:
stopFakeEnvironment()
else:
chdir(ENVIRONMENT_PATH)
TestRunner(verbosity=2).run(suite)
if __name__ == "__main__":
run()
runHandlerUnitTest.run("ooo")
......@@ -28,8 +28,7 @@
from xmlrpclib import ServerProxy, Fault
from base64 import encodestring, decodestring
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
import magic
file_detector = magic.Magic()
......
......@@ -28,8 +28,7 @@
from xmlrpclib import ServerProxy, Fault
from base64 import encodestring, decodestring
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
import magic
file_detector = magic.Magic()
......
......@@ -28,7 +28,7 @@
import unittest
from cloudooo.handler.ooo.application.application import Application
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import make_suite
class TestApplication(unittest.TestCase):
......
......@@ -33,7 +33,7 @@ from base64 import decodestring
from os import path
from zipfile import ZipFile
from cloudooo.handler.ooo.document import FileSystemDocument
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import make_suite
class TestFileSystemDocument(unittest.TestCase):
......
......@@ -28,7 +28,6 @@
import unittest
from cloudooo.handler.ooo.filter import Filter
from cloudoooTestCase import make_suite
class TestFilter(unittest.TestCase):
......
......@@ -29,8 +29,7 @@
from xmlrpclib import ServerProxy
from base64 import encodestring, decodestring
from multiprocessing import Process, Array
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
import magic
DAEMON = True
......
......@@ -46,8 +46,7 @@ from cloudooo.interfaces.monitor import IMonitor
from cloudooo.interfaces.granulate import ITableGranulator, \
IImageGranulator, \
ITextGranulator
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import make_suite
class TestInterface(unittest.TestCase):
"""Test All Interfaces"""
......
......@@ -26,10 +26,9 @@
#
##############################################################################
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.mimemapper import MimeMapper
from cloudoooTestCase import make_suite
text_expected_tuple = (
('doc', 'Microsoft Word 6.0'),
......
......@@ -27,8 +27,7 @@
##############################################################################
import cloudooo.handler.ooo.monitor as monitor
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.monitor.request import MonitorRequest
from cloudooo.handler.ooo.monitor.memory import MonitorMemory
......
......@@ -32,7 +32,7 @@ from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.monitor.memory import MonitorMemory
from psutil import Process
from types import IntType
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import make_suite
OPENOFFICE = True
......
......@@ -28,8 +28,7 @@
from time import sleep
from cloudooo.handler.ooo.monitor.request import MonitorRequest
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.application.openoffice import openoffice
OPENOFFICE = True
......
......@@ -30,7 +30,7 @@ import unittest
from time import sleep
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.monitor.timeout import MonitorTimeout
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import make_suite
OPENOFFICE = True
......
......@@ -30,8 +30,7 @@
from zipfile import ZipFile
from StringIO import StringIO
from lxml import etree
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.granulator import OOGranulator
......
......@@ -29,10 +29,9 @@
import magic
from os import path
from base64 import encodestring, decodestring
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.handler import OOHandler
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudoooTestCase import make_suite
import os
from lxml import etree
from zipfile import ZipFile
......
......@@ -28,8 +28,7 @@
from zipfile import ZipFile
from lxml import etree
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.document import OdfDocument
......
......@@ -26,9 +26,8 @@
#
##############################################################################
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.application.openoffice import OpenOffice
from cloudoooTestCase import make_suite
from cloudooo.handler.ooo.utils.utils import waitStopDaemon
OPENOFFICE = True
......
......@@ -30,8 +30,7 @@ from os.path import join, exists
from os import remove
from xmlrpclib import ServerProxy, Fault
from base64 import encodestring, decodestring
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from zipfile import ZipFile, is_zipfile
from types import DictType
import magic
......@@ -308,8 +307,8 @@ class TestServer(HandlerTestCase):
def testConvertPyToPDF(self):
"""Test export python to pdf"""
self._testConvertFile("cloudoooTestCase.py",
join(self.tmp_url, "cloudoooTestCase.py"),
self._testConvertFile(__file__,
join(self.tmp_url, "output.py"),
'py',
'pdf',
'application/pdf')
......
......@@ -31,8 +31,7 @@ import magic
import pkg_resources
from subprocess import Popen, PIPE
from os.path import exists, join
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.document import FileSystemDocument
......
......@@ -31,8 +31,7 @@ import pkg_resources
from cloudooo.handler.ooo.application.openoffice import openoffice
from subprocess import Popen, PIPE
from os import environ, path
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
OPENOFFICE = True
......
......@@ -30,7 +30,7 @@ import unittest
import logging
from cloudooo.utils.utils import logger, configureLogger, \
convertStringToBool
from cloudoooTestCase import make_suite
from cloudooo.handler.tests.handlerTestCase import make_suite
class TestUtils(unittest.TestCase):
......
#!/usr/bin/env python
##############################################################################
#
# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
# Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from cloudooo.handler.tests import runHandlerUnitTest
import sys
import unittest
from argparse import ArgumentParser
from os import path, curdir, environ, chdir
ENVIRONMENT_PATH = path.abspath(path.dirname(__file__))
def exit(msg):
sys.stderr.write(msg)
sys.exit(0)
# XXX - Duplicated function. This function must be generic to be used by all handlers
def run():
parser = ArgumentParser(description="Unit Test Runner for Cloudooo")
parser.add_argument('server_cloudooo_conf')
parser.add_argument('test_name')
parser.add_argument('--paster_path', dest='paster_path',
default='paster',
help="Path to Paster script")
namespace = parser.parse_args()
server_cloudooo_conf = namespace.server_cloudooo_conf
test_name = namespace.test_name
if server_cloudooo_conf.startswith(curdir):
server_cloudooo_conf = path.join(path.abspath(curdir),
server_cloudooo_conf)
environ['server_cloudooo_conf'] = server_cloudooo_conf
python_extension = '.py'
if test_name[-3:] == python_extension:
test_name = test_name[:-3]
if not path.exists(path.join(ENVIRONMENT_PATH,
'%s%s' % (test_name, python_extension))):
exit("%s not exists\n" % test_name)
sys.path.append(ENVIRONMENT_PATH)
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())
chdir(ENVIRONMENT_PATH)
TestRunner(verbosity=2).run(suite)
if __name__ == "__main__":
run()
runHandlerUnitTest.run("pdf")
......@@ -28,13 +28,21 @@
import unittest
from os import environ, path, mkdir
from ConfigParser import ConfigParser
import sys
from os import environ, path, mkdir, putenv
from ConfigParser import ConfigParser
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.mimemapper import mimemapper
config = ConfigParser()
def make_suite(test_case):
"""Function is used to run all tests together"""
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(test_case))
return suite
def check_folder(working_path, tmp_dir_path):
if not path.exists(working_path):
mkdir(working_path)
......@@ -42,6 +50,58 @@ def check_folder(working_path, tmp_dir_path):
mkdir(tmp_dir_path)
def startFakeEnvironment(start_openoffice=True, conf_path=None):
"""Create a fake environment"""
config.read(conf_path)
uno_path = config.get("app:main", "uno_path")
working_path = config.get("app:main", "working_path")
hostname = config.get("server:main", "host")
openoffice_port = int(config.get("app:main", "openoffice_port"))
office_binary_path = config.get("app:main", "office_binary_path")
tmp_dir = path.join(working_path, 'tmp')
check_folder(working_path, tmp_dir)
if not environ.get('uno_path'):
environ['uno_path'] = uno_path
office_binary_path = config.get("app:main", "office_binary_path")
if not environ.get('office_binary_path'):
environ['office_binary_path'] = office_binary_path
if uno_path not in sys.path:
sys.path.append(uno_path)
fundamentalrc_file = '%s/fundamentalrc' % office_binary_path
if path.exists(fundamentalrc_file) and \
'URE_BOOTSTRAP' not in environ:
putenv('URE_BOOTSTRAP', 'vnd.sun.star.pathname:%s' % fundamentalrc_file)
if start_openoffice:
default_language = config.get('app:main',
'openoffice_user_interface_language', False,
{'openoffice_user_interface_language': 'en'})
openoffice.loadSettings(hostname,
openoffice_port,
working_path,
office_binary_path,
uno_path,
default_language)
openoffice.start()
openoffice.acquire()
hostname, port = openoffice.getAddress()
kw = dict(uno_path=config.get("app:main", "uno_path"),
office_binary_path=config.get("app:main", "office_binary_path"))
if not mimemapper.isLoaded():
mimemapper.loadFilterList(hostname, port, **kw)
openoffice.release()
return openoffice
def stopFakeEnvironment(stop_openoffice=True):
"""Stop Openoffice """
if stop_openoffice:
openoffice.stop()
return True
class HandlerTestCase(unittest.TestCase):
"""Test Case to load cloudooo conf."""
......
#!/usr/bin/env python
import sys
from pkg_resources import resource_filename
import unittest
from time import sleep
from subprocess import Popen
from ConfigParser import ConfigParser
from argparse import ArgumentParser
from os import chdir, path, environ, curdir, remove
from psutil import Process
from signal import SIGQUIT
def wait_use_port(pid, timeout_limit=30):
process = Process(pid)
for n in range(timeout_limit):
if len(process.get_connections()) > 0:
return True
sleep(1)
return False
def exit(msg):
sys.stderr.write(msg)
sys.exit(0)
def run(handler_name):
description = "Unit Test Runner for %s Handler" % handler_name.capitalize()
parser = ArgumentParser(description=description)
parser.add_argument('server_cloudooo_conf')
parser.add_argument('test_name')
parser.add_argument('--timeout_limit', dest='timeout_limit',
type=long, default=30,
help="Timeout to waiting for the cloudooo stop")
parser.add_argument('--paster_path', dest='paster_path',
default='paster',
help="Path to Paster script")
namespace = parser.parse_args()
environment_path = resource_filename("cloudooo",
"handler/%s/tests" % handler_name)
server_cloudooo_conf = namespace.server_cloudooo_conf
test_name = namespace.test_name
if server_cloudooo_conf.startswith(curdir):
server_cloudooo_conf = path.join(path.abspath(curdir),
server_cloudooo_conf)
environ['server_cloudooo_conf'] = server_cloudooo_conf
paster_path = namespace.paster_path
python_extension = '.py'
if test_name[-3:] == python_extension:
test_name = test_name[:-3]
if not path.exists(path.join(environment_path,
'%s%s' % (test_name, python_extension))):
exit("%s not exists\n" % test_name)
from cloudooo.handler.tests.handlerTestCase import startFakeEnvironment, \
stopFakeEnvironment
sys.path.append(environment_path)
config = ConfigParser()
config.read(server_cloudooo_conf)
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)
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
suite.addTest(module.test_suite())
if DAEMON:
log_file = '%s/cloudooo_test.log' % config.get('app:main',
'working_path')
if path.exists(log_file):
remove(log_file)
command = [paster_path, 'serve', '--log-file', log_file,
server_cloudooo_conf]
process = Popen(command)
wait_use_port(process.pid)
chdir(environment_path)
try:
TestRunner(verbosity=2).run(suite)
finally:
process.send_signal(SIGQUIT)
process.wait()
elif OPENOFFICE:
chdir(environment_path)
startFakeEnvironment(conf_path=server_cloudooo_conf)
try:
TestRunner(verbosity=2).run(suite)
finally:
stopFakeEnvironment()
else:
chdir(environment_path)
TestRunner(verbosity=2).run(suite)
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