Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

mock uvicorn.run in CLI serve command tests #72

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def test_cli_version(cli_runner: CliRunner) -> None:

def test_serve_default_options(cli_runner: CliRunner, mock_logging: Any) -> None:
"""Test serve command with default options."""
with patch("logging.getLogger") as mock_logger:
with patch("logging.getLogger") as mock_logger, \
patch("uvicorn.run") as mock_run:
logger_instance = mock_logger.return_value
result = cli_runner.invoke(cli, ["serve"])

Expand All @@ -47,11 +48,13 @@ def test_serve_default_options(cli_runner: CliRunner, mock_logging: Any) -> None
"log_format": "JSON",
},
)
mock_run.assert_called_once()


def test_serve_custom_options(cli_runner: CliRunner, mock_logging: Any) -> None:
"""Test serve command with custom options."""
with patch("logging.getLogger") as mock_logger:
with patch("logging.getLogger") as mock_logger, \
patch("uvicorn.run") as mock_run:
logger_instance = mock_logger.return_value
result = cli_runner.invoke(
cli,
Expand Down Expand Up @@ -79,6 +82,7 @@ def test_serve_custom_options(cli_runner: CliRunner, mock_logging: Any) -> None:
"log_format": "TEXT",
},
)
mock_run.assert_called_once()


def test_serve_invalid_port(cli_runner: CliRunner) -> None:
Expand All @@ -103,7 +107,8 @@ def test_serve_with_config_file(
cli_runner: CliRunner, mock_logging: Any, temp_config_file: Path
) -> None:
"""Test serve command with config file."""
with patch("logging.getLogger") as mock_logger:
with patch("logging.getLogger") as mock_logger, \
patch("uvicorn.run") as mock_run:
logger_instance = mock_logger.return_value
result = cli_runner.invoke(cli, ["serve", "--config", str(temp_config_file)])

Expand All @@ -118,6 +123,7 @@ def test_serve_with_config_file(
"log_format": "JSON",
},
)
mock_run.assert_called_once()


def test_serve_with_nonexistent_config_file(cli_runner: CliRunner) -> None:
Expand All @@ -131,7 +137,8 @@ def test_serve_priority_resolution(
cli_runner: CliRunner, mock_logging: Any, temp_config_file: Path, env_vars: Any
) -> None:
"""Test serve command respects configuration priority."""
with patch("logging.getLogger") as mock_logger:
with patch("logging.getLogger") as mock_logger, \
patch("uvicorn.run") as mock_run:
logger_instance = mock_logger.return_value
result = cli_runner.invoke(
cli,
Expand Down Expand Up @@ -161,6 +168,7 @@ def test_serve_priority_resolution(
"log_format": "TEXT",
},
)
mock_run.assert_called_once()


def test_main_function() -> None:
Expand Down
Loading