diff --git a/tests/basic/test_io.py b/tests/basic/test_io.py index 3f313219d..93befabec 100644 --- a/tests/basic/test_io.py +++ b/tests/basic/test_io.py @@ -33,6 +33,43 @@ class TestInputOutput(unittest.TestCase): with patch.dict(os.environ, {"NO_COLOR": "1"}): io = InputOutput(fancy_input=False) self.assertFalse(io.pretty) + + def test_color_initialization(self): + """Test that color values are properly initialized with # prefix""" + # Test with hex colors without # + io = InputOutput( + user_input_color="00cc00", + tool_error_color="FF2222", + tool_warning_color="FFA500", + assistant_output_color="0088ff", + pretty=True + ) + + # Check that # was added to hex colors + self.assertEqual(io.user_input_color, "#00cc00") + self.assertEqual(io.tool_error_color, "#FF2222") + self.assertEqual(io.tool_warning_color, "#FFA500") # Already had # + self.assertEqual(io.assistant_output_color, "#0088ff") + + # Test with named colors (should be unchanged) + io = InputOutput( + user_input_color="blue", + tool_error_color="red", + pretty=True + ) + + self.assertEqual(io.user_input_color, "blue") + self.assertEqual(io.tool_error_color, "red") + + # Test with pretty=False (should not modify colors) + io = InputOutput( + user_input_color="00cc00", + tool_error_color="FF2222", + pretty=False + ) + + self.assertIsNone(io.user_input_color) + self.assertIsNone(io.tool_error_color) def test_dumb_terminal(self): with patch.dict(os.environ, {"TERM": "dumb"}): @@ -392,6 +429,31 @@ class TestInputOutputMultilineMode(unittest.TestCase): # Test prompt_ask() io.prompt_ask("Test prompt?") self.assertTrue(io.multiline_mode) # Should be restored + + def test_ensure_hash_prefix(self): + """Test that ensure_hash_prefix correctly adds # to valid hex colors""" + from aider.io import ensure_hash_prefix + + # Test valid hex colors without # + self.assertEqual(ensure_hash_prefix("000"), "#000") + self.assertEqual(ensure_hash_prefix("fff"), "#fff") + self.assertEqual(ensure_hash_prefix("F00"), "#F00") + self.assertEqual(ensure_hash_prefix("123456"), "#123456") + self.assertEqual(ensure_hash_prefix("abcdef"), "#abcdef") + self.assertEqual(ensure_hash_prefix("ABCDEF"), "#ABCDEF") + + # Test hex colors that already have # + self.assertEqual(ensure_hash_prefix("#000"), "#000") + self.assertEqual(ensure_hash_prefix("#123456"), "#123456") + + # Test invalid inputs (should return unchanged) + self.assertEqual(ensure_hash_prefix(""), "") + self.assertEqual(ensure_hash_prefix(None), None) + self.assertEqual(ensure_hash_prefix("red"), "red") # Named color + self.assertEqual(ensure_hash_prefix("12345"), "12345") # Wrong length + self.assertEqual(ensure_hash_prefix("1234567"), "1234567") # Wrong length + self.assertEqual(ensure_hash_prefix("xyz"), "xyz") # Invalid hex chars + self.assertEqual(ensure_hash_prefix("12345g"), "12345g") # Invalid hex chars if __name__ == "__main__":