Skip to content

Commit

Permalink
add tests for system config dir
Browse files Browse the repository at this point in the history
  • Loading branch information
rettigl committed Jan 20, 2025
1 parent fb71ec3 commit d283e93
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,27 @@ def test_env_var_precedence(mock_env_file, tmp_path, monkeypatch): # noqa: ARG0
# Create local .env directory if it doesn't exist
local_env_dir = tmp_path / "local"
local_env_dir.mkdir(exist_ok=True)
system_env_dir = tmp_path / "system"
system_env_dir.mkdir(exist_ok=True)
monkeypatch.setattr("sed.core.config.ENV_DIR", local_env_dir / ".env")
monkeypatch.setattr("sed.core.config.SYSTEM_CONFIG_PATH", system_env_dir)

# Set up test values in different locations
os.environ["TEST_VAR"] = "os_value"

# Save to user config first (lowest precedence)
# Save to system config first (4th precedence)
with open(system_env_dir / ".env", "w") as f:
f.write("TEST_VAR=system_value\n")

# Save to user config first (3rd precedence)
save_env_var("TEST_VAR", "user_value")

# Create local .env file (medium precedence)
# Create local .env file (2nd precedence)
with open(local_env_dir / ".env", "w") as f:
f.write("TEST_VAR=local_value\n")

assert read_env_var("TEST_VAR") == "os_value"

# Remove from OS env to test other precedence levels
monkeypatch.delenv("TEST_VAR", raising=False)
assert read_env_var("TEST_VAR") == "local_value"
Expand All @@ -305,8 +314,12 @@ def test_env_var_precedence(mock_env_file, tmp_path, monkeypatch): # noqa: ARG0
(local_env_dir / ".env").unlink()
assert read_env_var("TEST_VAR") == "user_value"

# Remove user config and should get None
# Remove user config and should get system value
(mock_env_file / ".env").unlink()
assert read_env_var("TEST_VAR") == "system_value"

# Remove system config and should get None
(system_env_dir / ".env").unlink()
assert read_env_var("TEST_VAR") is None


Expand Down

0 comments on commit d283e93

Please sign in to comment.