Files
noteflow/tests/cli/test_main.py
Travis Vasceannie d8090a98e8
Some checks failed
CI / test-typescript (push) Has been cancelled
CI / test-rust (push) Has been cancelled
CI / test-python (push) Has been cancelled
ci/cd fixes
2026-01-26 00:28:15 +00:00

111 lines
4.4 KiB
Python

"""Tests for CLI main entry point."""
from __future__ import annotations
from unittest.mock import MagicMock
import pytest
from noteflow.cli.__main__ import (
dispatch_command,
main,
run_models_command,
run_retention_command,
show_help,
)
class TestShowHelp:
def test_show_help_calls_console_print(self, mock_cli_console: MagicMock) -> None:
show_help()
assert mock_cli_console.print.call_count > 0, "Help should print multiple lines"
class TestDispatchCommand:
def test_dispatch_retention_command_returns_true(self, mock_retention_main: MagicMock) -> None:
assert mock_retention_main is not None, "Retention handler fixture should be provided"
result = dispatch_command("retention", ["status"])
assert result is True, "Known command should return True"
def test_dispatch_retention_command_calls_handler(self, mock_retention_main: MagicMock) -> None:
dispatch_command("retention", ["status"])
mock_retention_main.assert_called_once()
def test_dispatch_models_command_returns_true(self, mock_models_main: MagicMock) -> None:
assert mock_models_main is not None, "Models handler fixture should be provided"
result = dispatch_command("models", ["list"])
assert result is True, "Known command should return True"
def test_dispatch_models_command_calls_handler(self, mock_models_main: MagicMock) -> None:
dispatch_command("models", ["list"])
mock_models_main.assert_called_once()
def test_dispatch_unknown_command_returns_false(self) -> None:
result = dispatch_command("unknown_command", [])
assert result is False, "Unknown command should return False"
def test_dispatch_empty_command_returns_false(self) -> None:
result = dispatch_command("", [])
assert result is False, "Empty command should return False"
def test_dispatch_command_propagates_exception(
self, mock_retention_main_error: MagicMock
) -> None:
assert mock_retention_main_error is not None, "Retention error fixture should be provided"
with pytest.raises(RuntimeError, match="Test error"):
dispatch_command("retention", [])
class TestRunRetentionCommand:
def test_run_retention_calls_main(self, mock_retention_main: MagicMock) -> None:
run_retention_command("retention")
mock_retention_main.assert_called_once()
class TestRunModelsCommand:
def test_run_models_calls_main(self, mock_models_main: MagicMock) -> None:
run_models_command("models")
mock_models_main.assert_called_once()
class TestMain:
def test_main_no_args_exits_with_code_1(
self, argv_no_args: None, mock_cli_console: MagicMock
) -> None:
assert argv_no_args is None, "argv_no_args fixture should provide None"
assert mock_cli_console is not None, "Console fixture should be provided"
with pytest.raises(SystemExit, match="1") as exc_info:
main()
assert exc_info.value.code == 1, "Should exit with code 1"
def test_main_unknown_command_exits_with_code_1(
self, argv_unknown_command: None, mock_cli_console: MagicMock
) -> None:
assert argv_unknown_command is None, "argv_unknown_command fixture should provide None"
assert mock_cli_console is not None, "Console fixture should be provided"
with pytest.raises(SystemExit, match="1") as exc_info:
main()
assert exc_info.value.code == 1, "Should exit with code 1"
def test_main_unknown_command_prints_error(
self, argv_unknown_command: None, mock_cli_console: MagicMock
) -> None:
assert argv_unknown_command is None, "argv_unknown_command fixture should provide None"
with pytest.raises(SystemExit, match="1"):
main()
assert mock_cli_console.print.call_count > 0, "Should print error"
def test_main_retention_command_dispatches(
self, argv_retention_status: None, mock_retention_main: MagicMock
) -> None:
assert argv_retention_status is None, "argv_retention_status fixture should provide None"
main()
mock_retention_main.assert_called_once()
def test_main_models_command_dispatches(
self, argv_models_list: None, mock_models_main: MagicMock
) -> None:
assert argv_models_list is None, "argv_models_list fixture should provide None"
main()
mock_models_main.assert_called_once()