Coverage for tests / unit / cli / test_cli_commands_more.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Unit tests exercising subcommand wiring for CLI commands.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any 

6 

7import pytest 

8from assertpy import assert_that 

9from click.testing import CliRunner 

10 

11from lintro.cli_utils.commands.check import check_command 

12from lintro.cli_utils.commands.format import format_command 

13from lintro.cli_utils.commands.list_tools import list_tools_command 

14 

15 

16def test_check_invokes_executor(monkeypatch: pytest.MonkeyPatch) -> None: 

17 """Invoke check subcommand and verify executor receives parameters. 

18 

19 Args: 

20 monkeypatch: Pytest monkeypatch fixture to stub executor call. 

21 """ 

22 calls: dict[str, Any] = {} 

23 import lintro.cli_utils.commands.check as check_mod 

24 

25 def fake_run(**kwargs: Any) -> int: 

26 calls.update(kwargs) 

27 return 0 

28 

29 monkeypatch.setattr(check_mod, "run_lint_tools_simple", lambda **k: fake_run(**k)) 

30 runner = CliRunner() 

31 result = runner.invoke(check_command, ["--tools", "ruff", "."]) 

32 assert_that(result.exit_code).is_equal_to(0) 

33 assert_that(calls.get("action")).is_equal_to("check") 

34 

35 

36def test_format_invokes_executor(monkeypatch: pytest.MonkeyPatch) -> None: 

37 """Invoke format subcommand and verify executor receives parameters. 

38 

39 Args: 

40 monkeypatch: Pytest monkeypatch fixture to stub executor call. 

41 """ 

42 calls: dict[str, Any] = {} 

43 import lintro.cli_utils.commands.format as format_mod 

44 

45 def fake_run(**kwargs: Any) -> int: 

46 calls.update(kwargs) 

47 return 0 

48 

49 monkeypatch.setattr(format_mod, "run_lint_tools_simple", lambda **k: fake_run(**k)) 

50 runner = CliRunner() 

51 result = runner.invoke(format_command, ["--tools", "prettier", "."]) 

52 assert_that(result.exit_code).is_equal_to(0) 

53 assert_that(calls.get("action")).is_equal_to("fmt") 

54 

55 

56def test_list_tools_outputs(monkeypatch: pytest.MonkeyPatch) -> None: 

57 """Run list-tools command and validate expected text in output. 

58 

59 Args: 

60 monkeypatch: Pytest monkeypatch fixture (not used). 

61 """ 

62 runner = CliRunner() 

63 result = runner.invoke(list_tools_command, []) 

64 assert_that(result.exit_code).is_equal_to(0) 

65 assert_that(result.output).contains("Available Tools") 

66 # Rich table format uses "Total tools" without trailing colon 

67 assert_that(result.output).contains("Total tools")