Skip to content

Commit bf80c22

Browse files
More tests!
1 parent 5c29a6f commit bf80c22

8 files changed

+358
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.workflows.agent_lifecycle_workflow import (
9+
AgentLifecycleWorkflow,
10+
)
11+
12+
13+
async def test_execute_workflow(client: Client):
14+
task_queue_name = str(uuid.uuid4())
15+
16+
async with Worker(
17+
client,
18+
task_queue=task_queue_name,
19+
workflows=[AgentLifecycleWorkflow],
20+
activity_executor=ThreadPoolExecutor(5),
21+
# No external activities needed - workflow uses function tools
22+
):
23+
result = await client.execute_workflow(
24+
AgentLifecycleWorkflow.run,
25+
10, # max_number parameter
26+
id=str(uuid.uuid4()),
27+
task_queue=task_queue_name,
28+
)
29+
30+
# Verify the result has the expected structure
31+
assert hasattr(result, "number")
32+
assert isinstance(result.number, int)
33+
assert (
34+
0 <= result.number <= 20
35+
) # Should be between 0 and max*2 due to multiply operation
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.workflows.dynamic_system_prompt_workflow import (
9+
DynamicSystemPromptWorkflow,
10+
)
11+
12+
13+
async def test_execute_workflow_with_random_style(client: Client):
14+
task_queue_name = str(uuid.uuid4())
15+
16+
async with Worker(
17+
client,
18+
task_queue=task_queue_name,
19+
workflows=[DynamicSystemPromptWorkflow],
20+
activity_executor=ThreadPoolExecutor(5),
21+
# No external activities needed
22+
):
23+
result = await client.execute_workflow(
24+
DynamicSystemPromptWorkflow.run,
25+
"Tell me about the weather today.",
26+
id=str(uuid.uuid4()),
27+
task_queue=task_queue_name,
28+
)
29+
30+
# Verify the result has the expected format
31+
assert "Style:" in result
32+
assert "Response:" in result
33+
assert any(style in result for style in ["haiku", "pirate", "robot"])
34+
35+
36+
async def test_execute_workflow_with_specific_style(client: Client):
37+
task_queue_name = str(uuid.uuid4())
38+
39+
async with Worker(
40+
client,
41+
task_queue=task_queue_name,
42+
workflows=[DynamicSystemPromptWorkflow],
43+
activity_executor=ThreadPoolExecutor(5),
44+
# No external activities needed
45+
):
46+
result = await client.execute_workflow(
47+
DynamicSystemPromptWorkflow.run,
48+
args=["Tell me about the weather today.", "haiku"],
49+
id=str(uuid.uuid4()),
50+
task_queue=task_queue_name,
51+
)
52+
53+
# Verify the result has the expected format and style
54+
assert "Style: haiku" in result
55+
assert "Response:" in result
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.workflows.lifecycle_workflow import LifecycleWorkflow
9+
10+
11+
async def test_execute_workflow(client: Client):
12+
task_queue_name = str(uuid.uuid4())
13+
14+
async with Worker(
15+
client,
16+
task_queue=task_queue_name,
17+
workflows=[LifecycleWorkflow],
18+
activity_executor=ThreadPoolExecutor(5),
19+
# No external activities needed - workflow uses function tools
20+
):
21+
result = await client.execute_workflow(
22+
LifecycleWorkflow.run,
23+
10, # max_number parameter
24+
id=str(uuid.uuid4()),
25+
task_queue=task_queue_name,
26+
)
27+
28+
# Verify the result has the expected structure
29+
assert hasattr(result, "number")
30+
assert isinstance(result.number, int)
31+
assert (
32+
0 <= result.number <= 20
33+
) # Should be between 0 and max*2 due to multiply operation
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.activities.image_activities import read_image_as_base64
9+
from openai_agents.basic.workflows.local_image_workflow import LocalImageWorkflow
10+
11+
12+
async def test_execute_workflow_default_question(client: Client):
13+
task_queue_name = str(uuid.uuid4())
14+
15+
async with Worker(
16+
client,
17+
task_queue=task_queue_name,
18+
workflows=[LocalImageWorkflow],
19+
activity_executor=ThreadPoolExecutor(5),
20+
activities=[read_image_as_base64],
21+
):
22+
result = await client.execute_workflow(
23+
LocalImageWorkflow.run,
24+
"openai_agents/basic/media/image_bison.jpg", # Path to test image
25+
id=str(uuid.uuid4()),
26+
task_queue=task_queue_name,
27+
)
28+
29+
# Verify the result is a string response
30+
assert isinstance(result, str)
31+
assert len(result) > 0
32+
33+
34+
async def test_execute_workflow_custom_question(client: Client):
35+
task_queue_name = str(uuid.uuid4())
36+
37+
async with Worker(
38+
client,
39+
task_queue=task_queue_name,
40+
workflows=[LocalImageWorkflow],
41+
activity_executor=ThreadPoolExecutor(5),
42+
activities=[read_image_as_base64],
43+
):
44+
custom_question = "What animals do you see in this image?"
45+
result = await client.execute_workflow(
46+
LocalImageWorkflow.run,
47+
args=["openai_agents/basic/media/image_bison.jpg", custom_question],
48+
id=str(uuid.uuid4()),
49+
task_queue=task_queue_name,
50+
)
51+
52+
# Verify the result is a string response
53+
assert isinstance(result, str)
54+
assert len(result) > 0
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.workflows.non_strict_output_workflow import (
9+
NonStrictOutputWorkflow,
10+
)
11+
12+
13+
async def test_execute_workflow(client: Client):
14+
task_queue_name = str(uuid.uuid4())
15+
16+
async with Worker(
17+
client,
18+
task_queue=task_queue_name,
19+
workflows=[NonStrictOutputWorkflow],
20+
activity_executor=ThreadPoolExecutor(5),
21+
# No external activities needed
22+
):
23+
result = await client.execute_workflow(
24+
NonStrictOutputWorkflow.run,
25+
"Tell me 3 funny jokes about programming.",
26+
id=str(uuid.uuid4()),
27+
task_queue=task_queue_name,
28+
)
29+
30+
# Verify the result has the expected structure
31+
assert isinstance(result, dict)
32+
33+
# Should have either strict_result or strict_error
34+
assert "strict_result" in result or "strict_error" in result
35+
36+
# Should have either non_strict_result or non_strict_error
37+
assert "non_strict_result" in result or "non_strict_error" in result
38+
39+
# If there's a strict_error, it should be a string
40+
if "strict_error" in result:
41+
assert isinstance(result["strict_error"], str)
42+
assert len(result["strict_error"]) > 0
43+
44+
# If there's a non_strict_result, verify it's valid
45+
if "non_strict_result" in result:
46+
assert result["non_strict_result"] is not None
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.workflows.previous_response_id_workflow import (
9+
PreviousResponseIdWorkflow,
10+
)
11+
12+
13+
async def test_execute_workflow(client: Client):
14+
task_queue_name = str(uuid.uuid4())
15+
16+
async with Worker(
17+
client,
18+
task_queue=task_queue_name,
19+
workflows=[PreviousResponseIdWorkflow],
20+
activity_executor=ThreadPoolExecutor(5),
21+
# No external activities needed
22+
):
23+
first_question = "What is the capital of France?"
24+
follow_up_question = "What is the population of that city?"
25+
26+
result = await client.execute_workflow(
27+
PreviousResponseIdWorkflow.run,
28+
args=[first_question, follow_up_question],
29+
id=str(uuid.uuid4()),
30+
task_queue=task_queue_name,
31+
)
32+
33+
# Verify the result is a tuple with two string responses
34+
assert isinstance(result, tuple)
35+
assert len(result) == 2
36+
37+
first_response, second_response = result
38+
assert isinstance(first_response, str)
39+
assert isinstance(second_response, str)
40+
assert len(first_response) > 0
41+
assert len(second_response) > 0
42+
43+
# The responses should be different (not identical)
44+
assert first_response != second_response
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.workflows.remote_image_workflow import RemoteImageWorkflow
9+
10+
# TODO(@donald-pinckney): debug this test
11+
# async def test_execute_workflow_default_question(client: Client):
12+
# task_queue_name = str(uuid.uuid4())
13+
14+
# async with Worker(
15+
# client,
16+
# task_queue=task_queue_name,
17+
# workflows=[RemoteImageWorkflow],
18+
# activity_executor=ThreadPoolExecutor(5),
19+
# # No external activities needed - uses remote URL directly
20+
# ):
21+
# # Using a reliable test image URL
22+
# test_image_url = "https://httpbin.org/image/jpeg"
23+
24+
# result = await client.execute_workflow(
25+
# RemoteImageWorkflow.run,
26+
# test_image_url,
27+
# id=str(uuid.uuid4()),
28+
# task_queue=task_queue_name,
29+
# )
30+
31+
# # Verify the result is a string response
32+
# assert isinstance(result, str)
33+
# assert len(result) > 0
34+
35+
36+
# TODO(@donald-pinckney): debug this test
37+
# async def test_execute_workflow_custom_question(client: Client):
38+
# task_queue_name = str(uuid.uuid4())
39+
40+
# async with Worker(
41+
# client,
42+
# task_queue=task_queue_name,
43+
# workflows=[RemoteImageWorkflow],
44+
# activity_executor=ThreadPoolExecutor(5),
45+
# # No external activities needed - uses remote URL directly
46+
# ):
47+
# # Using a reliable test image URL
48+
# test_image_url = "https://httpbin.org/image/png"
49+
# custom_question = "What do you see in this image?"
50+
51+
# result = await client.execute_workflow(
52+
# RemoteImageWorkflow.run,
53+
# args=[test_image_url, custom_question],
54+
# id=str(uuid.uuid4()),
55+
# task_queue=task_queue_name,
56+
# )
57+
58+
# # Verify the result is a string response
59+
# assert isinstance(result, str)
60+
# assert len(result) > 0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import uuid
2+
from concurrent.futures import ThreadPoolExecutor
3+
4+
import pytest
5+
from temporalio.client import Client
6+
from temporalio.worker import Worker
7+
8+
from openai_agents.basic.activities.get_weather_activity import get_weather
9+
from openai_agents.basic.workflows.tools_workflow import ToolsWorkflow
10+
11+
12+
async def test_execute_workflow(client: Client):
13+
task_queue_name = str(uuid.uuid4())
14+
15+
async with Worker(
16+
client,
17+
task_queue=task_queue_name,
18+
workflows=[ToolsWorkflow],
19+
activity_executor=ThreadPoolExecutor(5),
20+
activities=[get_weather],
21+
):
22+
result = await client.execute_workflow(
23+
ToolsWorkflow.run,
24+
"What's the weather like in New York?",
25+
id=str(uuid.uuid4()),
26+
task_queue=task_queue_name,
27+
)
28+
29+
# Verify the result is a string response
30+
assert isinstance(result, str)
31+
assert len(result) > 0

0 commit comments

Comments
 (0)