Skip to content

🧪 [testing improvement] Add unit tests for get_category_color in utils/io.py#24

Merged
MnemOnicE merged 2 commits into
mainfrom
jules-11845819729044475212-5d2f92fa
Jun 17, 2026
Merged

🧪 [testing improvement] Add unit tests for get_category_color in utils/io.py#24
MnemOnicE merged 2 commits into
mainfrom
jules-11845819729044475212-5d2f92fa

Conversation

@MnemOnicE

Copy link
Copy Markdown
Owner

🎯 What: Added unit tests for the previously untested get_category_color UI helper function in commando/utils/io.py.

📊 Coverage: The tests cover all conditional branches mapped to specific colors: CYAN (file/disk), MAGENTA (network/web), RED (process/system), GREEN (navigation/search), YELLOW (text/edit), and the fallback return BOLD. The tests also cover mixed-case string matches to ensure correct logic execution.

Result: Test coverage for commando/utils/io.py is improved, providing reliable testing logic that safeguards against regressions when categorizing tags.


PR created automatically by Jules for task 11845819729044475212 started by @MnemOnicE

Co-authored-by: MnemOnicE <170563909+MnemOnicE@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
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.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@MnemOnicE, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 42 minutes and 27 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 78f6ecfd-d7b8-4f8a-9d1e-5ea3e2e22efa

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc49a4 and a06b593.

📒 Files selected for processing (1)
  • tests/test_io.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-11845819729044475212-5d2f92fa

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new test suite in tests/test_io.py to verify the behavior of the get_category_color function across various categories. The reviewer identified a potential issue where tests could produce false positives in non-TTY or CI/CD environments because color constants might default to empty strings. To resolve this, the reviewer suggested mocking the color constants with distinct values during test execution to ensure robust and reliable assertions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tests/test_io.py
Comment on lines +1 to +58
import unittest
from commando.utils.io import (
get_category_color,
CYAN,
MAGENTA,
RED,
GREEN,
YELLOW,
BOLD,
)


class TestGetCategoryColor(unittest.TestCase):
def test_cyan_categories(self):
"""Test categories that should return CYAN color"""
self.assertEqual(get_category_color("File Management"), CYAN)
self.assertEqual(get_category_color("Disk Utilities"), CYAN)
self.assertEqual(get_category_color("file"), CYAN)
self.assertEqual(get_category_color("DISK"), CYAN)

def test_magenta_categories(self):
"""Test categories that should return MAGENTA color"""
self.assertEqual(get_category_color("Network"), MAGENTA)
self.assertEqual(get_category_color("Web Tools"), MAGENTA)
self.assertEqual(get_category_color("network admin"), MAGENTA)
self.assertEqual(get_category_color("WEB"), MAGENTA)

def test_red_categories(self):
"""Test categories that should return RED color"""
self.assertEqual(get_category_color("Process Management"), RED)
self.assertEqual(get_category_color("System Utils"), RED)
self.assertEqual(get_category_color("process"), RED)
self.assertEqual(get_category_color("SYSTEM"), RED)

def test_green_categories(self):
"""Test categories that should return GREEN color"""
self.assertEqual(get_category_color("Navigation"), GREEN)
self.assertEqual(get_category_color("Search Tools"), GREEN)
self.assertEqual(get_category_color("navig"), GREEN)
self.assertEqual(get_category_color("SEARCH"), GREEN)

def test_yellow_categories(self):
"""Test categories that should return YELLOW color"""
self.assertEqual(get_category_color("Text Editors"), YELLOW)
self.assertEqual(get_category_color("Edit"), YELLOW)
self.assertEqual(get_category_color("text processing"), YELLOW)
self.assertEqual(get_category_color("EDIT"), YELLOW)

def test_fallback_categories(self):
"""Test categories that don't match any specific keyword should return BOLD"""
self.assertEqual(get_category_color("Unknown"), BOLD)
self.assertEqual(get_category_color("Misc"), BOLD)
self.assertEqual(get_category_color("Other Utilities"), BOLD)
self.assertEqual(get_category_color(""), BOLD)


if __name__ == "__main__":
unittest.main()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

In non-TTY environments (such as CI/CD pipelines like GitHub Actions) or when NO_COLOR is set, the color constants in commando/utils/io.py are initialized to empty strings ("").

Because of this, importing and asserting against these constants directly in tests can lead to false positives (false greens). For example, if get_category_color has a bug and returns RED instead of CYAN, the assertion self.assertEqual(get_category_color("File Management"), CYAN) will compare "" with "" and pass successfully, masking the bug.

To make the tests robust and reliable in all environments, we should override these color constants with distinct mock values during the test execution.

import unittest
import commando.utils.io as io


class TestGetCategoryColor(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # Save original colors to restore them later
        cls.original_colors = {
            "CYAN": io.CYAN,
            "MAGENTA": io.MAGENTA,
            "RED": io.RED,
            "GREEN": io.GREEN,
            "YELLOW": io.YELLOW,
            "BOLD": io.BOLD,
        }
        # Set distinct mock values to prevent false positives in non-TTY/CI environments
        io.CYAN = "mock_cyan"
        io.MAGENTA = "mock_magenta"
        io.RED = "mock_red"
        io.GREEN = "mock_green"
        io.YELLOW = "mock_yellow"
        io.BOLD = "mock_bold"

    @classmethod
    def tearDownClass(cls):
        # Restore original colors
        io.CYAN = cls.original_colors["CYAN"]
        io.MAGENTA = cls.original_colors["MAGENTA"]
        io.RED = cls.original_colors["RED"]
        io.GREEN = cls.original_colors["GREEN"]
        io.YELLOW = cls.original_colors["YELLOW"]
        io.BOLD = cls.original_colors["BOLD"]

    def test_cyan_categories(self):
        """Test categories that should return CYAN color"""
        self.assertEqual(io.get_category_color("File Management"), io.CYAN)
        self.assertEqual(io.get_category_color("Disk Utilities"), io.CYAN)
        self.assertEqual(io.get_category_color("file"), io.CYAN)
        self.assertEqual(io.get_category_color("DISK"), io.CYAN)

    def test_magenta_categories(self):
        """Test categories that should return MAGENTA color"""
        self.assertEqual(io.get_category_color("Network"), io.MAGENTA)
        self.assertEqual(io.get_category_color("Web Tools"), io.MAGENTA)
        self.assertEqual(io.get_category_color("network admin"), io.MAGENTA)
        self.assertEqual(io.get_category_color("WEB"), io.MAGENTA)

    def test_red_categories(self):
        """Test categories that should return RED color"""
        self.assertEqual(io.get_category_color("Process Management"), io.RED)
        self.assertEqual(io.get_category_color("System Utils"), io.RED)
        self.assertEqual(io.get_category_color("process"), io.RED)
        self.assertEqual(io.get_category_color("SYSTEM"), io.RED)

    def test_green_categories(self):
        """Test categories that should return GREEN color"""
        self.assertEqual(io.get_category_color("Navigation"), io.GREEN)
        self.assertEqual(io.get_category_color("Search Tools"), io.GREEN)
        self.assertEqual(io.get_category_color("navig"), io.GREEN)
        self.assertEqual(io.get_category_color("SEARCH"), io.GREEN)

    def test_yellow_categories(self):
        """Test categories that should return YELLOW color"""
        self.assertEqual(io.get_category_color("Text Editors"), io.YELLOW)
        self.assertEqual(io.get_category_color("Edit"), io.YELLOW)
        self.assertEqual(io.get_category_color("text processing"), io.YELLOW)
        self.assertEqual(io.get_category_color("EDIT"), io.YELLOW)

    def test_fallback_categories(self):
        """Test categories that don't match any specific keyword should return BOLD"""
        self.assertEqual(io.get_category_color("Unknown"), io.BOLD)
        self.assertEqual(io.get_category_color("Misc"), io.BOLD)
        self.assertEqual(io.get_category_color("Other Utilities"), io.BOLD)
        self.assertEqual(io.get_category_color(""), io.BOLD)


if __name__ == "__main__":
    unittest.main()

@MnemOnicE

Copy link
Copy Markdown
Owner Author

@jules tests/test_io.py
Comment on lines +1 to +58
import unittest
from commando.utils.io import (
get_category_color,
CYAN,
MAGENTA,
RED,
GREEN,
YELLOW,
BOLD,
)

class TestGetCategoryColor(unittest.TestCase):
def test_cyan_categories(self):
"""Test categories that should return CYAN color"""
self.assertEqual(get_category_color("File Management"), CYAN)
self.assertEqual(get_category_color("Disk Utilities"), CYAN)
self.assertEqual(get_category_color("file"), CYAN)
self.assertEqual(get_category_color("DISK"), CYAN)

def test_magenta_categories(self):
    """Test categories that should return MAGENTA color"""
    self.assertEqual(get_category_color("Network"), MAGENTA)
    self.assertEqual(get_category_color("Web Tools"), MAGENTA)
    self.assertEqual(get_category_color("network admin"), MAGENTA)
    self.assertEqual(get_category_color("WEB"), MAGENTA)

def test_red_categories(self):
    """Test categories that should return RED color"""
    self.assertEqual(get_category_color("Process Management"), RED)
    self.assertEqual(get_category_color("System Utils"), RED)
    self.assertEqual(get_category_color("process"), RED)
    self.assertEqual(get_category_color("SYSTEM"), RED)

def test_green_categories(self):
    """Test categories that should return GREEN color"""
    self.assertEqual(get_category_color("Navigation"), GREEN)
    self.assertEqual(get_category_color("Search Tools"), GREEN)
    self.assertEqual(get_category_color("navig"), GREEN)
    self.assertEqual(get_category_color("SEARCH"), GREEN)

def test_yellow_categories(self):
    """Test categories that should return YELLOW color"""
    self.assertEqual(get_category_color("Text Editors"), YELLOW)
    self.assertEqual(get_category_color("Edit"), YELLOW)
    self.assertEqual(get_category_color("text processing"), YELLOW)
    self.assertEqual(get_category_color("EDIT"), YELLOW)

def test_fallback_categories(self):
    """Test categories that don't match any specific keyword should return BOLD"""
    self.assertEqual(get_category_color("Unknown"), BOLD)
    self.assertEqual(get_category_color("Misc"), BOLD)
    self.assertEqual(get_category_color("Other Utilities"), BOLD)
    self.assertEqual(get_category_color(""), BOLD)

if name == "main":
unittest.main()

gemini-code-assist Bot
11 minutes ago
Contributor
high

In non-TTY environments (such as CI/CD pipelines like GitHub Actions) or when NO_COLOR is set, the color constants in commando/utils/io.py are initialized to empty strings ("").

Because of this, importing and asserting against these constants directly in tests can lead to false positives (false greens). For example, if get_category_color has a bug and returns RED instead of CYAN, the assertion self.assertEqual(get_category_color("File Management"), CYAN) will compare "" with "" and pass successfully, masking the bug.

To make the tests robust and reliable in all environments, we should override these color constants with distinct mock values during the test execution.

import unittest
import commando.utils.io as io

class TestGetCategoryColor(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Save original colors to restore them later
cls.original_colors = {
"CYAN": io.CYAN,
"MAGENTA": io.MAGENTA,
"RED": io.RED,
"GREEN": io.GREEN,
"YELLOW": io.YELLOW,
"BOLD": io.BOLD,
}
# Set distinct mock values to prevent false positives in non-TTY/CI environments
io.CYAN = "mock_cyan"
io.MAGENTA = "mock_magenta"
io.RED = "mock_red"
io.GREEN = "mock_green"
io.YELLOW = "mock_yellow"
io.BOLD = "mock_bold"

@classmethod
def tearDownClass(cls):
    # Restore original colors
    io.CYAN = cls.original_colors["CYAN"]
    io.MAGENTA = cls.original_colors["MAGENTA"]
    io.RED = cls.original_colors["RED"]
    io.GREEN = cls.original_colors["GREEN"]
    io.YELLOW = cls.original_colors["YELLOW"]
    io.BOLD = cls.original_colors["BOLD"]

def test_cyan_categories(self):
    """Test categories that should return CYAN color"""
    self.assertEqual(io.get_category_color("File Management"), io.CYAN)
    self.assertEqual(io.get_category_color("Disk Utilities"), io.CYAN)
    self.assertEqual(io.get_category_color("file"), io.CYAN)
    self.assertEqual(io.get_category_color("DISK"), io.CYAN)

def test_magenta_categories(self):
    """Test categories that should return MAGENTA color"""
    self.assertEqual(io.get_category_color("Network"), io.MAGENTA)
    self.assertEqual(io.get_category_color("Web Tools"), io.MAGENTA)
    self.assertEqual(io.get_category_color("network admin"), io.MAGENTA)
    self.assertEqual(io.get_category_color("WEB"), io.MAGENTA)

def test_red_categories(self):
    """Test categories that should return RED color"""
    self.assertEqual(io.get_category_color("Process Management"), io.RED)
    self.assertEqual(io.get_category_color("System Utils"), io.RED)
    self.assertEqual(io.get_category_color("process"), io.RED)
    self.assertEqual(io.get_category_color("SYSTEM"), io.RED)

def test_green_categories(self):
    """Test categories that should return GREEN color"""
    self.assertEqual(io.get_category_color("Navigation"), io.GREEN)
    self.assertEqual(io.get_category_color("Search Tools"), io.GREEN)
    self.assertEqual(io.get_category_color("navig"), io.GREEN)
    self.assertEqual(io.get_category_color("SEARCH"), io.GREEN)

def test_yellow_categories(self):
    """Test categories that should return YELLOW color"""
    self.assertEqual(io.get_category_color("Text Editors"), io.YELLOW)
    self.assertEqual(io.get_category_color("Edit"), io.YELLOW)
    self.assertEqual(io.get_category_color("text processing"), io.YELLOW)
    self.assertEqual(io.get_category_color("EDIT"), io.YELLOW)

def test_fallback_categories(self):
    """Test categories that don't match any specific keyword should return BOLD"""
    self.assertEqual(io.get_category_color("Unknown"), io.BOLD)
    self.assertEqual(io.get_category_color("Misc"), io.BOLD)
    self.assertEqual(io.get_category_color("Other Utilities"), io.BOLD)
    self.assertEqual(io.get_category_color(""), io.BOLD)

if name == "main":
unittest.main()

@google-labs-jules

Copy link
Copy Markdown
Contributor

@jules tests/test_io.py
Comment on lines +1 to +58
import unittest
from commando.utils.io import (
get_category_color,
CYAN,
MAGENTA,
RED,
GREEN,
YELLOW,
BOLD,
)

class TestGetCategoryColor(unittest.TestCase):
def test_cyan_categories(self):
"""Test categories that should return CYAN color"""
self.assertEqual(get_category_color("File Management"), CYAN)
self.assertEqual(get_category_color("Disk Utilities"), CYAN)
self.assertEqual(get_category_color("file"), CYAN)
self.assertEqual(get_category_color("DISK"), CYAN)

def test_magenta_categories(self):
    """Test categories that should return MAGENTA color"""
    self.assertEqual(get_category_color("Network"), MAGENTA)
    self.assertEqual(get_category_color("Web Tools"), MAGENTA)
    self.assertEqual(get_category_color("network admin"), MAGENTA)
    self.assertEqual(get_category_color("WEB"), MAGENTA)

def test_red_categories(self):
    """Test categories that should return RED color"""
    self.assertEqual(get_category_color("Process Management"), RED)
    self.assertEqual(get_category_color("System Utils"), RED)
    self.assertEqual(get_category_color("process"), RED)
    self.assertEqual(get_category_color("SYSTEM"), RED)

def test_green_categories(self):
    """Test categories that should return GREEN color"""
    self.assertEqual(get_category_color("Navigation"), GREEN)
    self.assertEqual(get_category_color("Search Tools"), GREEN)
    self.assertEqual(get_category_color("navig"), GREEN)
    self.assertEqual(get_category_color("SEARCH"), GREEN)

def test_yellow_categories(self):
    """Test categories that should return YELLOW color"""
    self.assertEqual(get_category_color("Text Editors"), YELLOW)
    self.assertEqual(get_category_color("Edit"), YELLOW)
    self.assertEqual(get_category_color("text processing"), YELLOW)
    self.assertEqual(get_category_color("EDIT"), YELLOW)

def test_fallback_categories(self):
    """Test categories that don't match any specific keyword should return BOLD"""
    self.assertEqual(get_category_color("Unknown"), BOLD)
    self.assertEqual(get_category_color("Misc"), BOLD)
    self.assertEqual(get_category_color("Other Utilities"), BOLD)
    self.assertEqual(get_category_color(""), BOLD)

if name == "main":
unittest.main()

gemini-code-assist Bot
11 minutes ago
Contributor
high

In non-TTY environments (such as CI/CD pipelines like GitHub Actions) or when NO_COLOR is set, the color constants in commando/utils/io.py are initialized to empty strings ("").

Because of this, importing and asserting against these constants directly in tests can lead to false positives (false greens). For example, if get_category_color has a bug and returns RED instead of CYAN, the assertion self.assertEqual(get_category_color("File Management"), CYAN) will compare "" with "" and pass successfully, masking the bug.

To make the tests robust and reliable in all environments, we should override these color constants with distinct mock values during the test execution.

import unittest
import commando.utils.io as io

class TestGetCategoryColor(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Save original colors to restore them later
cls.original_colors = {
"CYAN": io.CYAN,
"MAGENTA": io.MAGENTA,
"RED": io.RED,
"GREEN": io.GREEN,
"YELLOW": io.YELLOW,
"BOLD": io.BOLD,
}
# Set distinct mock values to prevent false positives in non-TTY/CI environments
io.CYAN = "mock_cyan"
io.MAGENTA = "mock_magenta"
io.RED = "mock_red"
io.GREEN = "mock_green"
io.YELLOW = "mock_yellow"
io.BOLD = "mock_bold"

@classmethod
def tearDownClass(cls):
    # Restore original colors
    io.CYAN = cls.original_colors["CYAN"]
    io.MAGENTA = cls.original_colors["MAGENTA"]
    io.RED = cls.original_colors["RED"]
    io.GREEN = cls.original_colors["GREEN"]
    io.YELLOW = cls.original_colors["YELLOW"]
    io.BOLD = cls.original_colors["BOLD"]

def test_cyan_categories(self):
    """Test categories that should return CYAN color"""
    self.assertEqual(io.get_category_color("File Management"), io.CYAN)
    self.assertEqual(io.get_category_color("Disk Utilities"), io.CYAN)
    self.assertEqual(io.get_category_color("file"), io.CYAN)
    self.assertEqual(io.get_category_color("DISK"), io.CYAN)

def test_magenta_categories(self):
    """Test categories that should return MAGENTA color"""
    self.assertEqual(io.get_category_color("Network"), io.MAGENTA)
    self.assertEqual(io.get_category_color("Web Tools"), io.MAGENTA)
    self.assertEqual(io.get_category_color("network admin"), io.MAGENTA)
    self.assertEqual(io.get_category_color("WEB"), io.MAGENTA)

def test_red_categories(self):
    """Test categories that should return RED color"""
    self.assertEqual(io.get_category_color("Process Management"), io.RED)
    self.assertEqual(io.get_category_color("System Utils"), io.RED)
    self.assertEqual(io.get_category_color("process"), io.RED)
    self.assertEqual(io.get_category_color("SYSTEM"), io.RED)

def test_green_categories(self):
    """Test categories that should return GREEN color"""
    self.assertEqual(io.get_category_color("Navigation"), io.GREEN)
    self.assertEqual(io.get_category_color("Search Tools"), io.GREEN)
    self.assertEqual(io.get_category_color("navig"), io.GREEN)
    self.assertEqual(io.get_category_color("SEARCH"), io.GREEN)

def test_yellow_categories(self):
    """Test categories that should return YELLOW color"""
    self.assertEqual(io.get_category_color("Text Editors"), io.YELLOW)
    self.assertEqual(io.get_category_color("Edit"), io.YELLOW)
    self.assertEqual(io.get_category_color("text processing"), io.YELLOW)
    self.assertEqual(io.get_category_color("EDIT"), io.YELLOW)

def test_fallback_categories(self):
    """Test categories that don't match any specific keyword should return BOLD"""
    self.assertEqual(io.get_category_color("Unknown"), io.BOLD)
    self.assertEqual(io.get_category_color("Misc"), io.BOLD)
    self.assertEqual(io.get_category_color("Other Utilities"), io.BOLD)
    self.assertEqual(io.get_category_color(""), io.BOLD)

if name == "main":
unittest.main()

Good catch! I've updated the tests to mock the color constants during setup to prevent false positives when running in non-TTY/CI environments. I also caught an issue where text processing would evaluate to RED because it matched the process string, so I updated that test case to Text Management to ensure it successfully targets the YELLOW condition.

Co-authored-by: MnemOnicE <170563909+MnemOnicE@users.noreply.github.com>
@MnemOnicE MnemOnicE merged commit 234b84b into main Jun 17, 2026
7 checks passed
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