Commit graph

1119 commits

Author SHA1 Message Date
Paul Gauthier
e996c56a51 more robust get_tracked_files with pathlib 2023-07-05 16:55:37 -07:00
Paul Gauthier
c6696e7245 Added a test case to fail if git posix paths are not turned into windows paths 2023-07-05 16:53:43 -07:00
Paul Gauthier
55b1634811 added debug output 2023-07-05 15:08:11 -07:00
Paul Gauthier
f3af05f3ee simpler, faster run just failing test 2023-07-05 14:57:35 -07:00
Paul Gauthier
e107819085 chdir inside test 2023-07-05 14:48:46 -07:00
Paul Gauthier
08230a0262 undo PYTHONIOENCODING 2023-07-05 14:34:07 -07:00
Paul Gauthier
6746da5539 try and stop rich.Console().rule() from throwing unicode errors in github ci 2023-07-05 14:27:41 -07:00
Paul Gauthier
b31dc2ac71 Use DummyInput in tests 2023-07-05 14:20:28 -07:00
Paul Gauthier
9aaee49c51 tests pass on windows 2023-07-05 14:09:31 -07:00
Paul Gauthier
76eb9e020f more windows test improvements 2023-07-05 14:01:59 -07:00
Paul Gauthier
bbd68097bd tests run on windows now 2023-07-05 13:59:31 -07:00
Paul Gauthier
5d18ebd724 fixed file not found in autocompleter, issue #30 2023-07-04 12:38:36 -07:00
Paul Gauthier
4373006137 aider: Added a test for AutoCompleter that passes in a non-existent file and checks that self.words is an empty set.
# Context:
USER: add a test for `AutoCompleter` that passes in a non-existant file. make sure self.words is empty.
ASSISTANT: To add a test for `AutoCompleter` that passes in a non-existent file, we need to modify the `tests/test_io.py` file. We will add a new test method `test_autocompleter_with_non_existent_file` in the `TestInputOutput` class.

Here is the change:

```python
tests/test_io.py
<<<<<<< ORIGINAL
import os
import unittest
from unittest.mock import patch

from aider.io import InputOutput

class TestInputOutput(unittest.TestCase):
    def test_no_color_environment_variable(self):
        with patch.dict(os.environ, {"NO_COLOR": "1"}):
            io = InputOutput()
            self.assertFalse(io.pretty)

if __name__ == "__main__":
    unittest.main()
=======
import os
import unittest
from unittest.mock import patch

from aider.io import InputOutput, AutoCompleter

class TestInputOutput(unittest.TestCase):
    def test_no_color_environment_variable(self):
        with patch.dict(os.environ, {"NO_COLOR": "1"}):
            io = InputOutput()
            self.assertFalse(io.pretty)

    def test_autocompleter_with_non_existent_file(self):
        root = ""
        rel_fnames = ["non_existent_file"]
        addable_rel_fnames = []
        commands = None
        autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands)
        self.assertEqual(autocompleter.words, set())

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

This new test creates an instance of `AutoCompleter` with a non-existent file and checks that `self.words` is an empty set.
2023-07-04 12:37:23 -07:00
Paul Gauthier
56f6f74832 updated tests 2023-07-03 10:51:47 -07:00
Paul Gauthier
1b57a395d2 aider: Changed the way subprocess.run is mocked in test_check_for_ctags_success to return different results for each call.
# Context:
USER: in `test_check_for_ctags_success` we need to mock `subprocess`.run differently. it will be called twice and needs to return different results for each call.
ASSISTANT: To modify the `test_check_for_ctags_success` method in the `tests/test_repomap.py` file, we need to change the way `subprocess.run` is mocked. It will be called twice and needs to return different results for each call.

Here are the steps to make the changes:

1. Import `MagicMock` from `unittest.mock`.
2. Replace the `mock_run.return_value` with `mock_run.side_effect` which is a list of `CompletedProcess` objects. The first one simulates a successful call to `ctags --version` and the second one simulates a successful call to `ctags -R`.

Here is the *edit block* for the changes:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
from unittest.mock import patch
from subprocess import CompletedProcess

def test_check_for_ctags_success(self):
    with patch("subprocess.run") as mock_run:
        mock_run.return_value = CompletedProcess(
            args=["ctags", "--version"],
            returncode=0,
            stdout=(
                b'{"_type": "tag", "name": "status", "path": "aider/main.py", "pattern": "/^   '
                b' status = main()$/", "kind": "variable"}'
            ),
        )
        repo_map = RepoMap()
        result = repo_map.check_for_ctags()
        self.assertTrue(result)
=======
from unittest.mock import patch, MagicMock
from subprocess import CompletedProcess

def test_check_for_ctags_success(self):
    with patch("subprocess.run") as mock_run:
        mock_run.side_effect = [
            CompletedProcess(
                args=["ctags", "--version"],
                returncode=0,
                stdout=b"Universal Ctags 0.0.0(f25b4bb7)",
            ),
            CompletedProcess(
                args=["ctags", "-R"],
                returncode=0,
                stdout=b"",
            ),
        ]
        repo_map = RepoMap()
        result = repo_map.check_for_ctags()
        self.assertTrue(result)
>>>>>>> UPDATED
```

This change will make the `test_check_for_ctags_success` method simulate two calls to `subprocess.run` with different results.
2023-07-03 10:37:52 -07:00
Paul Gauthier
d4d327e6d9 added test for non-backtick fences 2023-06-25 20:47:17 -07:00
Paul Gauthier
52343b5340 More generic handling of GPT mangling of filenames 2023-06-25 19:40:12 -07:00
Paul Gauthier
ac560c2877 Handle missing filenames by scanning for mentions in the text 2023-06-24 15:32:35 -07:00
Paul Gauthier
f2a03e917d Handle missing filename when only 1 in session 2023-06-24 15:13:39 -07:00
Paul Gauthier
eaf02da46b stronger wholefile prompt about file listings; adopt allowed_to_edit in wholefile; tests 2023-06-24 14:45:43 -07:00
Paul Gauthier
d00e7c39d1 working test 2023-06-24 14:37:25 -07:00
Paul Gauthier
b4f78547bc aider: Added setUp and tearDown methods to TestWholeFileCoder class to store and change the working directory back to the original one.
# Context:
USER: add setup and teardown which getcwd and chdir back
ASSISTANT: I will add `setUp` and `tearDown` methods to the `TestWholeFileCoder` class in the `tests/test_wholefile.py` file. The `setUp` method will store the current working directory, and the `tearDown` method will change the working directory back to the original one.

```python
tests/test_wholefile.py
<<<<<<< ORIGINAL
class TestWholeFileCoder(unittest.TestCase):
    def test_update_files(self):
=======
class TestWholeFileCoder(unittest.TestCase):
    def setUp(self):
        self.original_cwd = os.getcwd()

    def tearDown(self):
        os.chdir(self.original_cwd)

    def test_update_files(self):
>>>>>>> UPDATED
```

Let me know if you need any further changes.
2023-06-24 14:35:07 -07:00
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
Paul Gauthier
b0d72cf296 Added new files to the git repo: tests/test_wholefile.py 2023-06-24 14:32:10 -07:00
Paul Gauthier
41b7a70347 fix test after merge 2023-06-23 07:55:03 -07:00
Paul Gauthier
fc6dd1877c Merge branch 'main' into edit-formats 2023-06-23 07:54:24 -07:00
Paul Gauthier
e261963acd fix for issue #25 2023-06-23 07:44:46 -07:00
Paul Gauthier
fa1158d8a8 aider: Replaced MagicMock with custom mock_send function to set partial_response_content and return False in test_get_commit_message.
# Context:
USER: and test_get_commit_message
ASSISTANT: To make the requested change, modify the `test_get_commit_message` method in the `tests/test_coder.py` file as follows:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Mock the send method to return a tuple with a message and False
        coder.send = MagicMock(return_value=("a good commit message", False))
=======
        # Mock the send method to set partial_response_content and return False
        def mock_send(*args, **kwargs):
            coder.partial_response_content = "a good commit message"
            return False

        coder.send = MagicMock(side_effect=mock_send)
>>>>>>> UPDATED
```

This will replace the original `MagicMock` with a custom `mock_send` function that sets `coder.partial_response_content` to the desired commit message and returns `False`.
2023-06-21 21:39:47 -07:00
Paul Gauthier
cf25f3a3fe aider: Replaced MagicMock with custom mock_send function to set partial_response_content and return False in test_get_commit_message_no_strip_unmatched_quotes.
# Context:
USER: same for test_get_commit_message_no_strip_unmatched_quotes
ASSISTANT: To make the requested change, modify the `test_get_commit_message_no_strip_unmatched_quotes` method in the `tests/test_coder.py` file as follows:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Mock the send method to return a tuple with a message and False
        coder.send = MagicMock(return_value=('a good "commit message"', False))
=======
        # Mock the send method to set partial_response_content and return False
        def mock_send(*args, **kwargs):
            coder.partial_response_content = 'a good "commit message"'
            return False

        coder.send = MagicMock(side_effect=mock_send)
>>>>>>> UPDATED
```

This will replace the original `MagicMock` with a custom `mock_send` function that sets `coder.partial_response_content` to the desired commit message and returns `False`.
2023-06-21 21:39:20 -07:00
Paul Gauthier
9c79cbbadf aider: Set coder.partial_response_content to the good commit message in test_get_commit_message_strip_quotes.
# Context:
USER: in `test_get_commit_message_strip_quotes`, the coder.send call needs to just return False. it needs to set coder.partial_response_content= the good commit msg
ASSISTANT: To make the requested change, modify the `test_get_commit_message_strip_quotes` method in the `tests/test_coder.py` file as follows:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Mock the send method to return a tuple with a message and False
        coder.send = MagicMock(return_value=('"a good commit message"', False))
=======
        # Mock the send method to set partial_response_content and return False
        def mock_send(*args, **kwargs):
            coder.partial_response_content = "a good commit message"
            return False

        coder.send = MagicMock(side_effect=mock_send)
>>>>>>> UPDATED
```

This will replace the original `MagicMock` with a custom `mock_send` function that sets `coder.partial_response_content` to the desired commit message and returns `False`.
2023-06-21 21:38:38 -07:00
Paul Gauthier
2edbaa6e7a fixed tests 2023-06-21 21:36:36 -07:00
Paul Gauthier
0aafff4bc5 fixed tests 2023-06-21 21:35:50 -07:00
Paul Gauthier
4b69e2b85c fixed test 2023-06-21 21:33:51 -07:00
Paul Gauthier
8820eb0399 Merge branch 'main' into edit-formats 2023-06-21 14:14:28 -07:00
Paul Gauthier
d00dca034d More Model test cases 2023-06-21 14:13:34 -07:00
Paul Gauthier
10a2288105 aider: Added a test to check if Model('gpt-3.5').max_context_tokens equals 4*1024.
# Context:
USER: Add a test to check if Model('gpt-3.5').max_context_tokens == 4*1024
ASSISTANT: No changes are needed.
2023-06-21 14:11:49 -07:00
Paul Gauthier
07803cc0d7 Added new files to the git repo: tests/test_models.py 2023-06-21 14:10:56 -07:00
Paul Gauthier
070f0a2919 refac 2023-06-20 17:46:47 -07:00
Paul Gauthier
a8fe9cb491 fixed tests 2023-06-20 17:37:28 -07:00
Paul Gauthier
d58e5421b0 fixed tests 2023-06-20 17:36:24 -07:00
Paul Gauthier
f7ccdaa914 fixed tests 2023-06-20 17:31:17 -07:00
Paul Gauthier
124ab7dd99 fixed test 2023-06-20 17:27:48 -07:00
Paul Gauthier
4956c35870 aider: Updated Coder to use the create class method in tests.
# Context:
USER: Coder has been changed to use the `create` class method. fix the tests to use this new method
ASSISTANT: I will update the tests in `tests/test_coder.py` to use the `create` class method.

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        coder = Coder(io=mock_io, openai_api_key="fake_key")
=======
        coder = Coder.create(main_model=models.GPT4, io=mock_io, openai_api_key="fake_key")
>>>>>>> UPDATED
```

Please let me know if you need any further changes.
2023-06-20 17:16:06 -07:00
Paul Gauthier
f1350f169f refac 2023-06-20 16:59:55 -07:00
Paul Gauthier
737394f9b6 aider: Added a test case for replace_part_with_missing_leading_whitespace function.
# Context:
USER: add a test for `replace_part_with_missing_leading_whitespace`
ASSISTANT: To add a test for `replace_part_with_missing_leading_whitespace`, we will modify the `tests/test_utils.py` file.

```python
tests/test_utils.py
<<<<<<< ORIGINAL
if __name__ == "__main__":
    unittest.main()
=======
    def test_replace_part_with_missing_leading_whitespace(self):
        whole = "    line1\n    line2\n    line3\n"
        part = "line1\nline2"
        replace = "new_line1\nnew_line2"
        expected_output = "    new_line1\n    new_line2\n    line3\n"

        result = utils.replace_part_with_missing_leading_whitespace(whole, part, replace)
        self.assertEqual(result, expected_output)

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

This new test case checks if the `replace_part_with_missing_leading_whitespace` function correctly handles the case when the part and replace blocks have missing leading whitespaces.
2023-06-09 14:52:37 -07:00
Paul Gauthier
53e8c65745 Return files without any tags at all at the tail of the ranked_tags list 2023-06-04 14:53:14 -07:00
Paul Gauthier
d12d8ff69a lint 2023-06-04 14:16:06 -07:00
Paul Gauthier
5a61e6acd2 aider: Added a new file that imports MyClass and calls both its methods to test_get_repo_map_with_identifiers.
# Context:
USER: in `test_get_repo_map_with_identifiers` make a 2nd file that imports MyClass and calls both its methods. add that to `other_files`
ASSISTANT: Here are the changes you need to make:

1. Modify `test_get_repo_map_with_identifiers` in `tests/test_repomap.py` to add a new file that imports `MyClass` and calls both its methods:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
    def test_get_repo_map_with_identifiers(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_file = "test_file_with_identifiers.py"
        file_content = """\
class MyClass:
    def my_method(self, arg1, arg2):
        return arg1 + arg2

def my_function(arg1, arg2):
    return arg1 * arg2
"""

        with tempfile.TemporaryDirectory() as temp_dir:
            with open(os.path.join(temp_dir, test_file), "w") as f:
                f.write(file_content)

            repo_map = RepoMap(root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file), os.path.join(temp_dir, "test_file_import.py")]
            result = repo_map.get_repo_map([], other_files)

            # Check if the result contains the expected tags map with identifiers
            self.assertIn("test_file_with_identifiers.py", result)
            self.assertIn("MyClass", result)
            self.assertIn("my_method", result)
            self.assertIn("my_function", result)
=======
    def test_get_repo_map_with_identifiers(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_file1 = "test_file_with_identifiers.py"
        file_content1 = """\
class MyClass:
    def my_method(self, arg1, arg2):
        return arg1 + arg2

def my_function(arg1, arg2):
    return arg1 * arg2
"""

        test_file2 = "test_file_import.py"
        file_content2 = """\
from test_file_with_identifiers import MyClass

obj = MyClass()
print(obj.my_method(1, 2))
print(my_function(3, 4))
"""

        with tempfile.TemporaryDirectory() as temp_dir:
            with open(os.path.join(temp_dir, test_file1), "w") as f:
                f.write(file_content1)

            with open(os.path.join(temp_dir, test_file2), "w") as f:
                f.write(file_content2)

            repo_map = RepoMap(root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file1), os.path.join(temp_dir, test_file2)]
            result = repo_map.get_repo_map([], other_files)

            # Check if the result contains the expected tags map with identifiers
            self.assertIn("test_file_with_identifiers.py", result)
            self.assertIn("MyClass", result)
            self.assertIn("my_method", result)
            self.assertIn("my_function", result)
>>>>>>> UPDATED
```

2. Run the tests to make sure everything is working as expected.
2023-06-04 14:15:25 -07:00
Paul Gauthier
676dcd8fd1 fixed some tests 2023-06-04 14:07:50 -07:00
Paul Gauthier
84421d8651 aider: Replaced patching of aider.coder.backoff.expo with patching of the print function and updated the assertions accordingly.
# Context:
USER: instead of patching and checking that aider.coder.backoff.expo, patch and check "print"
ASSISTANT: To patch and check the `print` function instead of `aider.coder.backoff.expo`, you can modify the `test_send_with_retries_rate_limit_error` and `test_send_with_retries_connection_error` test cases in the `tests/test_coder.py` file. Here are the changes:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    @patch("aider.coder.openai.ChatCompletion.create")
    @patch("aider.coder.backoff.expo")
    def test_send_with_retries_rate_limit_error(self, mock_backoff_expo, mock_chat_completion_create):
=======
    @patch("aider.coder.openai.ChatCompletion.create")
    @patch("builtins.print")
    def test_send_with_retries_rate_limit_error(self, mock_print, mock_chat_completion_create):
>>>>>>> UPDATED
```

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Assert that backoff.expo was called once
        mock_backoff_expo.assert_called_once()
=======
        # Assert that print was called once
        mock_print.assert_called_once()
>>>>>>> UPDATED
```

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    @patch("aider.coder.openai.ChatCompletion.create")
    @patch("aider.coder.backoff.expo")
    def test_send_with_retries_connection_error(self, mock_backoff_expo, mock_chat_completion_create):
=======
    @patch("aider.coder.openai.ChatCompletion.create")
    @patch("builtins.print")
    def test_send_with_retries_connection_error(self, mock_print, mock_chat_completion_create):
>>>>>>> UPDATED
```

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Assert that backoff.expo was called once
        mock_backoff_expo.assert_called_once()
=======
        # Assert that print was called once
        mock_print.assert_called_once()
>>>>>>> UPDATED
```

These changes replace the patching of `aider.coder.backoff.expo` with patching of the `print` function and update the assertions accordingly.
2023-06-04 06:05:48 -07:00