free-claude-code/tests/test_server_module.py
Cursor Agent 1cface7f8c Fix all ty check errors without using type: ignore
- messaging/telegram.py: Remove unused type: ignore, fix retry_after typing
  with isinstance(timedelta), use local app variable for None narrowing
- messaging/tree_data.py: Replace _queue._queue access with drain-and-restore
  approach for get_queue_snapshot (avoids private API)
- tests/test_api.py: Use APIError instead of RuntimeError for status_code test
- tests/test_config.py: Use cast(Any, ...) for invalid validation tests
- tests/test_dependencies.py: Add isinstance check for NvidiaNimProvider
- tests/test_handler_markdown_and_status_edges.py: Use patch.object for
  tree_queue method mocks
- tests/test_response_models.py: Add isinstance narrowing for content blocks,
  use Literal list for stop_reason parametrization
- tests/test_restart_reply_restore.py: Use patch.object for enqueue mock
- tests/test_server_module.py: Use patch.object for uvicorn.run and
  get_settings
- tests/test_telegram_edge_cases.py: Use patch.object for method mocks
- tests/test_tree_concurrency.py: Add None assertions for get_node/get_tree

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:28:33 +00:00

32 lines
1.1 KiB
Python

def test_server_module_exports_app_and_create_app():
import server
assert server.app is not None
assert callable(server.create_app)
def test_server_main_invokes_uvicorn_run(monkeypatch):
import runpy
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import config.settings as settings_mod
import uvicorn as uvicorn_mod
# Patch settings used by server.__main__ block.
old_get_settings = settings_mod.get_settings
mock_settings = SimpleNamespace(host="127.0.0.1", port=9999)
try:
with (
patch.object(settings_mod, "get_settings", lambda: mock_settings),
patch.object(uvicorn_mod, "run") as mock_run,
):
runpy.run_module("server", run_name="__main__")
mock_run.assert_called_once()
call_kwargs = mock_run.call_args[1]
assert call_kwargs["host"] == "127.0.0.1"
assert call_kwargs["port"] == 9999
assert call_kwargs["log_level"] == "debug"
finally:
settings_mod.get_settings = old_get_settings