test_tools.py 818 B

12345678910111213141516171819202122232425262728
  1. import os
  2. import json
  3. def test_user_memory_tool():
  4. from src.agents.helper_agent import UserMemoryTool
  5. tool = UserMemoryTool(memory_file="test_memory.json")
  6. # Test get
  7. res = tool.run({"action": "get"})
  8. assert "beginner" in res or "level" in res
  9. # Test update
  10. res = tool.run({"action": "update", "level": "intermediate", "record": "hello_world"})
  11. assert res == "记忆更新成功"
  12. # Test get again
  13. res = tool.run({"action": "get"})
  14. assert "intermediate" in res
  15. assert "hello_world" in res
  16. # cleanup
  17. file_path = os.path.join(os.path.dirname(__file__), "../../data/test_memory.json")
  18. if os.path.exists(file_path):
  19. os.remove(file_path)
  20. print("UserMemoryTool test passed!")
  21. if __name__ == "__main__":
  22. test_user_memory_tool()