You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/tests/structs/test_nonlinear_workflow.py

51 lines
1.7 KiB

import pytest
11 months ago
from swarms.models import OpenAIChat
11 months ago
from swarms.structs import NonlinearWorkflow, Task
class TestNonlinearWorkflow:
def test_add_task(self):
llm = OpenAIChat(openai_api_key="")
task = Task(llm, "What's the weather in miami")
workflow = NonlinearWorkflow()
workflow.add(task)
assert task.name in workflow.tasks
assert task.name in workflow.edges
def test_run_without_tasks(self):
workflow = NonlinearWorkflow()
# No exception should be raised
workflow.run()
def test_run_with_single_task(self):
llm = OpenAIChat(openai_api_key="")
task = Task(llm, "What's the weather in miami")
workflow = NonlinearWorkflow()
workflow.add(task)
# No exception should be raised
workflow.run()
def test_run_with_circular_dependency(self):
llm = OpenAIChat(openai_api_key="")
task1 = Task(llm, "What's the weather in miami")
task2 = Task(llm, "What's the weather in new york")
workflow = NonlinearWorkflow()
workflow.add(task1, task2.name)
workflow.add(task2, task1.name)
with pytest.raises(
Exception, match="Circular dependency detected"
):
workflow.run()
def test_run_with_stopping_token(self):
llm = OpenAIChat(openai_api_key="")
task1 = Task(llm, "What's the weather in miami")
task2 = Task(llm, "What's the weather in new york")
workflow = NonlinearWorkflow(stopping_token="stop")
workflow.add(task1)
workflow.add(task2)
# Assuming that task1's execute method returns "stop"
# No exception should be raised
workflow.run()