parent
a679d01995
commit
45c6b116e7
@ -1,63 +0,0 @@
|
||||
import unittest
|
||||
import json
|
||||
import os
|
||||
|
||||
# Assuming the BingChat class is in a file named "bing_chat.py"
|
||||
from bing_chat import BingChat
|
||||
|
||||
|
||||
class TestBingChat(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Path to a mock cookies file for testing
|
||||
self.mock_cookies_path = "./mock_cookies.json"
|
||||
with open(self.mock_cookies_path, "w") as file:
|
||||
json.dump({"mock_cookie": "mock_value"}, file)
|
||||
|
||||
self.chat = BingChat(cookies_path=self.mock_cookies_path)
|
||||
|
||||
def tearDown(self):
|
||||
os.remove(self.mock_cookies_path)
|
||||
|
||||
def test_init(self):
|
||||
self.assertIsInstance(self.chat, BingChat)
|
||||
self.assertIsNotNone(self.chat.bot)
|
||||
|
||||
def test_call(self):
|
||||
# Mocking the asynchronous behavior for the purpose of the test
|
||||
self.chat.bot.ask = lambda *args, **kwargs: {
|
||||
"text": "Hello, Test!"
|
||||
}
|
||||
response = self.chat("Test prompt")
|
||||
self.assertEqual(response, "Hello, Test!")
|
||||
|
||||
def test_create_img(self):
|
||||
# Mocking the ImageGen behavior for the purpose of the test
|
||||
class MockImageGen:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def get_images(self, *args, **kwargs):
|
||||
return [{"path": "mock_image.png"}]
|
||||
|
||||
@staticmethod
|
||||
def save_images(*args, **kwargs):
|
||||
pass
|
||||
|
||||
original_image_gen = BingChat.ImageGen
|
||||
BingChat.ImageGen = MockImageGen
|
||||
|
||||
img_path = self.chat.create_img(
|
||||
"Test prompt", auth_cookie="mock_auth_cookie"
|
||||
)
|
||||
self.assertEqual(img_path, "./output/mock_image.png")
|
||||
|
||||
BingChat.ImageGen = original_image_gen
|
||||
|
||||
def test_set_cookie_dir_path(self):
|
||||
test_path = "./test_path"
|
||||
BingChat.set_cookie_dir_path(test_path)
|
||||
self.assertEqual(BingChat.Cookie.dir_path, test_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,69 +0,0 @@
|
||||
from unittest.mock import patch, MagicMock
|
||||
from swarms.structs.nonlinear_workflow import NonLinearWorkflow, Task
|
||||
|
||||
|
||||
class MockTask(Task):
|
||||
def can_execute(self):
|
||||
return True
|
||||
|
||||
def execute(self):
|
||||
return "Task executed"
|
||||
|
||||
|
||||
def test_nonlinearworkflow_initialization():
|
||||
agents = MagicMock()
|
||||
iters_per_task = MagicMock()
|
||||
workflow = NonLinearWorkflow(agents, iters_per_task)
|
||||
assert isinstance(workflow, NonLinearWorkflow)
|
||||
assert workflow.agents == agents
|
||||
assert workflow.tasks == []
|
||||
|
||||
|
||||
def test_nonlinearworkflow_add():
|
||||
agents = MagicMock()
|
||||
iters_per_task = MagicMock()
|
||||
workflow = NonLinearWorkflow(agents, iters_per_task)
|
||||
task = MockTask("task1")
|
||||
workflow.add(task)
|
||||
assert workflow.tasks == [task]
|
||||
|
||||
|
||||
@patch("your_module.NonLinearWorkflow.is_finished")
|
||||
@patch("your_module.NonLinearWorkflow.output_tasks")
|
||||
def test_nonlinearworkflow_run(mock_output_tasks, mock_is_finished):
|
||||
agents = MagicMock()
|
||||
iters_per_task = MagicMock()
|
||||
workflow = NonLinearWorkflow(agents, iters_per_task)
|
||||
task = MockTask("task1")
|
||||
workflow.add(task)
|
||||
mock_is_finished.return_value = False
|
||||
mock_output_tasks.return_value = [task]
|
||||
workflow.run()
|
||||
assert mock_output_tasks.called
|
||||
|
||||
|
||||
def test_nonlinearworkflow_output_tasks():
|
||||
agents = MagicMock()
|
||||
iters_per_task = MagicMock()
|
||||
workflow = NonLinearWorkflow(agents, iters_per_task)
|
||||
task = MockTask("task1")
|
||||
workflow.add(task)
|
||||
assert workflow.output_tasks() == [task]
|
||||
|
||||
|
||||
def test_nonlinearworkflow_to_graph():
|
||||
agents = MagicMock()
|
||||
iters_per_task = MagicMock()
|
||||
workflow = NonLinearWorkflow(agents, iters_per_task)
|
||||
task = MockTask("task1")
|
||||
workflow.add(task)
|
||||
assert workflow.to_graph() == {"task1": set()}
|
||||
|
||||
|
||||
def test_nonlinearworkflow_order_tasks():
|
||||
agents = MagicMock()
|
||||
iters_per_task = MagicMock()
|
||||
workflow = NonLinearWorkflow(agents, iters_per_task)
|
||||
task = MockTask("task1")
|
||||
workflow.add(task)
|
||||
assert workflow.order_tasks() == [task]
|
@ -1,69 +0,0 @@
|
||||
from unittest.mock import patch, MagicMock
|
||||
from swarms.structs.workflow import Workflow
|
||||
|
||||
|
||||
def test_workflow_initialization():
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
assert isinstance(workflow, Workflow)
|
||||
assert workflow.agent == agent
|
||||
assert workflow.tasks == []
|
||||
assert workflow.parallel is False
|
||||
|
||||
|
||||
def test_workflow_add():
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
task = workflow.add("What's the weather in miami")
|
||||
assert isinstance(task, Workflow.Task)
|
||||
assert task.task == "What's the weather in miami"
|
||||
assert task.parents == []
|
||||
assert task.children == []
|
||||
assert task.output is None
|
||||
assert task.structure == workflow
|
||||
|
||||
|
||||
def test_workflow_first_task():
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
assert workflow.first_task() is None
|
||||
workflow.add("What's the weather in miami")
|
||||
assert workflow.first_task().task == "What's the weather in miami"
|
||||
|
||||
|
||||
def test_workflow_last_task():
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
assert workflow.last_task() is None
|
||||
workflow.add("What's the weather in miami")
|
||||
assert workflow.last_task().task == "What's the weather in miami"
|
||||
|
||||
|
||||
@patch("your_module.Workflow.__run_from_task")
|
||||
def test_workflow_run(mock_run_from_task):
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
workflow.add("What's the weather in miami")
|
||||
workflow.run()
|
||||
mock_run_from_task.assert_called_once()
|
||||
|
||||
|
||||
def test_workflow_context():
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
task = workflow.add("What's the weather in miami")
|
||||
assert workflow.context(task) == {
|
||||
"parent_output": None,
|
||||
"parent": None,
|
||||
"child": None,
|
||||
}
|
||||
|
||||
|
||||
@patch("your_module.Workflow.Task.execute")
|
||||
def test_workflow___run_from_task(mock_execute):
|
||||
agent = MagicMock()
|
||||
workflow = Workflow(agent)
|
||||
task = workflow.add("What's the weather in miami")
|
||||
mock_execute.return_value = "Sunny"
|
||||
workflow.__run_from_task(task)
|
||||
mock_execute.assert_called_once()
|
Loading…
Reference in new issue