[Test Improver] test: add unit tests for utils/console.py (58% → 90%)#351
Draft
danielmeppiel wants to merge 1 commit intomainfrom
Draft
[Test Improver] test: add unit tests for utils/console.py (58% → 90%)#351danielmeppiel wants to merge 1 commit intomainfrom
danielmeppiel wants to merge 1 commit intomainfrom
Conversation
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>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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.pyis 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.pywith 33 focused tests covering:TestStatusSymbolsTestGetConsoleConsole()raises → returnsNone;RICH_AVAILABLE=False→ returnsNoneTestRichEchostyle=backward-compat alias; symbol prepend; unknown symbol ignored; bold flag; colorama fallback (consoleNone); colorama fallback (console raises); bold in colorama; unknown color → default; no-Rich + no-colorama plain fallbackTestRichConvenienceFunctions_rich_success/error/warning/infoall delegate to_rich_echowith correct color;_rich_successusesbold=TrueTestRichPanelconsole.printraises → fallbackTestCreateFilesTableRICH_AVAILABLE=False→None; dict items; list/tuple items; plain string items;Table()raises →None; empty listTestShowDownloadSpinnerNone+ prints message; Rich.status()raises → yieldsNone+ prints messageCoverage Impact
src/apm_cli/utils/console.pyRemaining 10% (lines 15-20, 27-30) are
except ImportErrorblocks executed only when Rich/colorama are absent at import time — unreachable in an environment where both packages are installed.Trade-offs
unittest.mock.patchextensively to simulate missing libraries and exception paths — this is the standard approach for testing optional-dependency fallback logic.Test Status
All 2047 tests pass (33 new + 2014 pre-existing).
Reproducing