Files
LandPPT/tests/test_lifespan.py
sligter 4d5ed16cc2 feat: Enhance OpenAI integration with responses API and reasoning capabilities
- Added configuration options for using the OpenAI responses API and enabling reasoning in AIConfig.
- Implemented logic to handle responses API and reasoning in the landppt_api and related services.
- Updated the FastAPI application to support new configuration options and adjust request payloads accordingly.
- Enhanced the web interface to allow users to toggle responses API and reasoning settings.
- Added utility functions for extracting response data and usage metrics from OpenAI API responses.
- Introduced a lifespan context manager for managing application startup and shutdown processes.
- Created tests for the lifespan functionality to ensure proper handling of startup and shutdown events.
2026-03-06 23:29:46 +08:00

35 lines
941 B
Python

import asyncio
import os
from pathlib import Path
from unittest.mock import AsyncMock, patch
from dotenv import load_dotenv
import pytest
load_dotenv(Path(__file__).resolve().parents[1] / ".env")
os.environ["DEBUG"] = "false"
from landppt import main as main_module
@pytest.mark.asyncio
async def test_lifespan_swallows_cancelled_error_and_runs_shutdown():
startup = AsyncMock()
shutdown = AsyncMock()
with (
patch.object(main_module, "startup_application", new=startup),
patch.object(main_module, "shutdown_application", new=shutdown),
):
context_manager = main_module.lifespan(main_module.app)
await context_manager.__aenter__()
suppressed = await context_manager.__aexit__(
asyncio.CancelledError,
asyncio.CancelledError(),
None,
)
assert suppressed is True
startup.assert_awaited_once()
shutdown.assert_awaited_once()