async def test_run_piper_tts_error(aiohttp_client):
    """Test how the service handles a non-200 response from the server.

    Expects an ErrorFrame to be returned.
    """

    async def handler(_request):
        # Return an error status for any request
        return web.Response(status=404, text="Not found")

    app = web.Application()
    app.router.add_post("/", handler)
    client = await aiohttp_client(app)
    base_url = str(client.make_url("")).rstrip("/")

    async with aiohttp.ClientSession() as session:
        tts_service = PiperTTSService(base_url=base_url, aiohttp_session=session, sample_rate=24000)

        frames_to_send = [
            TTSSpeakFrame(text="Error case."),
        ]

        expected_down_frames = [TTSStoppedFrame, TTSTextFrame]

        expected_up_frames = [ErrorFrame]

        frames_received = await run_test(
            tts_service,
            frames_to_send=frames_to_send,
            expected_down_frames=expected_down_frames,
            expected_up_frames=expected_up_frames,
        )
        up_frames = frames_received[1]

        assert isinstance(up_frames[0], ErrorFrame), "Must receive an ErrorFrame for 404"
        assert "status: 404" in up_frames[0].error, (
            "ErrorFrame should contain details about the 404"
        )
Test how the service handles a non-200 response from the server.

    Expects an ErrorFrame to be returned.
    
tests/test_piper_tts.py