From 13ac5f0b603aacb00a665947306ffe4acc8ff722 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 30 Nov 2023 11:38:37 +0100 Subject: [PATCH] Add `--message-file` flag and unit test This commit introduces the `--message-file` flag to the `aider` tool, allowing users to specify a file containing the message to send to GPT. This feature processes the reply and then exits, disabling the chat mode. The implementation includes reading the content of the specified file and using it as the prompt message. Additionally, a unit test has been added to `tests/test_main.py` to ensure the correct functionality of the `--message-file` flag. The test includes necessary mocks to handle non-interactive environments and verifies that the tool behaves as expected when a message file is provided. This enhancement improves the usability of the `aider` tool for users who prefer or require non-interactive execution, such as in scripting or automated workflows. --- tests/test_main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index c02204217..fc363ce5f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -182,6 +182,20 @@ class TestMain(TestCase): _, kwargs = MockCoder.call_args assert kwargs["dirty_commits"] is True + @patch('aider.main.InputOutput.confirm_ask', return_value=True) + def test_message_file_flag(self, mock_confirm): + message_file_content = "This is a test message from a file." + message_file_path = "test_message.txt" + with open(message_file_path, 'w', encoding='utf-8') as message_file: + message_file.write(message_file_content) + + with patch("aider.main.Coder.create") as MockCoder: + MockCoder.return_value.run = MagicMock() + main(["--message-file", message_file_path], input=DummyInput(), output=DummyOutput()) + MockCoder.return_value.run.assert_called_once_with(with_message=message_file_content) + + os.remove(message_file_path) + def test_encodings_arg(self): fname = "foo.py"