aider/tests
Paul Gauthier b4a92e312a aider: Added a test function to test the WholeFileCoder's update_files method.
# Context:
USER: make a test for `WholeFileCoder`.updated_files
ASSISTANT: To create a test for the `WholeFileCoder`'s `update_files` method, we will add a new test function in the `tests/test_wholefile.py` file. Here's the test function:

```python
tests/test_wholefile.py
<<<<<<< ORIGINAL

=======
import os
from pathlib import Path
import tempfile
import unittest

from aider.coders.wholefile_coder import WholeFileCoder
from aider.io import InputOutput

class TestWholeFileCoder(unittest.TestCase):
    def test_update_files(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            # Create a sample file in the temporary directory
            sample_file = os.path.join(temp_dir, "sample.txt")
            with open(sample_file, "w") as f:
                f.write("Original content\n")

            # Initialize WholeFileCoder with the temporary directory
            io = InputOutput()
            coder = WholeFileCoder(root=temp_dir, io=io)

            # Set the partial response content with the updated content
            coder.partial_response_content = f"{sample_file}\n```\nUpdated content\n```"

            # Call update_files method
            edited_files = coder.update_files()

            # Check if the sample file was updated
            self.assertIn("sample.txt", edited_files)

            # Check if the content of the sample file was updated
            with open(sample_file, "r") as f:
                updated_content = f.read()
            self.assertEqual(updated_content, "Updated content\n")

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This test function creates a temporary directory with a sample file, initializes a `WholeFileCoder` instance with the temporary directory, sets the partial response content with the updated content, calls the `update_files` method, and checks if the sample file was updated correctly.
2023-06-24 14:33:20 -07:00
..
__init__.py aider: Added empty __init__.py file to tests directory to fix ModuleNotFoundError when running tests. 2023-05-11 17:12:42 -07:00
test_coder.py aider: Replaced MagicMock with custom mock_send function to set partial_response_content and return False in test_get_commit_message. 2023-06-21 21:39:47 -07:00
test_commands.py fixed test 2023-06-21 21:33:51 -07:00
test_editblock.py fix test after merge 2023-06-23 07:55:03 -07:00
test_io.py isort 2023-05-28 22:47:38 -07:00
test_main.py refac 2023-06-20 17:46:47 -07:00
test_models.py More Model test cases 2023-06-21 14:13:34 -07:00
test_repomap.py Return files without any tags at all at the tail of the ranked_tags list 2023-06-04 14:53:14 -07:00
test_wholefile.py aider: Added a test function to test the WholeFileCoder's update_files method. 2023-06-24 14:33:20 -07:00