From 5a90be3ac1c3b6b38a10c162423a506e3999f75d Mon Sep 17 00:00:00 2001 From: vipyne Date: Fri, 22 Nov 2024 16:46:51 -0600 Subject: [PATCH] doctest fix WIP run with pytest --doctest-modules -v src/pipecat/processors/aggregators/user_response.py --- pyproject.toml | 2 ++ src/pipecat/processors/aggregators/user_response.py | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a362f6aad..9e1bd5bbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,8 @@ where = ["src"] [tool.pytest.ini_options] pythonpath = ["src"] +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" [tool.setuptools_scm] local_scheme = "no-local-version" diff --git a/src/pipecat/processors/aggregators/user_response.py b/src/pipecat/processors/aggregators/user_response.py index 903019059..aab5affcd 100644 --- a/src/pipecat/processors/aggregators/user_response.py +++ b/src/pipecat/processors/aggregators/user_response.py @@ -27,15 +27,18 @@ class ResponseAggregator(FrameProcessor): UserStoppedSpeakingFrame() -> TextFrame("Hello world.") Doctest: FIXME to work with asyncio + >>> import asyncio + >>> async def print_frames(aggregator, frame): - ... async for frame in aggregator.process_frame(frame): + ... async for frame in aggregator.process_frame(frame, FrameDirection.DOWNSTREAM): ... if isinstance(frame, TextFrame): ... print(frame.text) + >>> loop = asyncio.new_event_loop() >>> aggregator = ResponseAggregator(start_frame = UserStartedSpeakingFrame, ... end_frame=UserStoppedSpeakingFrame, ... accumulator_frame=TranscriptionFrame, - ... pass_through=False) + ... loop=loop) >>> asyncio.run(print_frames(aggregator, UserStartedSpeakingFrame())) >>> asyncio.run(print_frames(aggregator, TranscriptionFrame("Hello,", 1, 1))) >>> asyncio.run(print_frames(aggregator, TranscriptionFrame("world.", 1, 2))) @@ -51,8 +54,9 @@ def __init__( end_frame, accumulator_frame: TextFrame, interim_accumulator_frame: TextFrame | None = None, + **kwargs, ): - super().__init__() + super().__init__(**kwargs) self._start_frame = start_frame self._end_frame = end_frame