InMemoryRunner that is tailored for tests, features async run method. app_name is hardcoded as InMemoryRunner in the parent class.
| 211 | |
| 212 | |
| 213 | class TestInMemoryRunner(AfInMemoryRunner): |
| 214 | """InMemoryRunner that is tailored for tests, features async run method. |
| 215 | |
| 216 | app_name is hardcoded as InMemoryRunner in the parent class. |
| 217 | """ |
| 218 | |
| 219 | async def run_async_with_new_session( |
| 220 | self, new_message: types.ContentUnion |
| 221 | ) -> list[Event]: |
| 222 | |
| 223 | collected_events: list[Event] = [] |
| 224 | async for event in self.run_async_with_new_session_agen(new_message): |
| 225 | collected_events.append(event) |
| 226 | |
| 227 | return collected_events |
| 228 | |
| 229 | async def run_async_with_new_session_agen( |
| 230 | self, new_message: types.ContentUnion |
| 231 | ) -> AsyncGenerator[Event, None]: |
| 232 | session = await self.session_service.create_session( |
| 233 | app_name='InMemoryRunner', user_id='test_user' |
| 234 | ) |
| 235 | agen = self.run_async( |
| 236 | user_id=session.user_id, |
| 237 | session_id=session.id, |
| 238 | new_message=get_user_content(new_message), |
| 239 | ) |
| 240 | async with Aclosing(agen): |
| 241 | async for event in agen: |
| 242 | yield event |
| 243 | |
| 244 | |
| 245 | class InMemoryRunner: |
no outgoing calls