summaryrefslogtreecommitdiff
path: root/openerpcommand
diff options
context:
space:
mode:
authorAntony Lesuisse <al@openerp.com>2014-02-27 17:18:19 +0100
committerAntony Lesuisse <al@openerp.com>2014-02-27 17:18:19 +0100
commit38d1ca1ff2472f4e1d3bc3d5f3454dc7603374a6 (patch)
tree1b2a223afdb1cb27b7d0a19e8bcb7a15ae11219a /openerpcommand
parent14815d669ff5ae428a74c7b81327667cdbcf44f9 (diff)
parent6df317c54629e5c222e8db511b38ada767ec60af (diff)
[MERGE] trunk
bzr revid: al@openerp.com-20140227161819-p9chmskfifo0rygs
Diffstat (limited to 'openerpcommand')
-rw-r--r--openerpcommand/__init__.py3
-rw-r--r--openerpcommand/common.py8
-rw-r--r--openerpcommand/initialize.py54
-rw-r--r--openerpcommand/run_tests.py201
4 files changed, 21 insertions, 245 deletions
diff --git a/openerpcommand/__init__.py b/openerpcommand/__init__.py
index 9d5e81f0327..b7131913e1e 100644
--- a/openerpcommand/__init__.py
+++ b/openerpcommand/__init__.py
@@ -14,14 +14,13 @@ from . import initialize
from . import model
from . import module
from . import read
-from . import run_tests
from . import scaffold
from . import uninstall
from . import update
from . import web
from . import grunt_tests
-command_list_server = (conf, cron, drop, initialize, model, module, read, run_tests,
+command_list_server = (conf, cron, drop, initialize, model, module, read,
scaffold, uninstall, update, web, grunt_tests, )
command_list_client = (Call, Open, Show, ConsumeNothing, ConsumeMemory,
diff --git a/openerpcommand/common.py b/openerpcommand/common.py
index 9209f8e1eb6..7572bb4efa6 100644
--- a/openerpcommand/common.py
+++ b/openerpcommand/common.py
@@ -57,11 +57,11 @@ def required_or_default(name, h):
a mandatory argument.
"""
if os.environ.get('OPENERP_' + name.upper()):
- d = {'default': os.environ['OPENERP_' + name.upper()]}
+ d = {'default': os.environ['OPENERP_' + name.upper()]}
else:
- d = {'required': True}
+ d = {'required': True}
d['help'] = h + '. The environment variable OPENERP_' + \
- name.upper() + ' can be used instead.'
+ name.upper() + ' can be used instead.'
return d
class Command(object):
@@ -77,7 +77,7 @@ class Command(object):
self.parser = parser = subparsers.add_parser(self.command_name,
description=self.__class__.__doc__)
else:
- self.parser = parser = argparse.ArgumentParser(
+ self.parser = parser = argparse.ArgumentParser(
description=self.__class__.__doc__)
parser.add_argument('-d', '--database', metavar='DATABASE',
diff --git a/openerpcommand/initialize.py b/openerpcommand/initialize.py
index 6261312de7e..cf4e54bfb82 100644
--- a/openerpcommand/initialize.py
+++ b/openerpcommand/initialize.py
@@ -9,24 +9,6 @@ import time
import common
-def install_openerp(database_name, create_database_flag, module_names, install_demo_data):
- import openerp
- config = openerp.tools.config
-
- if create_database_flag:
- with lock_file('/tmp/global_openerp_create_database.lock'):
- create_database(database_name)
-
- config['init'] = dict.fromkeys(module_names, 1)
-
- # Install the import hook, to import openerp.addons.<module>.
- openerp.modules.module.initialize_sys_path()
-
- registry = openerp.modules.registry.RegistryManager.get(
- database_name, update_module=True, force_demo=install_demo_data)
-
- return registry
-
# From http://code.activestate.com/recipes/576572/
@contextlib.contextmanager
def lock_file(path, wait_delay=.1, max_try=600):
@@ -50,21 +32,6 @@ def lock_file(path, wait_delay=.1, max_try=600):
os.close(fd)
os.unlink(path)
-# TODO turn template1 in a parameter
-# This should be exposed from openerp (currently in
-# openerp/service/web_services.py).
-def create_database(database_name):
- import openerp
- db = openerp.sql_db.db_connect('template1')
- cr = db.cursor() # TODO `with db as cr:`
- try:
- cr.autocommit(True)
- cr.execute("""CREATE DATABASE "%s"
- ENCODING 'unicode' TEMPLATE "template1" """ \
- % (database_name,))
- finally:
- cr.close()
-
def run(args):
assert args.database
assert not (args.module and args.all_modules)
@@ -72,11 +39,14 @@ def run(args):
import openerp
config = openerp.tools.config
+ config['db_name'] = args.database
if args.tests:
config['log_handler'] = [':INFO']
config['test_enable'] = True
config['without_demo'] = False
+ if args.port:
+ config['xmlrpc_port'] = int(args.port)
else:
config['log_handler'] = [':CRITICAL']
config['test_enable'] = False
@@ -94,6 +64,7 @@ def run(args):
module_names = args.module
else:
module_names = ['base']
+ config['init'] = dict.fromkeys(module_names, 1)
if args.coverage:
import coverage
@@ -102,17 +73,22 @@ def run(args):
cov = coverage.coverage(branch=True, include='*.py')
cov.start()
openerp.netsvc.init_logger()
- registry = install_openerp(args.database, not args.no_create, module_names, not config['without_demo'])
+
+ if not args.no_create:
+ with lock_file('/tmp/global_openerp_create_database.lock'):
+ openerp.service.db._create_empty_database(args.database)
+
+ config['workers'] = False
+
+ rc = openerp.service.server.start(preload=[args.database], stop=True)
+
if args.coverage:
cov.stop()
cov.html_report(directory='coverage')
# If we wanted the report on stdout:
# cov.report()
- # The `_assertion_report` attribute was added on the registry during the
- # OpenERP 7.0 development.
- if hasattr(registry, '_assertion_report'):
- sys.exit(1 if registry._assertion_report.failures else 0)
+ sys.exit(rc)
def add_parser(subparsers):
parser = subparsers.add_parser('initialize',
@@ -120,6 +96,8 @@ def add_parser(subparsers):
parser.add_argument('-d', '--database', metavar='DATABASE',
**common.required_or_default('DATABASE', 'the database to create'))
common.add_addons_argument(parser)
+ parser.add_argument('-P', '--port', metavar='PORT',
+ **common.required_or_default('PORT', 'the server port'))
parser.add_argument('--module', metavar='MODULE', action='append',
help='specify a module to install'
' (this option can be repeated)')
diff --git a/openerpcommand/run_tests.py b/openerpcommand/run_tests.py
deleted file mode 100644
index 4000b227b90..00000000000
--- a/openerpcommand/run_tests.py
+++ /dev/null
@@ -1,201 +0,0 @@
-"""
-Execute the unittest2 tests available in OpenERP addons.
-"""
-
-import os
-import sys
-import types
-
-import common
-
-def get_test_modules(module, submodule, explode):
- """
- Return a list of submodules containing tests.
- `submodule` can be:
- - None
- - the name of a submodule
- - '__fast_suite__'
- - '__sanity_checks__'
- """
- # Turn command-line module, submodule into importable names.
- if module is None:
- pass
- elif module == 'openerp':
- module = 'openerp.tests'
- else:
- module = 'openerp.addons.' + module + '.tests'
-
- # Try to import the module
- try:
- __import__(module)
- except Exception, e:
- if explode:
- print 'Can not `import %s`.' % module
- import logging
- logging.exception('')
- sys.exit(1)
- else:
- if str(e) == 'No module named tests':
- # It seems the module has no `tests` sub-module, no problem.
- pass
- else:
- print 'Can not `import %s`.' % module
- return []
-
- # Discover available test sub-modules.
- m = sys.modules[module]
- submodule_names = sorted([x for x in dir(m) \
- if x.startswith('test_') and \
- isinstance(getattr(m, x), types.ModuleType)])
- submodules = [getattr(m, x) for x in submodule_names]
-
- def show_submodules_and_exit():
- if submodule_names:
- print 'Available submodules are:'
- for x in submodule_names:
- print ' ', x
- sys.exit(1)
-
- if submodule is None:
- # Use auto-discovered sub-modules.
- ms = submodules
- elif submodule == '__fast_suite__':
- # Obtain the explicit test sub-modules list.
- ms = getattr(sys.modules[module], 'fast_suite', None)
- # `suite` was used before the 6.1 release instead of `fast_suite`.
- ms = ms if ms else getattr(sys.modules[module], 'suite', None)
- if ms is None:
- if explode:
- print 'The module `%s` has no defined test suite.' % (module,)
- show_submodules_and_exit()
- else:
- ms = []
- elif submodule == '__sanity_checks__':
- ms = getattr(sys.modules[module], 'checks', None)
- if ms is None:
- if explode:
- print 'The module `%s` has no defined sanity checks.' % (module,)
- show_submodules_and_exit()
- else:
- ms = []
- else:
- # Pick the command-line-specified test sub-module.
- m = getattr(sys.modules[module], submodule, None)
- ms = [m]
-
- if m is None:
- if explode:
- print 'The module `%s` has no submodule named `%s`.' % \
- (module, submodule)
- show_submodules_and_exit()
- else:
- ms = []
-
- return ms
-
-def run(args):
- import unittest2
-
- import openerp
-
- config = openerp.tools.config
- config['db_name'] = args.database
- if args.port:
- config['xmlrpc_port'] = int(args.port)
- config['admin_passwd'] = 'admin'
- config['db_password'] = 'a2aevl8w' # TODO from .openerpserverrc
- config['addons_path'] = args.addons.replace(':',',')
- if args.addons:
- args.addons = args.addons.split(':')
- else:
- args.addons = []
- if args.sanity_checks and args.fast_suite:
- print 'Only at most one of `--sanity-checks` and `--fast-suite` ' \
- 'can be specified.'
- sys.exit(1)
-
- import logging
- openerp.netsvc.init_alternative_logger()
- logging.getLogger('openerp').setLevel(logging.CRITICAL)
-
- # Install the import hook, to import openerp.addons.<module>.
- openerp.modules.module.initialize_sys_path()
-
- # Extract module, submodule from the command-line args.
- if args.module is None:
- module, submodule = None, None
- else:
- splitted = args.module.split('.')
- if len(splitted) == 1:
- module, submodule = splitted[0], None
- elif len(splitted) == 2:
- module, submodule = splitted
- else:
- print 'The `module` argument must have the form ' \
- '`module[.submodule]`.'
- sys.exit(1)
-
- # Import the necessary modules and get the corresponding suite.
- if module is None:
- # TODO
- modules = common.get_addons_from_paths(args.addons, []) # TODO openerp.addons.base is not included ?
- test_modules = []
- for module in ['openerp'] + modules:
- if args.fast_suite:
- submodule = '__fast_suite__'
- if args.sanity_checks:
- submodule = '__sanity_checks__'
- test_modules.extend(get_test_modules(module,
- submodule, explode=False))
- else:
- if submodule and args.fast_suite:
- print "Submodule name `%s` given, ignoring `--fast-suite`." % (submodule,)
- if submodule and args.sanity_checks:
- print "Submodule name `%s` given, ignoring `--sanity-checks`." % (submodule,)
- if not submodule and args.fast_suite:
- submodule = '__fast_suite__'
- if not submodule and args.sanity_checks:
- submodule = '__sanity_checks__'
- test_modules = get_test_modules(module,
- submodule, explode=True)
-
- # Run the test suite.
- if not args.dry_run:
- suite = unittest2.TestSuite()
- for test_module in test_modules:
- suite.addTests(unittest2.TestLoader().loadTestsFromModule(test_module))
- r = unittest2.TextTestRunner(verbosity=2).run(suite)
- if r.errors or r.failures:
- sys.exit(1)
- else:
- print 'Test modules:'
- for test_module in test_modules:
- print ' ', test_module.__name__
-
-def add_parser(subparsers):
- parser = subparsers.add_parser('run-tests',
- description='Run the OpenERP server and/or addons tests.')
- parser.add_argument('-d', '--database', metavar='DATABASE', required=True,
- help='the database to test. Depending on the test suites, the '
- 'database must already exist or not.')
- parser.add_argument('-p', '--port', metavar='PORT',
- help='the port used for WML-RPC tests')
- common.add_addons_argument(parser)
- parser.add_argument('-m', '--module', metavar='MODULE',
- default=None,
- help='the module to test in `module[.submodule]` notation. '
- 'Use `openerp` for the core OpenERP tests. '
- 'Leave empty to run every declared tests. '
- 'Give a module but no submodule to run all the module\'s declared '
- 'tests. If both the module and the submodule are given, '
- 'the sub-module can be run even if it is not declared in the module.')
- parser.add_argument('--fast-suite', action='store_true',
- help='run only the tests explicitely declared in the fast suite (this '
- 'makes sense only with the bare `module` notation or no module at '
- 'all).')
- parser.add_argument('--sanity-checks', action='store_true',
- help='run only the sanity check tests')
- parser.add_argument('--dry-run', action='store_true',
- help='do not run the tests')
-
- parser.set_defaults(run=run)