Commit 8c0efdc7 authored by Priscila Manhaes's avatar Priscila Manhaes

refactor to auto select with handler test belongs to

parent a95df145
...@@ -8,6 +8,7 @@ from subprocess import Popen ...@@ -8,6 +8,7 @@ from subprocess import Popen
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from argparse import ArgumentParser from argparse import ArgumentParser
from os import chdir, path, environ, curdir, remove from os import chdir, path, environ, curdir, remove
from glob import glob
import psutil import psutil
from cloudooo.handler.ooo.util import socketStatus from cloudooo.handler.ooo.util import socketStatus
from signal import SIGQUIT from signal import SIGQUIT
...@@ -38,12 +39,9 @@ def run(): ...@@ -38,12 +39,9 @@ def run():
parser.add_argument('--paster_path', dest='paster_path', parser.add_argument('--paster_path', dest='paster_path',
default='paster', default='paster',
help="Path to Paster script") help="Path to Paster script")
parser.add_argument('--handler', dest='handler',
type=str,
help="Cloudooo's Handler'")
namespace = parser.parse_args() namespace = parser.parse_args()
environment_path = resource_filename("cloudooo.handler.%s" % namespace.handler, environment_path = glob(path.join(resource_filename("cloudooo", "handler"), '*', 'tests'))
"/tests") sys.path.extend(environment_path)
server_cloudooo_conf = namespace.server_cloudooo_conf server_cloudooo_conf = namespace.server_cloudooo_conf
test_name = namespace.test_name test_name = namespace.test_name
if server_cloudooo_conf.startswith(curdir): if server_cloudooo_conf.startswith(curdir):
...@@ -55,16 +53,18 @@ def run(): ...@@ -55,16 +53,18 @@ def run():
python_extension = '.py' python_extension = '.py'
if test_name[-3:] == python_extension: if test_name[-3:] == python_extension:
test_name = test_name[:-3] test_name = test_name[:-3]
full_path = path.join(environment_path, '%s%s' % (test_name, for env_handler_path in environment_path:
full_path = path.join(env_handler_path, '%s%s' % (test_name,
python_extension)) python_extension))
if not path.exists(full_path): if path.exists(full_path):
exit("%s does not exists\n" % full_path) handler_path = env_handler_path
break
else:
exit("%s does not exists\n" % full_path)
from cloudooo.tests.handlerTestCase import startFakeEnvironment from cloudooo.tests.handlerTestCase import startFakeEnvironment
from cloudooo.tests.handlerTestCase import stopFakeEnvironment from cloudooo.tests.handlerTestCase import stopFakeEnvironment
sys.path.append(environment_path)
config = ConfigParser() config = ConfigParser()
config.read(server_cloudooo_conf) config.read(server_cloudooo_conf)
module = __import__(test_name) module = __import__(test_name)
...@@ -87,19 +87,19 @@ def run(): ...@@ -87,19 +87,19 @@ def run():
server_cloudooo_conf] server_cloudooo_conf]
process = Popen(command) process = Popen(command)
wait_use_port(process.pid) wait_use_port(process.pid)
chdir(environment_path) chdir(handler_path)
try: try:
TestRunner(verbosity=2).run(suite) TestRunner(verbosity=2).run(suite)
finally: finally:
process.send_signal(SIGQUIT) process.send_signal(SIGQUIT)
process.wait() process.wait()
elif OPENOFFICE: elif OPENOFFICE:
chdir(environment_path) chdir(handler_path)
startFakeEnvironment(conf_path=server_cloudooo_conf) startFakeEnvironment(conf_path=server_cloudooo_conf)
try: try:
TestRunner(verbosity=2).run(suite) TestRunner(verbosity=2).run(suite)
finally: finally:
stopFakeEnvironment() stopFakeEnvironment()
else: else:
chdir(environment_path) chdir(handler_path)
TestRunner(verbosity=2).run(suite) 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