From a27fe4bde2ede48187bf7faa3b4e67555720857b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 21 Jan 2025 10:06:14 -0800 Subject: [PATCH] tests: move test_ai_services to test_utils_string --- tests/test_openai_tts.py | 43 ------------------- ...st_ai_services.py => test_utils_string.py} | 27 +----------- 2 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 tests/test_openai_tts.py rename tests/{test_ai_services.py => test_utils_string.py} (64%) diff --git a/tests/test_openai_tts.py b/tests/test_openai_tts.py deleted file mode 100644 index 171542232..000000000 --- a/tests/test_openai_tts.py +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (c) 2024-2025 Daily -# -# SPDX-License-Identifier: BSD 2-Clause License -# - -import asyncio -import unittest - -import openai -import pyaudio -from dotenv import load_dotenv - -from pipecat.frames.frames import AudioRawFrame, ErrorFrame -from pipecat.services.openai import OpenAITTSService - -load_dotenv() - - -class TestWhisperOpenAIService(unittest.IsolatedAsyncioTestCase): - @unittest.skip("FIXME: This test is failing") - async def test_whisper_tts(self): - pa = pyaudio.PyAudio() - stream = pa.open(format=pyaudio.paInt16, channels=1, rate=24_000, output=True) - - tts = OpenAITTSService(voice="nova") - - async for frame in tts.run_tts("Hello, there. Nice to meet you, seems to work well"): - self.assertIsInstance(frame, AudioRawFrame) - stream.write(frame.audio) - - await asyncio.sleep(0.5) - stream.stop_stream() - pa.terminate() - - tts = OpenAITTSService(voice="invalid_voice") - with self.assertRaises(openai.BadRequestError): - async for frame in tts.run_tts("wont work"): - self.assertIsInstance(frame, ErrorFrame) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_ai_services.py b/tests/test_utils_string.py similarity index 64% rename from tests/test_ai_services.py rename to tests/test_utils_string.py index 4b3a28408..9587544a1 100644 --- a/tests/test_ai_services.py +++ b/tests/test_utils_string.py @@ -5,30 +5,11 @@ # import unittest -from typing import AsyncGenerator -from pipecat.frames.frames import EndFrame, Frame, TextFrame -from pipecat.services.ai_services import AIService, match_endofsentence +from pipecat.utils.string import match_endofsentence -class SimpleAIService(AIService): - async def process_frame(self, frame: Frame) -> AsyncGenerator[Frame, None]: - yield frame - - -class TestBaseAIService(unittest.IsolatedAsyncioTestCase): - async def test_simple_processing(self): - service = SimpleAIService() - - input_frames = [TextFrame("hello"), EndFrame()] - - output_frames = [] - for input_frame in input_frames: - async for output_frame in service.process_frame(input_frame): - output_frames.append(output_frame) - - self.assertEqual(input_frames, output_frames) - +class TestUtilsString(unittest.IsolatedAsyncioTestCase): async def test_endofsentence(self): assert match_endofsentence("This is a sentence.") assert match_endofsentence("This is a sentence! ") @@ -57,7 +38,3 @@ class TestBaseAIService(unittest.IsolatedAsyncioTestCase): for i in chinese_sentences: assert match_endofsentence(i) assert not match_endofsentence("你好,") - - -if __name__ == "__main__": - unittest.main()