def test_pylint_checks(): base_path = pylint_cmk.get_test_dir() f = file(base_path + "/cmk-checks.py", "w") # add the modules for path in pylint_cmk.ordered_module_files(): pylint_cmk.add_file(f, path) # Now add the checks for path in pylint_cmk.check_files(repo_path() + "/checks"): pylint_cmk.add_file(f, path) # Also add inventory plugins for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(f, path) # Also add bakery plugins for path in pylint_cmk.check_files(os.path.realpath(repo_path() + "/../cmc/agents/bakery")): pylint_cmk.add_file(f, path) f.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in checks, inventory " \ "or agent bakery plugins"
def test_pylint_checks(): base_path = pylint_cmk.get_test_dir() f = file(base_path + "/cmk-checks.py", "w") # add the modules for path in pylint_cmk.ordered_module_files(): pylint_cmk.add_file(f, path) # Now add the checks for path in pylint_cmk.check_files(repo_path() + "/checks"): pylint_cmk.add_file(f, path) # Also add inventory plugins for path in pylint_cmk.check_files(repo_path() + "/inventory"): pylint_cmk.add_file(f, path) # Also add bakery plugins for path in pylint_cmk.check_files(cmc_path() + "/agents/bakery"): pylint_cmk.add_file(f, path) f.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in checks, inventory " \ "or agent bakery plugins"
def test_pylint(pylint_test_dir): # Only specify the path to python packages or modules here modules_or_packages = [ # OMD "omd/packages/omd/omdlib", "livestatus/api/python/livestatus.py", # Check_MK base "cmk_base", # TODO: Check if this kind of "overlay" really works. # TODO: Why do we have e.g. a symlink cmk_base/cee -> enterprise/cmk_base/cee? "enterprise/cmk_base/automations/cee.py", "enterprise/cmk_base/cee", "enterprise/cmk_base/default_config/cee.py", "enterprise/cmk_base/modes/cee.py", "managed/cmk_base/default_config/cme.py", # cmk module level # TODO: This checks the whole cmk hierarchy, including things like # cmk.gui.plugins.cron etc. Do we really want that here? # TODO: Funny links there, see above. "cmk", "enterprise/cmk/cee", # GUI specific "web/app/index.wsgi", "enterprise/cmk/gui/cee", "managed/cmk/gui/cme", ] # Add the compiled files for things that are no modules yet open(pylint_test_dir + "/__init__.py", "w") _compile_check_and_inventory_plugins(pylint_test_dir) _compile_bakery_plugins(pylint_test_dir) modules_or_packages += [ pylint_test_dir, ] # We use our own search logic to find scripts without python extension search_paths = [ "omd/packages/omd.bin", "bin", "notifications", "agents/plugins", "agents/special", "active_checks", "enterprise/agents/plugins", "enterprise/bin", "enterprise/misc", ] for path in search_paths: abs_path = cmk_path() + "/" + path for fname in pylint_cmk.get_pylint_files(abs_path, "*"): modules_or_packages.append(path + "/" + fname) exit_code = pylint_cmk.run_pylint(cmk_path(), modules_or_packages) assert exit_code == 0, "PyLint found an error"
def test_pylint(pylint_test_dir, capsys): with capsys.disabled(): print("\n") retcode = subprocess.call("python -m pylint --version".split(), shell=False) print() assert not retcode exit_code = pylint_cmk.run_pylint(repo_path(), _get_files_to_check(pylint_test_dir)) assert exit_code == 0, "PyLint found an error"
def test_pylint_modules(): base_path = pylint_cmk.get_test_dir() f = file(base_path + "/cmk-modules.py", "w") for path in pylint_cmk.ordered_module_files(): pylint_cmk.add_file(f, path) f.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in modules"
def test_pylint_misc(): search_paths = [ "lib", "bin", "notifications", "agents/plugins", "doc/treasures/active_checks", "../cmc/agents/plugins", "../cmc/bin", "../cmc/misc", ] checked, worst = 0, 0 for rel_path in search_paths: path = os.path.realpath(repo_path() + "/" + rel_path) worst = max(worst, pylint_cmk.run_pylint(path)) checked += 1 assert checked > 0, "Did not find a file to check!" assert worst == 0, "At least one issue found"
def test_pylint_misc(): search_paths = [ cmk_path() + "/cmk_base", cmc_path() + "/cmk_base", cmk_path() + "/lib", cmk_path() + "/bin", cmk_path() + "/notifications", cmk_path() + "/agents/plugins", cmk_path() + "/active_checks", cmc_path() + "/agents/plugins", cmc_path() + "/bin", cmc_path() + "/misc", ] checked, worst = 0, 0 for path in search_paths: worst = max(worst, pylint_cmk.run_pylint(path)) checked += 1 assert checked > 0, "Did not find a file to check!" assert worst == 0, "At least one issue found"
def test_pylint_web(): base_path = pylint_cmk.get_test_dir() # Make compiled files import eachother by default sys.path.insert(0, base_path) modules = glob.glob(cmk_path() + "/web/htdocs/*.py") \ + glob.glob(cmc_path() + "/web/htdocs/*.py") \ + glob.glob(cme_path() + "/web/htdocs/*.py") for module in modules: print("Copy %s to test directory" % module) f = open(base_path + "/" + os.path.basename(module), "w") pylint_cmk.add_file(f, module) f.close() # Move the whole plugins code to their modules, then # run pylint only on the modules for plugin_dir in get_web_plugin_dirs(): files = get_plugin_files(plugin_dir) for plugin_file, plugin_base in files: plugin_path = plugin_base + "/" + plugin_file if plugin_file.startswith('.'): continue elif plugin_dir in ["icons", "perfometer"]: module_name = "views" elif plugin_dir == "pages": module_name = "modules" else: module_name = plugin_dir print("[%s] add %s" % (module_name, plugin_path)) module = file(base_path + "/" + module_name + ".py", "a") pylint_cmk.add_file(module, plugin_path) module.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in the web code"
def test_pylint_web(): base_path = pylint_cmk.get_test_dir() # Make compiled files import eachother by default sys.path.insert(0, base_path) modules = glob.glob(cmk_path() + "/web/htdocs/*.py") \ + glob.glob(cmc_path() + "/web/htdocs/*.py") for module in modules: print("Copy %s to test directory" % module) f = open(base_path + "/" + os.path.basename(module), "w") pylint_cmk.add_file(f, module) f.close() # Move the whole plugins code to their modules, then # run pylint only on the modules for plugin_dir in get_web_plugin_dirs(): files = get_plugin_files(plugin_dir) for plugin_file, plugin_base in files: plugin_path = plugin_base +"/"+plugin_file if plugin_file.startswith('.'): continue elif plugin_dir in ["icons","perfometer"]: module_name = "views" elif plugin_dir == "pages": module_name = "modules" else: module_name = plugin_dir print("[%s] add %s" % (module_name, plugin_path)) module = file(base_path + "/" + module_name + ".py", "a") pylint_cmk.add_file(module, plugin_path) module.close() exit_code = pylint_cmk.run_pylint(base_path, cleanup_test_dir=True) assert exit_code == 0, "PyLint found an error in the web code"
def test_pylint(pylint_test_dir): exit_code = pylint_cmk.run_pylint(repo_path(), _get_files_to_check(pylint_test_dir)) assert exit_code == 0, "PyLint found an error"
def test_pylint(pylint_test_dir): # Only specify the path to python packages or modules here if sys.version_info[0] >= 3: modules_or_packages = [] else: modules_or_packages = [ "omd/packages/omd/omdlib", "livestatus/api/python/livestatus.py", "cmk_base", "cmk", "web/app/index.wsgi", ] if is_enterprise_repo(): modules_or_packages += [ # TODO: Check if this kind of "overlay" really works. # TODO: Why do we have e.g. a symlink cmk_base/cee -> enterprise/cmk_base/cee? "enterprise/cmk_base/automations/cee.py", "enterprise/cmk_base/cee", "enterprise/cmk_base/default_config/cee.py", "enterprise/cmk_base/modes/cee.py", # TODO: Funny links there, see above. "enterprise/cmk/cee", "enterprise/cmk/gui/cee", ] if is_managed_repo(): modules_or_packages += [ "managed/cmk_base/default_config/cme.py", "managed/cmk/gui/cme", ] # Add the compiled files for things that are no modules yet open(pylint_test_dir + "/__init__.py", "w") _compile_check_and_inventory_plugins(pylint_test_dir) if is_enterprise_repo(): _compile_bakery_plugins(pylint_test_dir) # Not checking compiled check, inventory, bakery plugins with Python 3 if sys.version_info[0] == 2: modules_or_packages += [ pylint_test_dir, ] # We use our own search logic to find scripts without python extension search_paths = [ "omd/packages/omd.bin", "bin", "notifications", "agents/plugins", "agents/special", "active_checks", ] if is_enterprise_repo(): search_paths += [ "enterprise/agents/plugins", "enterprise/bin", "enterprise/misc", ] for path in search_paths: abs_path = cmk_path() + "/" + path for fname in pylint_cmk.get_pylint_files(abs_path, "*"): modules_or_packages.append(path + "/" + fname) exit_code = pylint_cmk.run_pylint(cmk_path(), modules_or_packages) assert exit_code == 0, "PyLint found an error"