diff --git a/.automation/test/mega-linter-config-test/base.local.mega-linter.yml b/.automation/test/mega-linter-config-test/base.local.mega-linter.yml new file mode 100644 index 00000000000..2f642cb9d4f --- /dev/null +++ b/.automation/test/mega-linter-config-test/base.local.mega-linter.yml @@ -0,0 +1,2 @@ +FILTER_REGEX_INCLUDE: "(base-local)" +SHOW_ELAPSED_TIME: true diff --git a/.automation/test/mega-linter-config-test/local-error.mega-linter.yml b/.automation/test/mega-linter-config-test/local-error.mega-linter.yml new file mode 100644 index 00000000000..d2e5b5547ba --- /dev/null +++ b/.automation/test/mega-linter-config-test/local-error.mega-linter.yml @@ -0,0 +1 @@ +EXTENDS: base-error.local.mega-linter.yml diff --git a/.automation/test/mega-linter-config-test/local.mega-linter.yml b/.automation/test/mega-linter-config-test/local.mega-linter.yml new file mode 100644 index 00000000000..5c3c891f463 --- /dev/null +++ b/.automation/test/mega-linter-config-test/local.mega-linter.yml @@ -0,0 +1,3 @@ +EXTENDS: base.local.mega-linter.yml +FILTER_REGEX_INCLUDE: "(local)" +SHOW_ELAPSED_TIME: false diff --git a/megalinter/config.py b/megalinter/config.py index bca010cab3a..139f94a08d7 100644 --- a/megalinter/config.py +++ b/megalinter/config.py @@ -83,7 +83,7 @@ def init_config(workspace=None): ), f"Unable to retrieve EXTENDS config file {config_file_name}" extends_config_data = yaml.safe_load(r.content) else: - with open(extends_item, "r", encoding="utf-8") as f: + with open(workspace + os.path.sep + extends_item, "r", encoding="utf-8") as f: extends_config_data = yaml.safe_load(f) combined_config.update(extends_config_data) CONFIG_SOURCE += f"\n[config] - extends from: {extends_item}" diff --git a/megalinter/tests/test_megalinter/config_test.py b/megalinter/tests/test_megalinter/config_test.py index e54693f2ab6..c841e4d7185 100644 --- a/megalinter/tests/test_megalinter/config_test.py +++ b/megalinter/tests/test_megalinter/config_test.py @@ -8,6 +8,7 @@ from megalinter import config from megalinter.constants import ML_REPO +from megalinter.utils import REPO_HOME_DEFAULT class config_test(unittest.TestCase): @@ -45,6 +46,21 @@ def test_remote_config_error(self): except Exception as e: self.assertIn("http", str(e)) + def test_local_config_extends_success(self): + local_config = "local.mega-linter.yml" + os.environ["MEGALINTER_CONFIG"] = local_config + config.init_config(REPO_HOME_DEFAULT + os.path.sep + ".automation" + os.path.sep + "test" + os.path.sep + "mega-linter-config-test") + self.assertEqual("(local)", config.get("FILTER_REGEX_INCLUDE")) + self.assertEqual("false", config.get("SHOW_ELAPSED_TIME")) + + def test_local_config_extends_error(self): + local_config = "local-error.mega-linter.yml" + os.environ["MEGALINTER_CONFIG"] = local_config + try: + config.init_config(REPO_HOME_DEFAULT + os.path.sep + ".automation" + os.path.sep + "test" + os.path.sep + "mega-linter-config-test") + except Exception as e: + self.assertIn("No such file or directory", str(e)) + def test_remote_config_extends_success(self): remote_config = self.test_folder + "base.mega-linter.yml" os.environ["MEGALINTER_CONFIG"] = remote_config