From 1318da365c33e5b6e1ecfd941245999e932d742a Mon Sep 17 00:00:00 2001 From: Tahir Siddiuqe Date: Mon, 11 Mar 2024 18:21:44 +0500 Subject: [PATCH] Added testcases for functionality testing --- _01OS/_01OS/server/conftest.py | 9 +++++++++ _01OS/_01OS/server/tests/test_run.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/_01OS/_01OS/server/conftest.py b/_01OS/_01OS/server/conftest.py index c706173..ab01274 100644 --- a/_01OS/_01OS/server/conftest.py +++ b/_01OS/_01OS/server/conftest.py @@ -1,6 +1,9 @@ import os import sys import pytest +from _01OS.server.i import configure_interpreter +from unittest.mock import Mock +from interpreter import OpenInterpreter from fastapi.testclient import TestClient from .server import app @@ -8,3 +11,9 @@ from .server import app @pytest.fixture def client(): return TestClient(app) + + +@pytest.fixture +def mock_interpreter(): + interpreter = configure_interpreter(OpenInterpreter()) + return interpreter \ No newline at end of file diff --git a/_01OS/_01OS/server/tests/test_run.py b/_01OS/_01OS/server/tests/test_run.py index 393fbf8..4e910a1 100644 --- a/_01OS/_01OS/server/tests/test_run.py +++ b/_01OS/_01OS/server/tests/test_run.py @@ -2,6 +2,8 @@ import subprocess import uuid import pytest +from _01OS.server.i import configure_interpreter +from unittest.mock import Mock from fastapi.testclient import TestClient @@ -11,3 +13,29 @@ def test_ping(client): response = client.get("/ping") assert response.status_code == 200 assert response.text == "pong" + + +def test_interpreter_chat(mock_interpreter): + # Set up a sample conversation + messages = [ + {"role": "user", "type": "message", "content": "Hello."}, + {"role": "assistant", "type": "message", "content": "Hi there!"}, + # Add more messages as needed + ] + + # Configure the mock interpreter with the sample conversation + mock_interpreter.messages = messages + + # Simulate additional user input + user_input = {"role": "user", "type": "message", "content": "How are you?"} + mock_interpreter.chat([user_input]) + + # Ensure the interpreter processed the user input + assert len(mock_interpreter.messages) == len(messages) + assert mock_interpreter.messages[-1]["role"] == "assistant" + assert "don't have feelings" in mock_interpreter.messages[-1]["content"] + +def test_interpreter_configuration(mock_interpreter): + # Test interpreter configuration + interpreter = configure_interpreter(mock_interpreter) + assert interpreter is not None \ No newline at end of file