Files
AegisGitea-MCP/tests/test_cli.py
T

49 lines
1.5 KiB
Python

"""Tests for the command line skeleton."""
from __future__ import annotations
from pathlib import Path
import pytest
from aegis_gitea_mcp import __version__
from aegis_gitea_mcp.cli import build_parser, main
from tests.test_server_helpers import ANY_HOST
def test_version_prints_package_version(capsys: pytest.CaptureFixture[str]) -> None:
assert main(["version"]) == 0
assert capsys.readouterr().out.strip() == __version__
def test_serve_parses_host_and_port() -> None:
args = build_parser().parse_args(["serve", "--host", ANY_HOST, "--port", "9000"])
assert (args.host, args.port) == (ANY_HOST, 9000)
def test_serve_transport_choices() -> None:
parser = build_parser()
assert parser.parse_args(["serve", "--transport", "stdio"]).transport == "stdio"
with pytest.raises(SystemExit):
parser.parse_args(["serve", "--transport", "sse"])
def test_package_version_matches_pyproject() -> None:
tomllib = pytest.importorskip("tomllib") # Python 3.11+
data = tomllib.loads((Path(__file__).parent.parent / "pyproject.toml").read_text())
assert data["project"]["version"] == __version__
@pytest.mark.parametrize("value", ["0", "65536", "-1", "http", "80.5"])
def test_serve_rejects_bad_ports_with_a_short_message(
value: str, capsys: pytest.CaptureFixture[str]
) -> None:
with pytest.raises(SystemExit) as exit_info:
build_parser().parse_args(["serve", "--port", value])
err = capsys.readouterr().err
assert exit_info.value.code == 2
assert "--port" in err and "65535" in err
assert len(err) < 500