Files
manual_slop/tests/test_tool_preset_env.py

38 lines
1.2 KiB
Python

import os
import pytest
from unittest.mock import patch, MagicMock
from src import ai_client
def test_tool_preset_env_loading(monkeypatch):
"""Tests that SLOP_TOOL_PRESET env var triggers set_tool_preset."""
# We need to reload or re-evaluate the logic at the end of ai_client
# Since it runs on import, we can simulate the environment and re-run the check.
with patch("src.ai_client.set_tool_preset") as mock_set_preset:
monkeypatch.setenv("SLOP_TOOL_PRESET", "TestPreset")
# Manually trigger the logic that was added to the end of ai_client.py
if os.environ.get("SLOP_TOOL_PRESET"):
try:
ai_client.set_tool_preset(os.environ["SLOP_TOOL_PRESET"])
except Exception:
pass
mock_set_preset.assert_called_once_with("TestPreset")
def test_tool_preset_env_no_var(monkeypatch):
"""Tests that nothing happens if SLOP_TOOL_PRESET is not set."""
with patch("src.ai_client.set_tool_preset") as mock_set_preset:
monkeypatch.delenv("SLOP_TOOL_PRESET", raising=False)
# Manually trigger the logic
if os.environ.get("SLOP_TOOL_PRESET"):
try:
ai_client.set_tool_preset(os.environ["SLOP_TOOL_PRESET"])
except Exception:
pass
mock_set_preset.assert_not_called()