fix: Correct test for invalid --edit-format argument

This commit is contained in:
Paul Gauthier (aider) 2025-05-11 08:13:11 -07:00
parent c055602c6f
commit a53ab7d937

View file

@ -950,15 +950,18 @@ class TestMain(TestCase):
def test_invalid_edit_format(self): def test_invalid_edit_format(self):
with GitTemporaryDirectory(): with GitTemporaryDirectory():
with patch("aider.io.InputOutput.offer_url") as mock_offer_url: with patch("aider.io.InputOutput.offer_url") as mock_offer_url:
# Suppress stderr for this test as argparse prints an error message
with patch('sys.stderr', new_callable=StringIO):
result = main( result = main(
["--edit-format", "not-a-real-format", "--exit", "--yes"], ["--edit-format", "not-a-real-format", "--exit", "--yes"],
input=DummyInput(), input=DummyInput(),
output=DummyOutput(), output=DummyOutput(),
) )
self.assertEqual(result, 1) # main() should return 1 on error # main() should return 1 when argparse itself fails due to an invalid choice
mock_offer_url.assert_called_once() # (argparse exits with 2, which main converts to 1)
args, _ = mock_offer_url.call_args self.assertEqual(result, 1)
self.assertEqual(args[0], "https://aider.chat/docs/more/edit-formats.html") # offer_url is not called because argparse handles the error before aider's custom check
mock_offer_url.assert_not_called()
def test_default_model_selection(self): def test_default_model_selection(self):
with GitTemporaryDirectory(): with GitTemporaryDirectory():