Skip to content

[Test Improver] test: add unit tests for utils/console.py (58% → 90%)#351

Merged
danielmeppiel merged 1 commit intomainfrom
test-assist/utils-console-coverage-23224050701-6dd7d51eeb83513c
Mar 22, 2026
Merged

[Test Improver] test: add unit tests for utils/console.py (58% → 90%)#351
danielmeppiel merged 1 commit intomainfrom
test-assist/utils-console-coverage-23224050701-6dd7d51eeb83513c

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 This is an automated PR from Test Improver, an AI assistant focused on improving test coverage for this repository.

Goal & Rationale

src/apm_cli/utils/console.py is a shared utility used by nearly every CLI command for all user-facing output (success/error/warning messages, panels, tables, spinners). At 58% coverage, key fallback paths were untested — making it easy for regressions in the Rich/colorama degradation logic to go unnoticed.

Approach

Added tests/unit/test_console_utils.py with 33 focused tests covering:

Class What's tested
TestStatusSymbols Required symbol keys exist; all values are strings
TestGetConsole Normal Rich path; Console() raises → returns None; RICH_AVAILABLE=False → returns None
TestRichEcho Rich path; style= backward-compat alias; symbol prepend; unknown symbol ignored; bold flag; colorama fallback (console None); colorama fallback (console raises); bold in colorama; unknown color → default; no-Rich + no-colorama plain fallback
TestRichConvenienceFunctions _rich_success/error/warning/info all delegate to _rich_echo with correct color; _rich_success uses bold=True
TestRichPanel Rich panel rendered; fallback with title; fallback without title; console.print raises → fallback
TestCreateFilesTable RICH_AVAILABLE=FalseNone; dict items; list/tuple items; plain string items; Table() raises → None; empty list
TestShowDownloadSpinner Rich spinner yields status object; no-Rich yields None + prints message; Rich .status() raises → yields None + prints message

Coverage Impact

File Before After
src/apm_cli/utils/console.py 58% 90% (+32 pp)

Remaining 10% (lines 15-20, 27-30) are except ImportError blocks executed only when Rich/colorama are absent at import time — unreachable in an environment where both packages are installed.

Trade-offs

  • Tests use unittest.mock.patch extensively to simulate missing libraries and exception paths — this is the standard approach for testing optional-dependency fallback logic.
  • No new dependencies added.

Test Status

2047 passed in 12.92s

All 2047 tests pass (33 new + 2014 pre-existing).

Reproducing

uv sync --extra dev
uv run pytest tests/unit/test_console_utils.py -v
uv run pytest tests/unit/ --cov=apm_cli.utils.console --cov-report=term-missing

Generated by Daily Test Improver ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@b87234850bf9664d198f28a02df0f937d0447295

@danielmeppiel danielmeppiel added automation Deprecated: use type/automation. Kept for issue history; will be removed in milestone 0.10.0. testing Deprecated: use area/testing. Kept for issue history; will be removed in milestone 0.10.0. labels Mar 18, 2026
@danielmeppiel danielmeppiel marked this pull request as ready for review March 22, 2026 15:48
Copilot AI review requested due to automatic review settings March 22, 2026 15:48
@danielmeppiel danielmeppiel force-pushed the test-assist/utils-console-coverage-23224050701-6dd7d51eeb83513c branch from b5b3efb to eb0f65c Compare March 22, 2026 15:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the reliability of APM’s user-facing console output utilities by adding focused unit tests for apm_cli.utils.console, especially around Rich/colorama fallback behavior and exception paths.

Changes:

  • Added a new unit test module covering STATUS_SYMBOLS, _get_console, _rich_echo and wrappers, _rich_panel, _create_files_table, and show_download_spinner.
  • Exercised degradation paths when Rich is unavailable or when Rich rendering raises, plus colorama/plain-text fallbacks.

Cover _get_console, _rich_echo (Rich path, style/symbol/bold params,
colorama fallback, plain fallback), _rich_success/error/warning/info,
_rich_panel (Rich path + fallback), _create_files_table (dict/list/
string inputs, no-Rich path, exception path), and show_download_spinner
(Rich, no-Rich, and Rich-exception fallback paths).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Deprecated: use type/automation. Kept for issue history; will be removed in milestone 0.10.0. testing Deprecated: use area/testing. Kept for issue history; will be removed in milestone 0.10.0.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants