Files
grm/tests/unit/test_ui.py
T
emil 34742bab40
Post-merge / detect-type (push) Successful in 53s
Post-merge / release (push) Successful in 1m14s
Post-merge / validate-commit-msg (push) Successful in 1m25s
Post-merge / vikunja (push) Successful in 1m21s
Post-merge / badges (push) Successful in 1m45s
Post-merge / configure-repo (push) Successful in 1m15s
Post-merge / sync-wiki (push) Successful in 3m5s
Post-merge / publish (push) Successful in 1m1s
GRM-136: refactor: rename PyPI package from gitea-runner-manager to grm
2026-07-06 06:06:13 +00:00

66 lines
2.2 KiB
Python

"""Unit tests for user-facing output utilities."""
from __future__ import annotations
import logging
from unittest.mock import patch
import pytest
from grm.ui import _console_level, say
class TestConsoleLevel:
def test_default_is_info(self) -> None:
with patch.dict("os.environ", {}, clear=True):
assert _console_level() == logging.INFO
def test_env_override(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("GRM_LOG_LEVEL", "DEBUG")
assert _console_level() == logging.DEBUG
def test_invalid_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("GRM_LOG_LEVEL", "VERBOSE")
assert _console_level() == logging.INFO
class TestSay:
def test_echoes_to_console(self) -> None:
with patch("grm.ui.click.echo") as mock_echo:
say("hello")
mock_echo.assert_called_once_with("hello", err=False)
def test_logs_at_info_level(self) -> None:
with (
patch("grm.ui.click.echo"),
patch("grm.ui.logging.getLogger") as mock_get_logger,
):
mock_logger = mock_get_logger.return_value
say("hello")
mock_logger.log.assert_called_once_with(logging.INFO, "hello")
def test_passes_level_and_err(self) -> None:
with (
patch("grm.ui.click.echo") as mock_echo,
patch("grm.ui.logging.getLogger") as mock_get_logger,
):
mock_logger = mock_get_logger.return_value
say("error msg", level=logging.ERROR, err=True)
mock_echo.assert_called_once_with("error msg", err=True)
mock_logger.log.assert_called_once_with(logging.ERROR, "error msg")
def test_suppresses_console_below_level(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("GRM_LOG_LEVEL", "WARNING")
with (
patch("grm.ui.click.echo") as mock_echo,
patch("grm.ui.logging.getLogger") as mock_get_logger,
):
mock_logger = mock_get_logger.return_value
say("debug msg", level=logging.DEBUG)
mock_echo.assert_not_called()
mock_logger.log.assert_called_once_with(logging.DEBUG, "debug msg")