Spaces:
Sleeping
Sleeping
| # tests/test_agent_tool_selection_by_log.py | |
| import pytest | |
| from agent.agent import initialize_agent | |
| from unittest.mock import patch, Mock | |
| def agent_executor(): | |
| # Create an agent with a dummy LLM but real logging of tool calls | |
| with patch("streamlit.secrets", {"GOOGLE_API_KEY": "AIzaSyBxrJAxe69t02jMZKtOGXY3gCIgVm8RAMY"}): | |
| with patch("langchain_openai.ChatOpenAI") as mock_llm: | |
| mock_llm.return_value = Mock() | |
| yield initialize_agent() | |
| def test_tool_selected_in_logs(agent_executor, capsys, query, tool_name): | |
| # Run the agent; it will print "Invoking: `tool_name` with ..." | |
| agent_executor({"input": query}) | |
| captured = capsys.readouterr().out | |
| assert f"Invoking: `{tool_name}`" in captured | |