test: add UnknownEditFormat exception tests

This commit is contained in:
Paul Gauthier (aider) 2024-11-26 07:04:15 -08:00
parent cd79f7f4b0
commit e3efab7fbf

View file

@ -879,6 +879,27 @@ This command will print 'Hello, World!' to the console."""
self.assertEqual(result, [])
coder.commands.scraper.scrape.assert_not_called()
def test_unknown_edit_format_exception(self):
# Test the exception message format
invalid_format = "invalid_format"
valid_formats = ["diff", "whole", "map"]
exc = UnknownEditFormat(invalid_format, valid_formats)
expected_msg = f"Unknown edit format {invalid_format}. Valid formats are: {', '.join(valid_formats)}"
self.assertEqual(str(exc), expected_msg)
def test_unknown_edit_format_creation(self):
# Test that creating a Coder with invalid edit format raises the exception
io = InputOutput(yes=True)
invalid_format = "invalid_format"
with self.assertRaises(UnknownEditFormat) as cm:
Coder.create(self.GPT35, invalid_format, io=io)
exc = cm.exception
self.assertEqual(exc.edit_format, invalid_format)
self.assertIsInstance(exc.valid_formats, list)
self.assertTrue(len(exc.valid_formats) > 0)
def test_coder_create_with_new_file_oserror(self):
with GitTemporaryDirectory():
io = InputOutput(yes=True)