Coverage for tests / unit / logging / test_console_logger_more.py: 100%
41 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Additional tests for console_logger small branches."""
3from __future__ import annotations
5from pathlib import Path
7import pytest
8from assertpy import assert_that
10from lintro.enums.action import Action
11from lintro.utils.console import create_logger, get_tool_emoji
14def test_get_tool_emoji_default() -> None:
15 """Return a default emoji for unknown tools and non-empty string."""
16 # Unknown tool should return the default emoji
17 emoji = get_tool_emoji("unknown-tool")
18 assert_that(emoji).is_not_empty()
19 # Known tools return specific emojis, default is different character set
20 assert_that(emoji).is_not_equal_to("")
23def test_console_logger_parsing_messages(
24 tmp_path: Path,
25 capsys: pytest.CaptureFixture[str],
26) -> None:
27 """Parse typical messages and print a concise summary.
29 Args:
30 tmp_path: Temporary directory for artifacts.
31 capsys: Pytest capture fixture.
32 """
33 logger = create_logger(run_dir=tmp_path, verbose=False, raw_output=False)
34 raw = (
35 "Fixed 1 issue(s)\n"
36 "Found 2 issue(s) that cannot be auto-fixed\n"
37 "Would reformat: a.py"
38 )
39 logger.print_tool_result(
40 tool_name="ruff",
41 output="formatted table",
42 issues_count=2,
43 raw_output_for_meta=raw,
44 action=Action.CHECK,
45 )
46 out = capsys.readouterr().out
47 assert_that(
48 "auto-fixed" in out or "Would reformat" in out or "Found" in out,
49 ).is_true()
52def test_get_tool_emoji_pytest() -> None:
53 """Test that pytest tool has the test emoji."""
54 emoji_pytest = get_tool_emoji("pytest")
55 # Should return test emoji
56 assert_that(emoji_pytest).is_not_empty()
57 # Should be the test emoji
58 assert_that(emoji_pytest).is_equal_to("🧪")
61def test_console_logger_pytest_result_no_issues(
62 tmp_path: Path,
63 capsys: pytest.CaptureFixture[str],
64) -> None:
65 """Test print_tool_result for pytest with no issues.
67 Args:
68 tmp_path: Temporary directory for artifacts.
69 capsys: Pytest capture fixture.
70 """
71 logger = create_logger(run_dir=tmp_path, verbose=False, raw_output=False)
72 logger.print_tool_result(
73 tool_name="pytest",
74 output="All tests passed",
75 issues_count=0,
76 action=Action.TEST,
77 success=True,
78 )
79 out = capsys.readouterr().out
80 # Should display test results section
81 assert_that(out).contains("Test Results")
84def test_console_logger_pytest_result_with_failures(
85 tmp_path: Path,
86 capsys: pytest.CaptureFixture[str],
87) -> None:
88 """Test print_tool_result for pytest with failures.
90 Args:
91 tmp_path: Temporary directory for artifacts.
92 capsys: Pytest capture fixture.
93 """
94 logger = create_logger(run_dir=tmp_path, verbose=False, raw_output=False)
95 logger.print_tool_result(
96 tool_name="pytest",
97 output="2 tests failed",
98 issues_count=2,
99 action=Action.TEST,
100 success=False,
101 )
102 out = capsys.readouterr().out
103 # Should display test results
104 assert_that(out).contains("Test Results")
107def test_console_logger_pytest_success_message(
108 tmp_path: Path,
109 capsys: pytest.CaptureFixture[str],
110) -> None:
111 """Test success message for pytest results.
113 Args:
114 tmp_path: Temporary directory for artifacts.
115 capsys: Pytest capture fixture.
116 """
117 logger = create_logger(run_dir=tmp_path, verbose=False, raw_output=False)
118 logger.success(message="All tests passed!")
119 out = capsys.readouterr().out
120 assert_that(out).contains("All tests passed!")
123def test_console_logger_print_tool_header_pytest(
124 tmp_path: Path,
125 capsys: pytest.CaptureFixture[str],
126) -> None:
127 """Test print_tool_header for pytest.
129 Args:
130 tmp_path: Temporary directory for artifacts.
131 capsys: Pytest capture fixture.
132 """
133 logger = create_logger(run_dir=tmp_path, verbose=False, raw_output=False)
134 logger.print_tool_header(tool_name="pytest", action="test")
135 out = capsys.readouterr().out
136 # Should include the pytest tool name and action
137 assert_that(out).contains("pytest")
138 assert_that(out).contains("test")