Skip to content

Commit c9e2655

Browse files
wuliang229copybara-github
authored andcommitted
test: add assert statements in hello_world agent main.py
They will check the states of the agent after each die roll. PiperOrigin-RevId: 769949096
1 parent 416dc6f commit c9e2655

File tree

1 file changed

+10
-0
lines changed
  • contributing/samples/hello_world

1 file changed

+10
-0
lines changed

contributing/samples/hello_world/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,22 @@ async def run_prompt_bytes(session: Session, new_message: str):
7070
if event.content.parts and event.content.parts[0].text:
7171
print(f'** {event.author}: {event.content.parts[0].text}')
7272

73+
async def check_rolls_in_state(rolls_size: int):
74+
session = await runner.session_service.get_session(
75+
app_name=app_name, user_id=user_id_1, session_id=session_11.id
76+
)
77+
assert len(session.state['rolls']) == rolls_size
78+
for roll in session.state['rolls']:
79+
assert roll > 0 and roll <= 100
80+
7381
start_time = time.time()
7482
print('Start time:', start_time)
7583
print('------------------------------------')
7684
await run_prompt(session_11, 'Hi')
7785
await run_prompt(session_11, 'Roll a die with 100 sides')
86+
await check_rolls_in_state(1)
7887
await run_prompt(session_11, 'Roll a die again with 100 sides.')
88+
await check_rolls_in_state(2)
7989
await run_prompt(session_11, 'What numbers did I got?')
8090
await run_prompt_bytes(session_11, 'Hi bytes')
8191
print(

0 commit comments

Comments
 (0)