def get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude): """ Get the list of modules that need to be installed :param travis_build_dir: Travis build directory :param odoo_include: addons to include (travis parameter) :param odoo_exclude: addons to exclude (travis parameter) :return: List of addons to test """ if odoo_include: addons_list = parse_list(odoo_include) else: addons_list = get_modules(travis_build_dir) if odoo_exclude: exclude_list = parse_list(odoo_exclude) addons_list = [x for x in addons_list if x not in exclude_list] return addons_list
def get_addons_to_check(gitlab_build_dir, flectra_include, flectra_exclude): """ Get the list of modules that need to be installed :param gitlab_build_dir: Travis build directory :param flectra_include: addons to include (gitlab parameter) :param flectra_exclude: addons to exclude (gitlab parameter) :return: List of addons to test """ if flectra_include: addons_list = parse_list(flectra_include) else: addons_list = get_modules(gitlab_build_dir) if flectra_exclude: exclude_list = parse_list(flectra_exclude) addons_list = [x for x in addons_list if x not in exclude_list] return addons_list
def get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude): """ Get the list of modules that need to be installed :param travis_build_dir: Travis build directory :param odoo_include: addons to include (travis parameter) :param odoo_exclude: addons to exclude (travis parameter) :return: List of addons to test """ if odoo_include: addons_list = parse_list(odoo_include) else: addons_list = get_modules(travis_build_dir) if odoo_exclude: exclude_list = parse_list(odoo_exclude) addons_list = [ x for x in addons_list if x not in exclude_list] return addons_list
def main(argv=None): if argv is None: argv = sys.argv run_from_env_var('RUN_COMMAND_MQT', os.environ) travis_home = os.environ.get("HOME", "~/") travis_dependencies_dir = os.path.join(travis_home, 'dependencies') travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") odoo_unittest = str2bool(os.environ.get("UNIT_TEST")) odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") options = os.environ.get("OPTIONS", "").split() install_options = os.environ.get("INSTALL_OPTIONS", "").split() server_options = os.environ.get('SERVER_OPTIONS', "").split() expected_errors = int(os.environ.get("SERVER_EXPECTED_ERRORS", "0")) odoo_version = os.environ.get("VERSION") instance_alive = str2bool(os.environ.get('INSTANCE_ALIVE')) unbuffer = str2bool(os.environ.get('UNBUFFER', True)) data_dir = os.environ.get("DATA_DIR", '~/data_dir') test_enable = str2bool(os.environ.get('TEST_ENABLE', True)) dbtemplate = os.environ.get('MQT_TEMPLATE_DB', 'openerp_template') database = os.environ.get('MQT_TEST_DB', 'openerp_test') if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version) test_loghandler = None if odoo_version == "6.1": install_options += ["--test-disable"] test_loglevel = 'test' else: if test_enable: options += ["--test-enable"] if odoo_version == '7.0': test_loglevel = 'test' else: test_loglevel = 'info' test_loghandler = 'openerp.tools.yaml_import:DEBUG' odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_version, travis_home) script_name = get_server_script(odoo_version) addons_path = get_addons_path(travis_dependencies_dir, travis_build_dir, server_path) create_server_conf({ 'addons_path': addons_path, 'data_dir': data_dir, }, odoo_version) tested_addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) tested_addons = ','.join(tested_addons_list) print("Working in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not tested_addons: print("WARNING!\nNothing to test- exiting early.") return 0 else: print("Modules to test: %s" % tested_addons) # setup the base module without running the tests preinstall_modules = get_test_dependencies(addons_path, tested_addons_list) preinstall_modules = list(set(preinstall_modules) - set(get_modules( os.environ.get('TRAVIS_BUILD_DIR')))) print("Modules to preinstall: %s" % preinstall_modules) setup_server(dbtemplate, odoo_unittest, tested_addons, server_path, script_name, addons_path, install_options, preinstall_modules, unbuffer, server_options) # Running tests cmd_odoo_test = ["coverage", "run", "%s/%s" % (server_path, script_name), "-d", database, "--stop-after-init", "--log-level", test_loglevel, ] if test_loghandler is not None: cmd_odoo_test += ['--log-handler', test_loghandler] cmd_odoo_test += options + ["--init", None] if odoo_unittest: to_test_list = tested_addons_list cmd_odoo_install = [ "%s/%s" % (server_path, script_name), "-d", database, "--stop-after-init", "--log-level=warn", ] + install_options + ["--init", None] + server_options commands = ((cmd_odoo_install, False), (cmd_odoo_test, True), ) else: to_test_list = [tested_addons] commands = ((cmd_odoo_test, True), ) all_errors = [] counted_errors = 0 for to_test in to_test_list: print("\nTesting %s:" % to_test) db_odoo_created = False try: db_odoo_created = subprocess.call( ["createdb", "-T", dbtemplate, database]) copy_attachments(dbtemplate, database, data_dir) except subprocess.CalledProcessError: db_odoo_created = True for command, check_loaded in commands: if db_odoo_created and instance_alive: # If exists database of odoo test # then start server with regular command without tests params rm_items = [ 'coverage', 'run', '--stop-after-init', '--test-enable', '--init', None, '--log-handler', 'openerp.tools.yaml_import:DEBUG', ] command_call = [item for item in commands[0][0] if item not in rm_items] + \ ['--db-filter=^%s$' % database, '--pidfile=/tmp/odoo.pid'] else: command[-1] = to_test # Run test command; unbuffer keeps output colors command_call = (["unbuffer"] if unbuffer else []) + command print(' '.join(command_call)) pipe = subprocess.Popen(command_call, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) with open('stdout.log', 'w') as stdout: for line in iter(pipe.stdout.readline, ''): stdout.write(line) print(line.strip()) returncode = pipe.wait() # Find errors, except from failed mails errors = has_test_errors( "stdout.log", database, odoo_version, check_loaded) if returncode != 0: all_errors.append(to_test) print(fail_msg, "Command exited with code %s" % returncode) # If not exists errors then # add an error when returcode!=0 # because is really a error. if not errors: errors += 1 if errors: counted_errors += errors all_errors.append(to_test) print(fail_msg, "Found %d lines with errors" % errors) if not instance_alive: # Don't drop the database if will be used later. subprocess.call(["dropdb", database]) print('Module test summary') for to_test in to_test_list: if to_test in all_errors: print(fail_msg, to_test) else: print(success_msg, to_test) if expected_errors and counted_errors != expected_errors: print("Expected %d errors, found %d!" % (expected_errors, counted_errors)) return 1 elif counted_errors != expected_errors: return 1 # if we get here, all is OK return 0
def main(argv=None): if argv is None: argv = sys.argv run_from_env_var('RUN_COMMAND_MQT', os.environ) travis_home = os.environ.get("HOME", "~/") travis_dependencies_dir = os.path.join(travis_home, 'dependencies') travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") odoo_unittest = str2bool(os.environ.get("UNIT_TEST")) odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") options = os.environ.get("OPTIONS", "").split() install_options = os.environ.get("INSTALL_OPTIONS", "").split() expected_errors = int(os.environ.get("SERVER_EXPECTED_ERRORS", "0")) odoo_version = os.environ.get("VERSION") instance_alive = str2bool(os.environ.get('INSTANCE_ALIVE')) unbuffer = str2bool(os.environ.get('UNBUFFER', True)) data_dir = os.environ.get("DATA_DIR", '~/data_dir') test_enable = str2bool(os.environ.get('TEST_ENABLE', True)) if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version) test_loghandler = None if odoo_version == "6.1": install_options += ["--test-disable"] test_loglevel = 'test' else: if test_enable: options += ["--test-enable"] if odoo_version == '7.0': test_loglevel = 'test' else: test_loglevel = 'info' test_loghandler = 'openerp.tools.yaml_import:DEBUG' odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_version, travis_home) addons_path = get_addons_path(travis_dependencies_dir, travis_build_dir, server_path) create_server_conf({ 'addons_path': addons_path, 'data_dir': data_dir, }, odoo_version) tested_addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) tested_addons = ','.join(tested_addons_list) print("Working in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not tested_addons: print("WARNING!\nNothing to test- exiting early.") return 0 else: print("Modules to test: %s" % tested_addons) # setup the base module without running the tests dbtemplate = "openerp_template" preinstall_modules = get_test_dependencies(addons_path, tested_addons_list) preinstall_modules = list( set(preinstall_modules) - set(get_modules(os.environ.get('TRAVIS_BUILD_DIR')))) print("Modules to preinstall: %s" % preinstall_modules) setup_server(dbtemplate, odoo_unittest, tested_addons, server_path, addons_path, install_options, preinstall_modules, unbuffer) # Running tests database = "openerp_test" cmd_odoo_test = [ "coverage", "run", "%s/openerp-server" % server_path, "-d", database, "--stop-after-init", "--log-level", test_loglevel, ] if test_loghandler is not None: cmd_odoo_test += ['--log-handler', test_loghandler] cmd_odoo_test += options + ["--init", None] if odoo_unittest: to_test_list = tested_addons_list cmd_odoo_install = [ "%s/openerp-server" % server_path, "-d", database, "--stop-after-init", "--log-level=warn", ] + install_options + ["--init", None] commands = ( (cmd_odoo_install, False), (cmd_odoo_test, True), ) else: to_test_list = [tested_addons] commands = ((cmd_odoo_test, True), ) all_errors = [] counted_errors = 0 for to_test in to_test_list: print("\nTesting %s:" % to_test) db_odoo_created = False try: db_odoo_created = subprocess.call( ["createdb", "-T", dbtemplate, database]) copy_attachments(dbtemplate, database, data_dir) except subprocess.CalledProcessError: db_odoo_created = True for command, check_loaded in commands: if db_odoo_created and instance_alive: # If exists database of odoo test # then start server with regular command without tests params rm_items = [ 'coverage', 'run', '--stop-after-init', '--test-enable', '--init', None, '--log-handler', 'openerp.tools.yaml_import:DEBUG', ] command_call = [item for item in commands[0][0] if item not in rm_items] + \ ['--db-filter=^%s$' % database] else: command[-1] = to_test # Run test command; unbuffer keeps output colors command_call = (["unbuffer"] if unbuffer else []) + command print(' '.join(command_call)) pipe = subprocess.Popen(command_call, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) with open('stdout.log', 'w') as stdout: for line in iter(pipe.stdout.readline, ''): stdout.write(line) print(line.strip()) returncode = pipe.wait() # Find errors, except from failed mails errors = has_test_errors("stdout.log", database, odoo_version, check_loaded) if returncode != 0: all_errors.append(to_test) print(fail_msg, "Command exited with code %s" % returncode) # If not exists errors then # add an error when returcode!=0 # because is really a error. if not errors: errors += 1 if errors: counted_errors += errors all_errors.append(to_test) print(fail_msg, "Found %d lines with errors" % errors) if not instance_alive: # Don't drop the database if will be used later. subprocess.call(["dropdb", database]) print('Module test summary') for to_test in to_test_list: if to_test in all_errors: print(fail_msg, to_test) else: print(success_msg, to_test) if expected_errors and counted_errors != expected_errors: print("Expected %d errors, found %d!" % (expected_errors, counted_errors)) return 1 elif counted_errors != expected_errors: return 1 # if we get here, all is OK return 0
def main(argv=None): if argv is None: argv = sys.argv else: argv = sys.argv + argv run_from_env_var('RUN_COMMAND_MQT', os.environ) travis_home = os.environ.get("HOME", "~/") travis_dependencies_dir = os.path.join(travis_home, 'dependencies') travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") odoo_unittest = str2bool(os.environ.get("UNIT_TEST")) odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") options = os.environ.get("OPTIONS", "").split() install_options = os.environ.get("INSTALL_OPTIONS", "").split() server_options = os.environ.get('SERVER_OPTIONS', "").split() expected_errors = int(os.environ.get("SERVER_EXPECTED_ERRORS", "0")) odoo_version = os.environ.get("VERSION") odoo_branch = os.environ.get("ODOO_BRANCH") instance_alive = str2bool(os.environ.get('INSTANCE_ALIVE')) unbuffer = str2bool(os.environ.get('UNBUFFER', True)) data_dir = os.path.expanduser(os.environ.get("DATA_DIR", '~/data_dir')) test_enable = str2bool(os.environ.get('TEST_ENABLE', True)) dbtemplate = os.environ.get('MQT_TEMPLATE_DB', 'openerp_template') database = os.environ.get('MQT_TEST_DB', 'openerp_test') if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version) test_loghandler = None if odoo_version == "6.1": install_options += ["--test-disable"] test_loglevel = 'test' else: if test_enable: options += ["--test-enable"] if odoo_version == '7.0': test_loglevel = 'test' else: test_loglevel = 'info' test_loghandler = 'openerp.tools.yaml_import:DEBUG' odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_branch or odoo_version, travis_home) script_name = get_server_script(server_path) addons_path = get_addons_path(travis_dependencies_dir, travis_build_dir, server_path) create_server_conf({ 'addons_path': addons_path, 'data_dir': data_dir, }, odoo_version) tested_addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) tested_addons = ','.join(tested_addons_list) print("Working in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not tested_addons: print("WARNING!\nNothing to test- exiting early.") return 0 else: print("Modules to test: %s" % tested_addons_list) # setup the preinstall modules without running the tests preinstall_modules = get_test_dependencies(addons_path, tested_addons_list) preinstall_modules = list( set(preinstall_modules) - set(get_modules(os.environ.get('TRAVIS_BUILD_DIR')))) or ['base'] print("Modules to preinstall: %s" % preinstall_modules) setup_server(dbtemplate, odoo_unittest, tested_addons_list, server_path, script_name, addons_path, install_options, preinstall_modules, unbuffer, server_options) # Running tests cmd_odoo_test = [ "coverage", "run", "%s/%s" % (server_path, script_name), "-d", database, "--db-filter=^%s$" % database, "--log-level", test_loglevel, ] if not "background_no_stop" in argv: cmd_odoo_test.append("--stop-after-init") if test_loghandler is not None: cmd_odoo_test += ['--log-handler', test_loghandler] cmd_odoo_test += options + ["--init", None] if odoo_unittest: to_test_list = tested_addons_list cmd_odoo_install = [ "%s/%s" % (server_path, script_name), "-d", database, "--log-level=warn", ] + server_options + install_options + ["--init", None] if not "background_no_stop" in argv: cmd_odoo_install.append("--stop-after-init") commands = ( (cmd_odoo_install, False), (cmd_odoo_test, True), ) else: to_test_list = [tested_addons] commands = ((cmd_odoo_test, True), ) all_errors = [] counted_errors = 0 for to_test in to_test_list: if odoo_unittest: print("\nTesting %s:" % [to_test]) else: print("\nTesting %s:" % tested_addons_list) try: db_odoo_created = subprocess.call( ["createdb", "-T", dbtemplate, database]) copy_attachments(dbtemplate, database, data_dir) except subprocess.CalledProcessError: db_odoo_created = True for command, check_loaded in commands: if db_odoo_created and instance_alive: # If exists database of odoo test # then start server with regular command without tests params rm_items = [ 'coverage', 'run', '--test-enable', '--init', None, '--log-handler', 'openerp.tools.yaml_import:DEBUG', ] if not "background_no_stop" in argv: rm_items.append("--stop-after-init") command_call = [item for item in commands[0][0] if item not in rm_items] + \ ['--pidfile=/tmp/odoo.pid'] else: command[-1] = to_test # Run test command; unbuffer keeps output colors command_call = (["unbuffer"] if unbuffer else []) + command print(" ".join(cmd_strip_secret(command_call))) pipe = subprocess.Popen(command_call, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) with open('stdout.log', 'wb') as stdout: for line in iter(pipe.stdout.readline, b''): stdout.write(line) print(line.strip().decode('UTF-8', errors='backslashreplace')) returncode = pipe.wait() # Find errors, except from failed mails errors = has_test_errors("stdout.log", database, odoo_version, check_loaded) if returncode != 0: all_errors.append(to_test) print(fail_msg, "Command exited with code %s" % returncode) # If there are no errors, # adds an error when returcode!=0 # because it's actually an error. if not errors: errors += 1 if errors: counted_errors += errors all_errors.append(to_test) print(fail_msg, "Found %d lines with errors" % errors) if not instance_alive and odoo_unittest: # Don't drop the database if will be used later. subprocess.call(["dropdb", database]) print('Module test summary') for to_test in to_test_list: if to_test in all_errors: print(fail_msg, to_test) else: print(success_msg, to_test) if expected_errors and counted_errors != expected_errors: print("Expected %d errors, found %d!" % (expected_errors, counted_errors)) return 1 elif counted_errors != expected_errors: return 1 # no test error, let's generate .pot and msgmerge all .po files must_run_makepot = (os.environ.get('MAKEPOT') == '1' and os.environ.get( 'TRAVIS_REPO_SLUG', '').startswith('OCA/') and os.environ.get('TRAVIS_BRANCH') in ('8.0', '9.0', '10.0', '11.0', '12.0') and os.environ.get('TRAVIS_PULL_REQUEST') == 'false' and os.environ.get('GITHUB_USER') and os.environ.get('GITHUB_EMAIL') and os.environ.get('GITHUB_TOKEN')) if must_run_makepot: # run makepot using the database we just tested makepot_cmd = ['unbuffer'] if unbuffer else [] makepot_cmd += [ 'travis_makepot', database, ] if subprocess.call(makepot_cmd) != 0: return 1 # if we get here, all is OK return 0
def main(argv=None): if argv is None: argv = sys.argv run_from_env_var('RUN_COMMAND_MQT', os.environ) travis_home = os.environ.get("HOME", "~/") travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") odoo_unittest = str2bool(os.environ.get("UNIT_TEST")) odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") options = os.environ.get("OPTIONS", "").split() install_options = os.environ.get("INSTALL_OPTIONS", "").split() server_options = os.environ.get('SERVER_OPTIONS', "").split() expected_errors = int(os.environ.get("SERVER_EXPECTED_ERRORS", "0")) odoo_version = os.environ.get("VERSION") odoo_branch = os.environ.get("ODOO_BRANCH") test_other_projects = parse_list(os.environ.get("TEST_OTHER_PROJECTS", '')) instance_alive = str2bool(os.environ.get('INSTANCE_ALIVE')) unbuffer = str2bool(os.environ.get('UNBUFFER', True)) # is_runbot = str2bool(os.environ.get('RUNBOT')) data_dir = os.environ.get("DATA_DIR", '~/data_dir') test_enable = str2bool(os.environ.get('TEST_ENABLE', True)) pg_logs_enable = str2bool(os.environ.get('PG_LOGS_ENABLE', False)) phantomjs_test = str2bool(os.environ.get('PHANTOMJS_TESTS')) no_extra_repos = str2bool(os.environ.get('NO_EXTRA_REPOS')) stdout_log = os.environ.get( "STDOUT_LOG", os.path.join(os.path.expanduser(data_dir), 'stdout.log')) if not os.path.isdir(os.path.dirname(stdout_log)): os.makedirs(os.path.dirname(stdout_log)) if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version) test_loghandler = None if odoo_version == "6.1": install_options += ["--test-disable"] test_loglevel = 'test' else: if test_enable: options += ["--test-enable"] if odoo_version == '7.0': test_loglevel = 'test' else: test_loglevel = 'info' test_loghandler = ['openerp.tools.yaml_import:DEBUG', 'openerp.models.schema:DEBUG'] odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path( odoo_full, odoo_branch or odoo_version, travis_home) script_name = get_server_script(server_path) addons_path = get_addons_path(travis_home, travis_build_dir, server_path) create_server_conf({ 'addons_path': addons_path, 'data_dir': data_dir, # Fix wkhtmltopdf freezing issue 'limit_memory_soft': 1073741824, 'limit_memory_hard': 1610612736, }, odoo_version) tested_addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) addons_path_list = parse_list(addons_path) all_depends = get_depends(addons_path_list, tested_addons_list) test_other_projects = map( lambda other_project: os.path.join(travis_home, other_project), test_other_projects) tested_addons = ','.join(tested_addons_list) if tested_addons and odoo_version == '8.0' and not no_extra_repos: tested_addons += ',odoolint_isolated' print("Working in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not tested_addons: print("WARNING!\nNothing to test- exiting early.") return 0 else: print("Modules to test: %s" % tested_addons) # setup the base module without running the tests dbtemplate = "openerp_template" preinstall_modules = get_test_dependencies(addons_path, tested_addons_list) preinstall_modules = list( set(preinstall_modules) - set(get_modules(travis_build_dir))) modules_other_projects = {} for test_other_project in test_other_projects: modules_other_projects[test_other_project] = get_modules( os.path.join(travis_home, test_other_project)) main_projects = modules_other_projects.copy() main_projects[travis_build_dir] = get_modules(travis_build_dir) primary_modules = [] for path, modules in main_projects.items(): primary_modules.extend(modules) primary_modules = set(primary_modules) & all_depends # Extend list of list in one main_modules = sum(main_projects.values(), []) primary_path_modules = {} for path, modules in main_projects.items(): for module in modules: if module in primary_modules: primary_path_modules[module] = os.path.join(path, module) fname_coveragerc = ".coveragerc" if os.path.exists(fname_coveragerc): with open(fname_coveragerc) as fp_coveragerc: coverage_data = fp_coveragerc.read() with open(fname_coveragerc, "w") as fpw_coveragerc: fpw_coveragerc.write(coverage_data.replace( ' */build/*', '\t' + '/*\n\t'.join(primary_path_modules.values()) + '/*' )) secondary_addons_path_list = set(addons_path_list) - set( [travis_build_dir] + test_other_projects) secondary_modules = [] for secondary_addons_path in secondary_addons_path_list: secondary_modules.extend(get_modules(secondary_addons_path)) secondary_modules = set(secondary_modules) & all_depends secondary_depends_primary = [] for secondary_module in secondary_modules: for secondary_depend in get_depends( addons_path_list, [secondary_module]): if secondary_depend in primary_modules: secondary_depends_primary.append(secondary_module) preinstall_modules = list( secondary_modules - set(secondary_depends_primary)) if phantomjs_test: # If you explicitly define this environ variable is because you want # run just phantomjs without normal unit-test. # Then we need install from template database ALL modules to run: # dbtemplate -i ALL_MODULES # dbtest --test-enable (without -i) # This run just phantomjs tests preinstall_modules += tested_addons.split(',') print("Modules to preinstall: %s" % preinstall_modules) setup_server(dbtemplate, odoo_unittest, tested_addons, server_path, script_name, addons_path, install_options, preinstall_modules, unbuffer, server_options, test_loghandler) # Running tests database = "openerp_test" cmd_odoo_test = ["coverage", "run", "%s/%s" % (server_path, script_name), "-d", database, "--stop-after-init", "--log-level", test_loglevel, ] if test_loghandler is not None: for lghd in test_loghandler: cmd_odoo_test += ['--log-handler', lghd] if odoo_unittest: cmd_odoo_test += options + ["--update", None] to_test_list = primary_modules cmd_odoo_install = [ "%s/%s" % (server_path, script_name), "-d", database, "--stop-after-init", "--log-level=warn", ] + install_options + ["--init", None] + server_options commands = ((cmd_odoo_install, False), (cmd_odoo_test, True), ) else: cmd_odoo_test += options + ["--init", None] to_test_list = [tested_addons] commands = ((cmd_odoo_test, True), ) all_errors = [] counted_errors = 0 stdout_log_base = stdout_log database_base = database for to_test in to_test_list: if odoo_unittest: database = database_base + '_' + to_test db_index = cmd_odoo_install.index('-d') + 1 cmd_odoo_install[db_index] = database stdout_log, stdout_ext = os.path.splitext(stdout_log_base) stdout_log += '_' + database + stdout_ext print("\nTesting %s:" % to_test) db_odoo_created = False try: db_odoo_created = subprocess.call( ["createdb", "-T", dbtemplate, database]) copy_attachments(dbtemplate, database, data_dir) except subprocess.CalledProcessError: db_odoo_created = True for command, check_loaded in commands: if db_odoo_created and instance_alive: command_start = commands[0][0] rm_items = [ 'coverage', 'run', '--stop-after-init', '--test-enable', '--init', None, '--log-handler', 'openerp.tools.yaml_import:DEBUG', ] for rm_item in rm_items: try: command_start.remove(rm_item) except ValueError: pass command_call = command_start + [ '--db-filter=^' + database_base] else: if phantomjs_test: # Remove the (--init, None) parameters command = command[:-2] else: command[-1] = to_test if not unbuffer: command_call = [] else: # Run test command; unbuffer keeps output colors command_call = ["unbuffer"] command_call += command if odoo_unittest: db_index = command_call.index('-d') + 1 command_call[db_index] = database print(' '.join(command_call)) env = None if pg_logs_enable and '--test-enable' in command_call: env = psql_log.get_env_log(os.environ) pipe = subprocess.Popen(command_call, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, env=env) with open(stdout_log, 'w') as stdout: for line in iter(pipe.stdout.readline, ''): if hidden_line(line, main_modules, addons_path_list): continue if 'openerp.models.schema: ' in line and 'DEBUG' in line: line = line.replace('DEBUG', 'WARNING') stdout.write(line) print(line.strip()) returncode = pipe.wait() # Find errors, except from failed mails errors = has_test_errors( stdout_log, database, odoo_version, check_loaded) if returncode != 0: all_errors.append(to_test) print(fail_msg, "Command exited with code %s" % returncode) # If not exists errors then # add an error when returcode!=0 # because is really a error. if not errors: errors += 1 if errors: counted_errors += errors all_errors.append(to_test) print(fail_msg, "Found %d lines with errors" % errors) if not instance_alive and odoo_unittest: subprocess.call(["dropdb", database]) print('Module test summary') for to_test in to_test_list: if to_test in all_errors: print(fail_msg, to_test) else: print(success_msg, to_test) if expected_errors and counted_errors != expected_errors: print("Expected %d errors, found %d!" % (expected_errors, counted_errors)) return 1 elif counted_errors != expected_errors: return 1 # if we get here, all is OK return 0
def main(argv=None): if argv is None: argv = sys.argv run_from_env_var('RUN_COMMAND_MQT', os.environ) travis_home = os.environ.get("HOME", "~/") travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") odoo_unittest = str2bool(os.environ.get("UNIT_TEST")) odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") options = os.environ.get("OPTIONS", "").split() install_options = os.environ.get("INSTALL_OPTIONS", "").split() server_options = os.environ.get('SERVER_OPTIONS', "").split() expected_errors = int(os.environ.get("SERVER_EXPECTED_ERRORS", "0")) odoo_version = os.environ.get("VERSION") odoo_branch = os.environ.get("ODOO_BRANCH") test_other_projects = parse_list(os.environ.get("TEST_OTHER_PROJECTS", '')) instance_alive = str2bool(os.environ.get('INSTANCE_ALIVE')) unbuffer = str2bool(os.environ.get('UNBUFFER', True)) # is_runbot = str2bool(os.environ.get('RUNBOT')) data_dir = os.environ.get("DATA_DIR", '~/data_dir') test_enable = str2bool(os.environ.get('TEST_ENABLE', True)) pg_logs_enable = str2bool(os.environ.get('PG_LOGS_ENABLE', False)) phantomjs_test = str2bool(os.environ.get('PHANTOMJS_TESTS')) no_extra_repos = str2bool(os.environ.get('NO_EXTRA_REPOS')) stdout_log = os.environ.get( "STDOUT_LOG", os.path.join(os.path.expanduser(data_dir), 'stdout.log')) if not os.path.isdir(os.path.dirname(stdout_log)): os.makedirs(os.path.dirname(stdout_log)) if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version) test_loghandler = None if odoo_version == "6.1": install_options += ["--test-disable"] test_loglevel = 'test' else: if test_enable: options += ["--test-enable"] if odoo_version == '7.0': test_loglevel = 'test' else: test_loglevel = 'info' test_loghandler = [ 'openerp.tools.yaml_import:DEBUG', 'openerp.models.schema:DEBUG' ] odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_branch or odoo_version, travis_home) script_name = get_server_script(server_path) addons_path = get_addons_path(travis_home, travis_build_dir, server_path) create_server_conf( { 'addons_path': addons_path, 'data_dir': data_dir, # Fix wkhtmltopdf freezing issue 'limit_memory_soft': 1073741824, 'limit_memory_hard': 1610612736, }, odoo_version) tested_addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) addons_path_list = parse_list(addons_path) all_depends = get_depends(addons_path_list, tested_addons_list) test_other_projects = map( lambda other_project: os.path.join(travis_home, other_project), test_other_projects) tested_addons = ','.join(tested_addons_list) if tested_addons and odoo_version == '8.0' and not no_extra_repos: tested_addons += ',odoolint_isolated' print("Working in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not tested_addons: print("WARNING!\nNothing to test- exiting early.") return 0 else: print("Modules to test: %s" % tested_addons) # setup the base module without running the tests dbtemplate = "openerp_template" preinstall_modules = get_test_dependencies(addons_path, tested_addons_list) preinstall_modules = list( set(preinstall_modules) - set(get_modules(travis_build_dir))) modules_other_projects = {} for test_other_project in test_other_projects: modules_other_projects[test_other_project] = get_modules( os.path.join(travis_home, test_other_project)) main_projects = modules_other_projects.copy() main_projects[travis_build_dir] = get_modules(travis_build_dir) primary_modules = [] for path, modules in main_projects.items(): primary_modules.extend(modules) primary_modules = set(primary_modules) & all_depends # Extend list of list in one main_modules = sum(main_projects.values(), []) primary_path_modules = {} for path, modules in main_projects.items(): for module in modules: if module in primary_modules: primary_path_modules[module] = os.path.join(path, module) fname_coveragerc = ".coveragerc" if os.path.exists(fname_coveragerc): with open(fname_coveragerc) as fp_coveragerc: coverage_data = fp_coveragerc.read() with open(fname_coveragerc, "w") as fpw_coveragerc: fpw_coveragerc.write( coverage_data.replace( ' */build/*', '\t' + '/*\n\t'.join(primary_path_modules.values()) + '/*')) secondary_addons_path_list = set(addons_path_list) - set( [travis_build_dir] + test_other_projects) secondary_modules = [] for secondary_addons_path in secondary_addons_path_list: secondary_modules.extend(get_modules(secondary_addons_path)) secondary_modules = set(secondary_modules) & all_depends secondary_depends_primary = [] for secondary_module in secondary_modules: for secondary_depend in get_depends(addons_path_list, [secondary_module]): if secondary_depend in primary_modules: secondary_depends_primary.append(secondary_module) preinstall_modules = list(secondary_modules - set(secondary_depends_primary)) if phantomjs_test: # If you explicitly define this environ variable is because you want # run just phantomjs without normal unit-test. # Then we need install from template database ALL modules to run: # dbtemplate -i ALL_MODULES # dbtest --test-enable (without -i) # This run just phantomjs tests preinstall_modules += tested_addons.split(',') print("Modules to preinstall: %s" % preinstall_modules) setup_server(dbtemplate, odoo_unittest, tested_addons, server_path, script_name, addons_path, install_options, preinstall_modules, unbuffer, server_options, test_loghandler) # Running tests database = "openerp_test" cmd_odoo_test = [ "coverage", "run", "%s/%s" % (server_path, script_name), "-d", database, "--stop-after-init", "--log-level", test_loglevel, ] if test_loghandler is not None: for lghd in test_loghandler: cmd_odoo_test += ['--log-handler', lghd] if odoo_unittest: cmd_odoo_test += options + ["--update", None] to_test_list = primary_modules cmd_odoo_install = [ "%s/%s" % (server_path, script_name), "-d", database, "--stop-after-init", "--log-level=warn", ] + install_options + ["--init", None] + server_options commands = ( (cmd_odoo_install, False), (cmd_odoo_test, True), ) else: cmd_odoo_test += options + ["--init", None] to_test_list = [tested_addons] commands = ((cmd_odoo_test, True), ) all_errors = [] counted_errors = 0 stdout_log_base = stdout_log database_base = database for to_test in to_test_list: if odoo_unittest: database = database_base + '_' + to_test db_index = cmd_odoo_install.index('-d') + 1 cmd_odoo_install[db_index] = database stdout_log, stdout_ext = os.path.splitext(stdout_log_base) stdout_log += '_' + database + stdout_ext print("\nTesting %s:" % to_test) db_odoo_created = False try: db_odoo_created = subprocess.call( ["createdb", "-T", dbtemplate, database]) copy_attachments(dbtemplate, database, data_dir) except subprocess.CalledProcessError: db_odoo_created = True for command, check_loaded in commands: if db_odoo_created and instance_alive: command_start = commands[0][0] rm_items = [ 'coverage', 'run', '--stop-after-init', '--test-enable', '--init', None, '--log-handler', 'openerp.tools.yaml_import:DEBUG', ] for rm_item in rm_items: try: command_start.remove(rm_item) except ValueError: pass command_call = command_start + [ '--db-filter=^' + database_base ] else: if phantomjs_test: # Remove the (--init, None) parameters command = command[:-2] else: command[-1] = to_test if not unbuffer: command_call = [] else: # Run test command; unbuffer keeps output colors command_call = ["unbuffer"] command_call += command if odoo_unittest: db_index = command_call.index('-d') + 1 command_call[db_index] = database print(' '.join(command_call)) env = None if pg_logs_enable and '--test-enable' in command_call: env = psql_log.get_env_log(os.environ) pipe = subprocess.Popen(command_call, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, env=env) with open(stdout_log, 'w') as stdout: for line in iter(pipe.stdout.readline, ''): if hidden_line(line, main_modules, addons_path_list): continue if 'openerp.models.schema: ' in line and 'DEBUG' in line: line = line.replace('DEBUG', 'WARNING') stdout.write(line) print(line.strip()) returncode = pipe.wait() # Find errors, except from failed mails errors = has_test_errors(stdout_log, database, odoo_version, check_loaded) if returncode != 0: all_errors.append(to_test) print(fail_msg, "Command exited with code %s" % returncode) # If not exists errors then # add an error when returcode!=0 # because is really a error. if not errors: errors += 1 if errors: counted_errors += errors all_errors.append(to_test) print(fail_msg, "Found %d lines with errors" % errors) if not instance_alive and odoo_unittest: subprocess.call(["dropdb", database]) print('Module test summary') for to_test in to_test_list: if to_test in all_errors: print(fail_msg, to_test) else: print(success_msg, to_test) if expected_errors and counted_errors != expected_errors: print("Expected %d errors, found %d!" % (expected_errors, counted_errors)) return 1 elif counted_errors != expected_errors: return 1 # if we get here, all is OK return 0