mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 20:35:00 +00:00
aider: Added a test function for the check_for_file_mentions
method in tests/test_coder.py
.
# Context: USER: write a test for check_for_file_mentions ASSISTANT: To write a test for the `check_for_file_mentions` method, we will create a new test function in the `tests/test_coder.py` file. Here's the test function: ```python tests/test_coder.py <<<<<<< ORIGINAL ======= import unittest from unittest.mock import MagicMock from aider.coder import Coder class TestCoder(unittest.TestCase): def test_check_for_file_mentions(self): # Mock the IO object mock_io = MagicMock() mock_io.get_input.return_value = "Please check file1.txt and file2.py" mock_io.confirm_ask.return_value = True # Initialize the Coder object with the mocked IO coder = Coder(io=mock_io, openai_api_key="fake_key") # Add sample files to the Coder object coder.abs_fnames = { "/path/to/repo/file1.txt", "/path/to/repo/file2.py", } coder.root = "/path/to/repo" # Call the check_for_file_mentions method result = coder.check_for_file_mentions("Please check file1.txt and file2.py") # Check if the result is as expected self.assertEqual(result, "Added files: file1.txt, file2.py") if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This test function creates a `Coder` object with a mocked IO, adds sample files to the object, and then calls the `check_for_file_mentions` method with a sample input. It checks if the returned result is as expected.
This commit is contained in:
parent
dd3bdfbe15
commit
475f85bcc3
1 changed files with 29 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
|||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
from aider.coder import Coder
|
||||
|
||||
class TestCoder(unittest.TestCase):
|
||||
def test_check_for_file_mentions(self):
|
||||
# Mock the IO object
|
||||
mock_io = MagicMock()
|
||||
mock_io.get_input.return_value = "Please check file1.txt and file2.py"
|
||||
mock_io.confirm_ask.return_value = True
|
||||
|
||||
# Initialize the Coder object with the mocked IO
|
||||
coder = Coder(io=mock_io, openai_api_key="fake_key")
|
||||
|
||||
# Add sample files to the Coder object
|
||||
coder.abs_fnames = {
|
||||
"/path/to/repo/file1.txt",
|
||||
"/path/to/repo/file2.py",
|
||||
}
|
||||
coder.root = "/path/to/repo"
|
||||
|
||||
# Call the check_for_file_mentions method
|
||||
result = coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
||||
|
||||
# Check if the result is as expected
|
||||
self.assertEqual(result, "Added files: file1.txt, file2.py")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue