diff --git a/bin/project_config/test_project_config.py b/bin/project_config/test_project_config.py index ff9bcd0c..c41870ce 100644 --- a/bin/project_config/test_project_config.py +++ b/bin/project_config/test_project_config.py @@ -9,7 +9,7 @@ import unittest.mock sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from failure import Failure -from project_config.settings import held, load, OUTSIDE, ProjectConfig, SETTINGS +from project_config.settings import env_files, held, load, OUTSIDE, ProjectConfig, SETTINGS from test_env import isolated_env TOOL = pathlib.Path(__file__).resolve().parents[1] / "project-config" @@ -238,6 +238,15 @@ class HeldTest(ConfigCase): self.assertIsInstance(held(target, self.home), ProjectConfig, "git names the folder by its resolved path") +class EnvFilesTest(ConfigCase): + def test_lists_each_readable_configs_env_file_even_one_load_refuses(self) -> None: + self.write("acme", CLIENT + 'env-file = "~/acme.env"\n') + self.write("misplaced", 'checkout = "~/code/other"\nenv-file = "/srv/other.env"\n') + self.write("broken", "checkout = ") + self.write("none", CLIENT) + self.assertEqual(env_files(self.home), [self.home / "acme.env", pathlib.Path("/srv/other.env")]) + + class ToolTest(ConfigCase): def run_tool(self, *args: str, cwd: pathlib.Path | None = None) -> subprocess.CompletedProcess[str]: return subprocess.run([sys.executable, str(TOOL), *args], cwd=cwd or self.checkout, env={**isolated_env(), "HOME": str(self.home)}, capture_output=True, text=True) diff --git a/bin/rule_hook/env_file.py b/bin/rule_hook/env_file.py index 8dee6803..d0acaf31 100644 --- a/bin/rule_hook/env_file.py +++ b/bin/rule_hook/env_file.py @@ -7,12 +7,12 @@ import os import pathlib import re -from failure import Failure -from rule_hook.call import Call, text -from rule_hook.git import guarded_git from rule_hook.rules import Breach -from command_lines.shell_command import resolved, simple_commands +from rule_hook.call import Call, text from project_config.settings import env_files +from failure import Failure +from rule_hook.git import guarded_git +from command_lines.shell_command import resolved, simple_commands def env_file_breaches(call: Call, home: str) -> list[Breach]: