style: Format test_deprecated.py with black

This commit is contained in:
Paul Gauthier (aider) 2025-03-08 13:42:21 -08:00
parent 5447483da2
commit 9e668cda7f

View file

@ -5,8 +5,8 @@ from unittest.mock import MagicMock, patch
from prompt_toolkit.input import DummyInput from prompt_toolkit.input import DummyInput
from prompt_toolkit.output import DummyOutput from prompt_toolkit.output import DummyOutput
from aider.main import main
from aider.deprecated import handle_deprecated_model_args from aider.deprecated import handle_deprecated_model_args
from aider.main import main
class TestDeprecated(TestCase): class TestDeprecated(TestCase):
@ -24,31 +24,33 @@ class TestDeprecated(TestCase):
def test_deprecated_args_show_warnings(self, mock_tool_warning): def test_deprecated_args_show_warnings(self, mock_tool_warning):
# Test all deprecated flags to ensure they show warnings # Test all deprecated flags to ensure they show warnings
deprecated_flags = [ deprecated_flags = [
"--opus", "--opus",
"--sonnet", "--sonnet",
"--haiku", "--haiku",
"--4", "--4",
"--4o", "--4o",
"--mini", "--mini",
"--4-turbo", "--4-turbo",
"--3", "--3",
"--deepseek", "--deepseek",
"--o1-mini", "--o1-mini",
"--o1-preview" "--o1-preview",
] ]
for flag in deprecated_flags: for flag in deprecated_flags:
mock_tool_warning.reset_mock() mock_tool_warning.reset_mock()
with patch("aider.models.Model"), self.subTest(flag=flag): with patch("aider.models.Model"), self.subTest(flag=flag):
main([flag, "--no-git", "--exit", "--yes"], input=DummyInput(), output=DummyOutput()) main(
[flag, "--no-git", "--exit", "--yes"], input=DummyInput(), output=DummyOutput()
)
mock_tool_warning.assert_called_once() mock_tool_warning.assert_called_once()
warning_msg = mock_tool_warning.call_args[0][0] warning_msg = mock_tool_warning.call_args[0][0]
# Remove any leading hyphens for the comparison # Remove any leading hyphens for the comparison
flag_in_msg = flag.lstrip('-') flag_in_msg = flag.lstrip("-")
self.assertIn(flag_in_msg, warning_msg) self.assertIn(flag_in_msg, warning_msg)
self.assertIn("deprecated", warning_msg) self.assertIn("deprecated", warning_msg)
self.assertIn("use --model", warning_msg.lower()) self.assertIn("use --model", warning_msg.lower())
@ -58,8 +60,10 @@ class TestDeprecated(TestCase):
# Test that the warning uses the model alias if available # Test that the warning uses the model alias if available
with patch("aider.models.MODEL_ALIASES", {"gpt4": "gpt-4-0613"}): with patch("aider.models.MODEL_ALIASES", {"gpt4": "gpt-4-0613"}):
with patch("aider.models.Model"): with patch("aider.models.Model"):
main(["--4", "--no-git", "--exit", "--yes"], input=DummyInput(), output=DummyOutput()) main(
["--4", "--no-git", "--exit", "--yes"], input=DummyInput(), output=DummyOutput()
)
mock_tool_warning.assert_called_once() mock_tool_warning.assert_called_once()
warning_msg = mock_tool_warning.call_args[0][0] warning_msg = mock_tool_warning.call_args[0][0]
self.assertIn("--model gpt4", warning_msg) self.assertIn("--model gpt4", warning_msg)
@ -79,19 +83,19 @@ class TestDeprecated(TestCase):
("o1_mini", "o1-mini"), ("o1_mini", "o1-mini"),
("o1_preview", "o1-preview"), ("o1_preview", "o1-preview"),
] ]
for flag, expected_model in test_cases: for flag, expected_model in test_cases:
with self.subTest(flag=flag): with self.subTest(flag=flag):
# Create a mock IO instance # Create a mock IO instance
mock_io = MagicMock() mock_io = MagicMock()
# Create args with the flag set to True # Create args with the flag set to True
args = MagicMock() args = MagicMock()
args.model = None args.model = None
setattr(args, flag, True) setattr(args, flag, True)
# Call the handle_deprecated_model_args function # Call the handle_deprecated_model_args function
handle_deprecated_model_args(args, mock_io) handle_deprecated_model_args(args, mock_io)
# Check that args.model was set to the expected model # Check that args.model was set to the expected model
self.assertEqual(args.model, expected_model) self.assertEqual(args.model, expected_model)