Exemple #1
0
 def test_load_plugin_format_error_2(self):
     try:
         utilstest.call_mega_linter({
             "PLUGINS": "hello",
             "LOG_LEVEL": "DEBUG",
             "MULTI_STATUS": "false",
             "GITHUB_COMMENT_REPORTER": "false",
         })
     except Exception as e:
         self.assertIn(
             "[Plugins] Plugin descriptors must follow the format", str(e))
Exemple #2
0
 def test_load_plugin_http_error(self):
     try:
         utilstest.call_mega_linter({
             "PLUGINS":
             "https://raw.githubus3ent.com/nvuillam/mega-linter/"
             "plugins/.automation/test/mega-linter-plugin-test/test.not.here.megalinter-descriptor.yml",
             "LOG_LEVEL":
             "DEBUG",
             "MULTI_STATUS":
             "false",
             "GITHUB_COMMENT_REPORTER":
             "false",
         })
     except Exception as e:
         self.assertIn("[Plugins] Unable to load plugin", str(e))
 def test_logging_level_debug(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"LOG_LEVEL": "DEBUG"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("[INFO]", output)
     self.assertIn("[DEBUG]", output)
Exemple #4
0
 def test_2_apply_fixes_on_all_linters(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"APPLY_FIXES": "all", "LOG_LEVEL": "DEBUG", "MULTI_STATUS": "false"}
     )
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run"
     )
     self.assertIn("### Processing [JAVASCRIPT] files", output)
     time.sleep(5)
     # Check fixable files has been updated
     fixable_files = [
         "bash_for_fixes_1.sh",
         "csharp_for_fixes_1.cs",
         "env_for_fixes_1.env",
         "groovy_for_fixes_1.groovy",
         "javascript_for_fixes_1.js",
         "kotlin_for_fixes_1.kt",
         "markdown_for_fixes_1.md",
         "python_for_fixes_1.py",
         "rst_for_fixes_1.rst",
         "ruby_for_fixes_1.rb",
         "spell_for_fixes_1.js",
         # "scala_for_fixes_1.scala",
         "snakemake_for_fixes_1.smk",
         "vbdotnet_for_fixes_1.vb",
     ]
     # updated_dir = config.get("UPDATED_SOURCES_REPORTER_DIR", "updated_sources")
     # updated_sources_dir = f"{mega_linter.report_folder}{os.path.sep}{updated_dir}"
     for fixable_file in fixable_files:
         # Check linters applied updates
         utilstest.assert_file_has_been_updated(fixable_file, True, self)
Exemple #5
0
 def test_new_flavor_suggestion(self):
     mega_linter, output = utilstest.call_mega_linter({
         "MULTI_STATUS": "false",
         "LOG_LEVEL": "DEBUG"
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertEqual("new", mega_linter.flavor_suggestions[0])
Exemple #6
0
 def test_disable_linter(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"DISABLE_LINTERS": "JAVASCRIPT_ES"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     utilstest.assert_is_skipped("JAVASCRIPT_ES", output, self)
     self.assertIn("### Processed [JAVASCRIPT] files", output)
     self.assertIn("Using [standard", output)
 def test_disable_linter_legacy(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"VALIDATE_JAVASCRIPT_ES": "false"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     utilstest.assert_is_skipped("JAVASCRIPT_ES", output, self)
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn("Using [standard", output)
 def test_enable_only_one_linter(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"ENABLE_LINTERS": "JAVASCRIPT_ES"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     utilstest.assert_is_skipped("JAVASCRIPT_STANDARD", output, self)
     utilstest.assert_is_skipped("GROOVY", output, self)
Exemple #9
0
 def test_load_plugin_file_name_error(self):
     try:
         utilstest.call_mega_linter({
             "PLUGINS":
             "https://raw.githubusercontent.com/nvuillam/mega-linter/"
             "plugins/.automation/test/mega-linter-plugin-test/test.megalinter-wrong.yml",
             "LOG_LEVEL":
             "DEBUG",
             "MULTI_STATUS":
             "false",
             "GITHUB_COMMENT_REPORTER":
             "false",
         })
     except Exception as e:
         self.assertIn(
             "[Plugins] Plugin descriptor file must end with .megalinter-descriptor.yml",
             str(e),
         )
 def test_enable_only_one_language_legacy(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"VALIDATE_JAVASCRIPT": "true"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     self.assertIn("Using [standard", output)
     utilstest.assert_is_skipped("GROOVY", output, self)
Exemple #11
0
 def test_enable_only_one_linter_legacy(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"VALIDATE_JAVASCRIPT_ES": "true"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("### Processed [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     utilstest.assert_is_skipped("JAVASCRIPT_STANDARD", output, self)
     utilstest.assert_is_skipped("GROOVY", output, self)
Exemple #12
0
 def test_enable_only_one_language(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"ENABLE": "JAVASCRIPT"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("### Processed [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     self.assertIn("Using [standard", output)
     utilstest.assert_is_skipped("GROOVY", output, self)
Exemple #13
0
 def test_load_plugin_host_url_error_1(self):
     try:
         utilstest.call_mega_linter({
             "PLUGINS":
             "https://raw.githubusercontent.com/nvuillam/mega-linter/"
             "plugins/.automation/test/some_folder_name/test.megalinter-descriptor.yml",
             "LOG_LEVEL":
             "DEBUG",
             "MULTI_STATUS":
             "false",
             "GITHUB_COMMENT_REPORTER":
             "false",
         })
     except Exception as e:
         self.assertIn(
             "[Plugins] Plugin descriptor file must be hosted in"
             " a directory containing /mega-linter-plugin-",
             str(e),
         )
Exemple #14
0
 def test_config_reporter(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"CONFIG_REPORTER": "true"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     expected_output_file = (mega_linter.report_folder + os.path.sep +
                             "IDE-config.txt")
     self.assertTrue(
         os.path.isfile(expected_output_file),
         "Output IDE config file " + expected_output_file + " should exist",
     )
Exemple #15
0
 def test_json_output(self):
     mega_linter, output = utilstest.call_mega_linter(
         {"JSON_REPORTER": "true"})
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     expected_output_file = (mega_linter.report_folder + os.path.sep +
                             "mega-linter-report.json")
     self.assertTrue(
         os.path.isfile(expected_output_file),
         "Output json file " + expected_output_file + " should exist",
     )
 def test_general_include_exclude(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "JAVASCRIPT_ES",
         "FILTER_REGEX_INCLUDE":
         r"(.*_good_.*|.*\/good\/.*)",
         "FILTER_REGEX_EXCLUDE":
         r"(.*_bad_.*|.*\/bad\/.*)",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("Linting [JAVASCRIPT] files", output)
Exemple #17
0
 def test_pre_post_success(self):
     mega_linter, output = utilstest.call_mega_linter({
         "MULTI_STATUS":
         "false",
         "GITHUB_COMMENT_REPORTER":
         "false",
         "LOG_LEVEL":
         "DEBUG",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("pre-test command has been called", output)
     self.assertIn("npm run test has been called", output)
 def test_override_linter_rules_path(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "JAVASCRIPT_ES",
         "LINTER_RULES_PATH":
         ".",
         "JAVASCRIPT_ES_FILE_NAME":
         ".eslintrc-custom.yml",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     self.assertIn(".eslintrc-custom.yml", output)
Exemple #19
0
 def test_print_all_files_false_and_no_flavor_suggestion(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "JAVASCRIPT_ES",
         "PRINT_ALL_FILES":
         "false",
         "MEGALINTER_FLAVOR":
         "javascript",
         "FLAVOR_SUGGESTIONS":
         "false",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("- Number of files analyzed", output)
 def test_override_linter_rules_path_remote_error(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "JAVASCRIPT_ES",
         "LINTER_RULES_PATH":
         "https://raw.githubusercontent.com/nvuillam/notexisting",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn(
         "Unable to fetch https://raw.githubusercontent.com/nvuillam/notexisting",
         output,
     )
 def test_validate_all_code_base_false(self):
     megalinter.config.set_value(
         "GITHUB_WORKSPACE",
         ("/tmp/lint" if os.path.isdir("/tmp/lint") else os.path.relpath(
             os.path.relpath(os.path.dirname(os.path.abspath(__file__))) +
             "/../../..")),
     )
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "PYTHON_PYLINT",
         "VALIDATE_ALL_CODEBASE":
         "false"
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
 def test_custom_config_on_linter(self):
     mega_linter, output = utilstest.call_mega_linter(
         {
             "ENABLE_LINTERS": "JAVASCRIPT_ES",
             "JAVASCRIPT_ES_LINTER_RULES_PATH": ".",
             "JAVASCRIPT_ES_FILE_NAME": ".eslintrc-custom.yml",
             "JAVASCRIPT_FILTER_REGEX_INCLUDE": "(.*_good_.*|.*\\/good\\/.*)",
             "JAVASCRIPT_FILTER_REGEX_EXCLUDE": "(.*_bad_.*|.*\\/bad\\/.*)",
             "MULTI_STATUS": "false",
         }
     )
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run"
     )
     self.assertIn("Linting [JAVASCRIPT] files", output)
Exemple #23
0
 def test_1_apply_fixes_on_one_linter(self):
     mega_linter, output = utilstest.call_mega_linter(
         {
             "APPLY_FIXES": "JAVASCRIPT_STANDARD",
             "LOG_LEVEL": "DEBUG",
             "MULTI_STATUS": "false",
         }
     )
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run"
     )
     self.assertIn("### Processing [JAVASCRIPT] files", output)
     time.sleep(5)
     utilstest.assert_file_has_been_updated("javascript_for_fixes_1.js", True, self)
     utilstest.assert_file_has_been_updated("env_for_fixes_1.env", False, self)
Exemple #24
0
 def test_custom_config_on_language(self):
     mega_linter, output = utilstest.call_mega_linter(
         {
             "ENABLE_LINTERS": "JAVASCRIPT_ES",
             "JAVASCRIPT_LINTER_RULES_PATH": ".",
             "JAVASCRIPT_CONFIG_FILE": ".eslintrc-custom.yml",
             "JAVASCRIPT_FILTER_REGEX_INCLUDE": r"(.*_good_.*|.*\/good\/.*)",
             "JAVASCRIPT_FILTER_REGEX_EXCLUDE": r"(.*_bad_.*|.*\/bad\/.*)",
         }
     )
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run"
     )
     self.assertIn("### Processing [JAVASCRIPT] files", output)
     self.assertIn(".eslintrc-custom.yml", output)
 def test_user_arguments_on_linter(self):
     mega_linter, output = utilstest.call_mega_linter(
         {
             "ENABLE_LINTERS": "JAVASCRIPT_ES",
             "JAVASCRIPT_ES_FILTER_REGEX_INCLUDE": "(.*_good_.*|.*\\/good\\/.*)",
             "JAVASCRIPT_ES_FILTER_REGEX_EXCLUDE": "(.*_bad_.*|.*\\/bad\\/.*)",
             "JAVASCRIPT_ES_ARGUMENTS": "--debug --env-info",
             "MULTI_STATUS": "false",
             "LOG_LEVEL": "DEBUG",
         }
     )
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run"
     )
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn("--debug --env-info", output)
Exemple #26
0
 def test_load_plugin_success(self):
     mega_linter, output = utilstest.call_mega_linter({
         "PLUGINS":
         "https://raw.githubusercontent.com/nvuillam/mega-linter/"
         "master/.automation/test/mega-linter-plugin-test/test.megalinter-descriptor.yml",
         "LOG_LEVEL":
         "DEBUG",
         "MULTI_STATUS":
         "false",
         "GITHUB_COMMENT_REPORTER":
         "false",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("### Processed [TEST] files", output)
     self.assertIn("[Plugins] Loaded plugin descriptor", output)
     self.assertIn("[Plugins] Successful initialization of TEST", output)
 def test_override_linter_rules_path_remote(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "JAVASCRIPT_ES",
         "LINTER_RULES_PATH":
         "https://raw.githubusercontent.com/nvuillam/"
         "mega-linter/master/.automation/test/sample_project",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("Linting [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     self.assertIn(
         "- Rules config: [https://raw.githubusercontent.com/nvuillam/"
         "mega-linter/master/.automation/test/sample_project/.eslintrc.json]",
         output,
     )
Exemple #28
0
 def test_override_cli_lint_mode(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE":
         "YAML",
         "YAML_YAMLLINT_CLI_LINT_MODE":
         "file",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertTrue(
         len(
             list(
                 filter(
                     lambda x: (x.name == "YAML_YAMLLINT" and x.
                                cli_lint_mode == "file"),
                     mega_linter.linters,
                 ))) == 1,
         "YAML_YAMLLINT should have been processed with cli_lint_mode = file",
     )
Exemple #29
0
 def test_override_cli_executable(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE":
         "PHP",
         "PHP_BUILTIN_CLI_EXECUTABLE":
         "/usr/bin/php8",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertTrue(
         len(
             list(
                 filter(
                     lambda x: (x.name == "PHP_BUILTIN" and x.cli_executable
                                == "/usr/bin/php8"),
                     mega_linter.linters,
                 ))) == 1,
         "PHP_BUILTIN should have been processed with cli_executable = /usr/bin/php8",
     )
Exemple #30
0
 def test_override_linter_rules_path_remote_custom_file_name(self):
     mega_linter, output = utilstest.call_mega_linter({
         "ENABLE_LINTERS":
         "JAVASCRIPT_ES",
         "LINTER_RULES_PATH":
         f"https://raw.githubusercontent.com/{ML_REPO}/main/"
         ".automation/test/sample_project",
         "JAVASCRIPT_ES_CONFIG_FILE":
         ".eslintrc-custom.yml",
     })
     self.assertTrue(
         len(mega_linter.linters) > 0, "Linters have been created and run")
     self.assertIn("### Processed [JAVASCRIPT] files", output)
     self.assertIn("Using [eslint", output)
     self.assertIn(
         f"- Rules config: [https://raw.githubusercontent.com/{ML_REPO}/main/"
         ".automation/test/sample_project/.eslintrc-custom.yml]",
         output,
     )
     self.assertIn(".eslintrc-custom.yml", output)