-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 Polish: Refactor CLI status coloring to use constant map #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧹 Polish: Refactor CLI status coloring to use constant map #636
Conversation
- Extracted status-to-color mapping into `_STATUS_COLOR_MAP` in `imednet/cli/utils.py`. - Replaced conditional `if/elif` logic in `_format_cell_value` with dictionary lookup (O(1)). - Added unit tests for status color formatting in `tests/unit/cli/test_utils_output.py`. - Verified no logic changes. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Refactors CLI cell formatting to replace repetitive status-color conditionals with a centralized status→color map, and adds unit tests to validate status coloring behavior.
Changes:
- Introduced
_STATUS_COLOR_MAPconstant for status-to-color mapping and switched_format_cell_valueto a dictionary lookup. - Added unit tests covering status coloring, non-status columns, and unknown statuses.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
imednet/cli/utils.py |
Replaces conditional status coloring logic with a constant lookup map. |
tests/unit/cli/test_utils_output.py |
Adds unit tests asserting status coloring and non-coloring behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import pytest | ||
|
|
||
| from imednet.cli.utils import display_list, fetching_status | ||
| from imednet.cli.utils import _format_cell_value, display_list, fetching_status |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests import and assert against a private helper (_format_cell_value). This couples tests to internal implementation details and makes refactors harder. Prefer testing the behavior via public output (e.g., display_list) or consider promoting the formatter to a public API (dropping the leading underscore) if it’s intended to be stable and directly tested.
| from imednet.cli.utils import _format_cell_value, display_list, fetching_status | |
| from imednet.cli.utils import display_list, fetching_status |
| def test_format_cell_value_status_colors() -> None: | ||
| """Test that status columns are correctly colorized.""" | ||
| # Green statuses | ||
| assert _format_cell_value("Active", key="status") == "[green]Active[/green]" | ||
| assert _format_cell_value("Success", key="state") == "[green]Success[/green]" | ||
| assert _format_cell_value("OK", key="status") == "[green]OK[/green]" | ||
|
|
||
| # Yellow statuses | ||
| assert _format_cell_value("Pending", key="status") == "[yellow]Pending[/yellow]" | ||
| assert _format_cell_value("Processing", key="state") == "[yellow]Processing[/yellow]" | ||
|
|
||
| # Red statuses | ||
| assert _format_cell_value("Inactive", key="status") == "[red]Inactive[/red]" | ||
| assert _format_cell_value("Error", key="state") == "[red]Error[/red]" | ||
| assert _format_cell_value("Failed", key="status") == "[red]Failed[/red]" | ||
|
|
||
|
|
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is a good behavioral check, but it’s repetitive and will be cumbersome to extend as the map grows. Consider converting to pytest.mark.parametrize with a table of (value, key, expected) cases to reduce duplication and make additions/removals more maintainable.
| def test_format_cell_value_status_colors() -> None: | |
| """Test that status columns are correctly colorized.""" | |
| # Green statuses | |
| assert _format_cell_value("Active", key="status") == "[green]Active[/green]" | |
| assert _format_cell_value("Success", key="state") == "[green]Success[/green]" | |
| assert _format_cell_value("OK", key="status") == "[green]OK[/green]" | |
| # Yellow statuses | |
| assert _format_cell_value("Pending", key="status") == "[yellow]Pending[/yellow]" | |
| assert _format_cell_value("Processing", key="state") == "[yellow]Processing[/yellow]" | |
| # Red statuses | |
| assert _format_cell_value("Inactive", key="status") == "[red]Inactive[/red]" | |
| assert _format_cell_value("Error", key="state") == "[red]Error[/red]" | |
| assert _format_cell_value("Failed", key="status") == "[red]Failed[/red]" | |
| @pytest.mark.parametrize( | |
| "value,key,expected", | |
| [ | |
| # Green statuses | |
| ("Active", "status", "[green]Active[/green]"), | |
| ("Success", "state", "[green]Success[/green]"), | |
| ("OK", "status", "[green]OK[/green]"), | |
| # Yellow statuses | |
| ("Pending", "status", "[yellow]Pending[/yellow]"), | |
| ("Processing", "state", "[yellow]Processing[/yellow]"), | |
| # Red statuses | |
| ("Inactive", "status", "[red]Inactive[/red]"), | |
| ("Error", "state", "[red]Error[/red]"), | |
| ("Failed", "status", "[red]Failed[/red]"), | |
| ], | |
| ) | |
| def test_format_cell_value_status_colors(value: str, key: str, expected: str) -> None: | |
| """Test that status columns are correctly colorized.""" | |
| assert _format_cell_value(value, key=key) == expected |
| # Map status strings to Rich colors for O(1) lookup | ||
| _STATUS_COLOR_MAP = { | ||
| # Green (Success/Active) | ||
| "active": "green", | ||
| "success": "green", | ||
| "ok": "green", | ||
| "completed": "green", | ||
| "open": "green", | ||
| "approved": "green", | ||
| "verified": "green", | ||
| # Yellow (Pending/Processing) | ||
| "pending": "yellow", | ||
| "processing": "yellow", | ||
| "suspended": "yellow", | ||
| "hold": "yellow", | ||
| "incomplete": "yellow", | ||
| "initiated": "yellow", | ||
| # Red (Failure/Inactive) | ||
| "inactive": "red", | ||
| "closed": "red", | ||
| "error": "red", | ||
| "fail": "red", | ||
| "failed": "red", | ||
| "rejected": "red", | ||
| "terminated": "red", | ||
| "withdrawn": "red", | ||
| } |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is intended as a constant, consider making the intent explicit and preventing accidental runtime mutation. For example, annotate it as Final (and/or Mapping[str, str]) and/or wrap it in an immutable mapping (e.g., types.MappingProxyType). This improves safety and helps type checkers treat it as a true constant.
💩 Smell: Long function with repetitive
if/elifblocks and magic strings for status colors in_format_cell_value.✨ Polish: Extracted status strings to
_STATUS_COLOR_MAPconstant and used dictionary lookup.📉 Reduction: Replaced 26 lines of conditional logic with a simple lookup.
🛡️ Safety: Verified with full test suite - NO LOGIC CHANGES. Added specific unit tests for status coloring.
PR created automatically by Jules for task 7286232161775436279 started by @fderuiter