minimall add pytest (#1859)

* minimall add pytest

* updated docs and pytest command

* proveted milvus integration test running if milvus is not installed
This commit is contained in:
0xArty
2023-04-16 21:55:53 +01:00
committed by GitHub
parent 7d9269e1a1
commit 627533bed6
8 changed files with 208 additions and 157 deletions

View File

@@ -1,18 +1,22 @@
"""Unit tests for the commands module"""
from unittest.mock import MagicMock, patch
import pytest
import autogpt.agent.agent_manager as agent_manager
from autogpt.app import start_agent, list_agents, execute_command
import unittest
from unittest.mock import patch, MagicMock
from autogpt.app import execute_command, list_agents, start_agent
class TestCommands(unittest.TestCase):
def test_make_agent(self):
with patch("openai.ChatCompletion.create") as mock:
obj = MagicMock()
obj.response.choices[0].messages[0].content = "Test message"
mock.return_value = obj
start_agent("Test Agent", "chat", "Hello, how are you?", "gpt2")
agents = list_agents()
self.assertEqual("List of agents:\n0: chat", agents)
start_agent("Test Agent 2", "write", "Hello, how are you?", "gpt2")
agents = list_agents()
self.assertEqual("List of agents:\n0: chat\n1: write", agents)
@pytest.mark.integration_test
def test_make_agent() -> None:
"""Test the make_agent command"""
with patch("openai.ChatCompletion.create") as mock:
obj = MagicMock()
obj.response.choices[0].messages[0].content = "Test message"
mock.return_value = obj
start_agent("Test Agent", "chat", "Hello, how are you?", "gpt2")
agents = list_agents()
assert "List of agents:\n0: chat" == agents
start_agent("Test Agent 2", "write", "Hello, how are you?", "gpt2")
agents = list_agents()
assert "List of agents:\n0: chat\n1: write" == agents