Skip to content

Conversation

@fderuiter
Copy link
Owner

💩 Smell: Long function with repetitive if/elif blocks and magic strings for status colors in _format_cell_value.
Polish: Extracted status strings to _STATUS_COLOR_MAP constant 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

- 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>
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fderuiter fderuiter marked this pull request as ready for review February 9, 2026 16:54
Copilot AI review requested due to automatic review settings February 9, 2026 16:54
@fderuiter fderuiter merged commit 6c23193 into main Feb 9, 2026
13 checks passed
@fderuiter fderuiter deleted the polish-cli-utils-status-map-7286232161775436279 branch February 9, 2026 16:54
Copy link
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

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_MAP constant for status-to-color mapping and switched _format_cell_value to 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
Copy link

Copilot AI Feb 9, 2026

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.

Suggested change
from imednet.cli.utils import _format_cell_value, display_list, fetching_status
from imednet.cli.utils import display_list, fetching_status

Copilot uses AI. Check for mistakes.
Comment on lines +141 to +157
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]"


Copy link

Copilot AI Feb 9, 2026

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +45
# 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",
}
Copy link

Copilot AI Feb 9, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant