Commit graph

422 commits

Author SHA1 Message Date
Paul Gauthier (aider)
d5a258356b Mocked the aider.scraper.Scraper.scrape method in the test_cmd_web_imports_playwright test. 2024-07-16 11:14:29 +01:00
Paul Gauthier
d41f07b024 Refactored the test_cmd_web_imports_playwright test to capture stdout and assert that the example.com content was scraped. 2024-07-16 11:12:59 +01:00
Paul Gauthier (aider)
74f4bd106a Implemented a test for the cmd_scrape command that ensures playwright can be imported after running cmd_web. 2024-07-16 11:11:17 +01:00
Paul Gauthier (aider)
3e7663e914 Added a test for the cmd_web command to ensure that playwright can be imported after running the command. 2024-07-16 11:08:33 +01:00
Paul Gauthier
b18dbf4772 renamed hf-embed -> help 2024-07-16 11:03:01 +01:00
Paul Gauthier (aider)
bd8143a880 Added test for running main with --browser --yes flags 2024-07-16 10:53:27 +01:00
Paul Gauthier
7f38bb49c2 test pip install on /help directory 2024-07-16 10:50:26 +01:00
Paul Gauthier
896e79bcd1 use pytest.ini testpaths to order testing 2024-07-16 10:33:42 +01:00
Paul Gauthier
0860e7b30d do not package tests/ 2024-07-15 08:40:32 +01:00
Paul Gauthier
ce46ea8d62 moved tests/ to aider/tests/ 2024-06-10 15:33:49 -07:00
Paul Gauthier
2d55d532be aider: Add test to ensure all URLs return a 200 status code.
# Aider chat conversation:

USER: write a test that makes sure all the urls are 200

ASSISTANT: Here is the test to ensure all the URLs return a 200 status code:

tests/test_urls.py
```python
<<<<<<< SEARCH
=======
import requests
from aider import urls

def test_urls():
    url_attributes = [attr for attr in dir(urls) if not callable(getattr(urls, attr)) and not attr.startswith("__")]
    for attr in url_attributes:
        url = getattr(urls, attr)
        response = requests.get(url)
        assert response.status_code == 200, f"URL {url} returned status code {response.status_code}"
>>>>>>> REPLACE
```
2024-06-08 12:55:13 -07:00
Paul Gauthier
a57dd90a49 fix unicode err 2024-05-23 15:02:31 -07:00
Paul Gauthier
cb4384edc7 aider: Set the environment variable PYTHONIOENCODING to utf-8 in the test to prevent UnicodeEncodeError.
# Aider chat conversation:

USER: I am getting this testing error on Windows: ======================================================================
ERROR: test_get_input_is_a_directory_error (test_io.TestInputOutput.test_get_input_is_a_directory_error)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\unittest\mock.py", line 1390, in patched
    return func(*newargs, **newkeywargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\a\aider\aider\tests\test_io.py", line 60, in test_get_input_is_a_directory_error
    result = io.get_input(root, rel_fnames, addable_rel_fnames, commands)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\a\aider\aider\aider\io.py", line 186, in get_input
    self.console.rule(**style)
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\console.py", line 1580, in rule
    self.print(rule)
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\console.py", line 1673, in print
    with self:
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\console.py", line 865, in __exit__
    self._exit_buffer()
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\console.py", line 823, in _exit_buffer
    self._check_buffer()
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\console.py", line 2027, in _check_buffer
    legacy_windows_render(buffer, LegacyWindowsTerm(self.file))
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\_windows_renderer.py", line 17, in legacy_windows_render
    term.write_styled(text, style)
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\_win32_console.py", line 442, in write_styled
    self.write_text(text)
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\site-packages\rich\_win32_console.py", line 403, in write_text
    self.write(text)
  File "C:\hostedtoolcache\windows\Python\3.12.3\x64\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-78: character maps to <undefined>

ASSISTANT: The error you're encountering is due to the `charmap` codec on Windows not being able to encode certain Unicode characters. To fix this, we can set the environment variable `PYTHONIOENCODING` to `utf-8` in the test to ensure that the console output uses UTF-8 encoding.

Let's update the test to set this environment variable:

tests/test_io.py
```python
<<<<<<< SEARCH
        # Mock the PromptSession to simulate user input
=======
        # Set the environment variable to ensure UTF-8 encoding
        os.environ["PYTHONIOENCODING"] = "utf-8"

        # Mock the PromptSession to simulate user input
>>>>>>> REPLACE
```

This change will ensure that the console output uses UTF-8 encoding, which should prevent the `UnicodeEncodeError` from occurring.
2024-05-23 14:21:13 -07:00
Paul Gauthier
670f78a874 aider: Added a test case for the get_input method in the InputOutput class.
# Aider chat conversation:

USER: add a test case for this

ASSISTANT: To add a test case for the `get_input` method in the `InputOutput` class, we need to create a new test file. Let's create a new file named `test_io.py` in the `tests` directory and add the necessary test case.

Here is the *SEARCH/REPLACE* block to create the new test file:

tests/test_io.py
```python
<<<<<<< SEARCH
=======
import unittest
from unittest.mock import patch, MagicMock
from aider.io import InputOutput

class TestInputOutput(unittest.TestCase):
    @patch('aider.io.PromptSession')
    def test_get_input_is_a_directory_error(self, MockPromptSession):
        # Mock the PromptSession to simulate user input
        mock_session = MockPromptSession.return_value
        mock_session.prompt.return_value = "test input"

        io = InputOutput()
        root = "/"
        rel_fnames = ["existing_file.txt"]
        addable_rel_fnames = ["new_file.txt"]
        commands = MagicMock()

        # Simulate IsADirectoryError
        with patch('aider.io.open', side_effect=IsADirectoryError):
            result = io.get_input(root, rel_fnames, addable_rel_fnames, commands)
            self.assertEqual(result, "test input")

if __name__ == '__main__':
    unittest.main()
>>>>>>> REPLACE
```

This test case uses the `unittest` framework and mocks the `PromptSession` to simulate user input. It also patches the `open` function to raise an `IsADirectoryError` and verifies that the `get_input` method handles it correctly.

USER: I added these files to the chat: tests/test_io.py.

If you need to propose edits to other existing files not already added to the chat, you *MUST* tell the me their full path names and ask me to *add the files to the chat*. End your reply and wait for my approval. You can keep asking if you then decide you need to edit more files.

ASSISTANT: Let's add the new test case to the existing `tests/test_io.py` file to ensure that the `get_input` method in the `InputOutput` class handles the `IsADirectoryError` exception appropriately.

Here is the *SEARCH/REPLACE* block to add the new test case:

tests/test_io.py
```python
<<<<<<< SEARCH
import os
import unittest
from pathlib import Path
from unittest.mock import patch

from aider.io import AutoCompleter, InputOutput
from aider.utils import ChdirTemporaryDirectory

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.txt"]
        addable_rel_fnames = []
        commands = None
        autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
        self.assertEqual(autocompleter.words, set(rel_fnames))

    def test_autocompleter_with_unicode_file(self):
        with ChdirTemporaryDirectory():
            root = ""
            fname = "file.py"
            rel_fnames = [fname]
            addable_rel_fnames = []
            commands = None
            autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
            self.assertEqual(autocompleter.words, set(rel_fnames))

            Path(fname).write_text("def hello(): pass\n")
            autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
            self.assertEqual(autocompleter.words, set(rel_fnames + ["hello"]))

            encoding = "utf-16"
            some_content_which_will_error_if_read_with_encoding_utf8 = "ÅÍÎÏ".encode(encoding)
            with open(fname, "wb") as f:
                f.write(some_content_which_will_error_if_read_with_encoding_utf8)

            autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
            self.assertEqual(autocompleter.words, set(rel_fnames))

=======
import os
import unittest
from pathlib import Path
from unittest.mock import patch, MagicMock

from aider.io import AutoCompleter, InputOutput
from aider.utils import ChdirTemporaryDirectory

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.txt"]
        addable_rel_fnames = []
        commands = None
        autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
        self.assertEqual(autocompleter.words, set(rel_fnames))

    def test_autocompleter_with_unicode_file(self):
        with ChdirTemporaryDirectory():
            root = ""
            fname = "file.py"
            rel_fnames = [fname]
            addable_rel_fnames = []
            commands = None
            autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
            self.assertEqual(autocompleter.words, set(rel_fnames))

            Path(fname).write_text("def hello(): pass\n")
            autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
            self.assertEqual(autocompleter.words, set(rel_fnames + ["hello"]))

            encoding = "utf-16"
            some_content_which_will_error_if_read_with_encoding_utf8 = "ÅÍÎÏ".encode(encoding)
            with open(fname, "wb") as f:
                f.write(some_content_which_will_error_if_read_with_encoding_utf8)

            autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
            self.assertEqual(autocompleter.words, set(rel_fnames))

    @patch('aider.io.PromptSession')
    def test_get_input_is_a_directory_error(self, MockPromptSession):
        # Mock the PromptSession to simulate user input
        mock_session = MockPromptSession.return_value
        mock_session.prompt.return_value = "test input"

        io = InputOutput()
        root = "/"
        rel_fnames = ["existing_file.txt"]
        addable_rel_fnames = ["new_file.txt"]
        commands = MagicMock()

        # Simulate IsADirectoryError
        with patch('aider.io.open', side_effect=IsADirectoryError):
            result = io.get_input(root, rel_fnames, addable_rel_fnames, commands)
            self.assertEqual(result, "test input")
>>>>>>> REPLACE
```

This will add the new test case to the existing `tests/test_io.py` file.
2024-05-23 13:49:37 -07:00
Paul Gauthier
bb93c2a903 fixed tests 2024-05-09 14:35:57 -07:00
Paul Gauthier
a0649ba5fa fixed sendchat test 2024-05-05 08:03:26 -07:00
Paul Gauthier
250d89649b added test coverage #585 2024-05-02 13:01:41 -07:00
Paul Gauthier
e610e5bd0a Handle existing dirnames with [globby] chars, with test #195 2024-04-30 15:50:24 -07:00
Paul Gauthier
9bc8ed9227 fixed test to work with yield 2024-04-28 13:26:29 -07:00
Paul Gauthier
594a6bd934 updated mocks of Coder.send() to fix tests 2024-04-27 14:08:21 -07:00
Paul Gauthier
a2f6860e34 fixed tests 2024-04-22 14:14:06 -07:00
Paul Gauthier
b882d5db4c Do not require gpt-3.5 in GitRepo 2024-04-20 09:47:43 -07:00
Paul Gauthier
9b26eeb9eb Added validate_environment=False to tests 2024-04-20 08:18:27 -07:00
Paul Gauthier
957026d3cc fixed test_sendchat 2024-04-18 16:13:08 -07:00
Paul Gauthier
363b3202ab fixed test_repomap 2024-04-18 16:06:35 -07:00
Paul Gauthier
2a3eb8ac35 fixed test_editblock and _wholefile 2024-04-18 16:02:50 -07:00
Paul Gauthier
512b991a51 fixed test_coder 2024-04-18 15:55:59 -07:00
Paul Gauthier
f960774b51 fixed test_commands 2024-04-18 15:01:02 -07:00
Paul Gauthier
67cc974454 fixed test_main 2024-04-18 14:57:51 -07:00
Paul Gauthier
cb547da90c Fixed test_models 2024-04-18 14:53:20 -07:00
Paul Gauthier
c2b8b2355d Handle diffs on a detached head #520 2024-04-12 08:26:49 -07:00
Paul Gauthier
837f3ab048 Merge remote-tracking branch 'origin/main' 2024-03-22 10:03:04 -07:00
Paul Gauthier
a39965a9ff Only /undo the files which were part of the last commit, don't stomp other dirty files #513 2024-03-22 10:00:15 -07:00
Ryan Freckleton
19c8fa389f fix(tree-sitter-typescript-tags): correct tree-sitter queries
Add a new test case for typescript.
Fix queries for typescript.
2024-03-04 14:36:35 -07:00
Paul Gauthier
a9fe4532c7 Aider should fully ignore files in aiderignore #479 2024-02-24 09:39:33 -08:00
Paul Gauthier
35f812859e Rationalized openai model attributes #458 2024-02-07 12:07:30 -08:00
Paul Gauthier
d5f4ba2278 handle multiple udiffs inside a single fenced block 2024-01-04 12:53:01 -08:00
Paul Gauthier
0371b0f58b try and make windows tests happy 2024-01-02 09:44:47 -08:00
paul-gauthier
2824acb5c2
Merge pull request #379 from joshuavial/gpt4-vision
add support for gpt-4-vision
2024-01-02 13:37:17 -04:00
Paul Gauthier
e09a2033e2 Refactored the cmd_undo method to handle dirty files not in the last commit. 2024-01-02 09:04:57 -08:00
Paul Gauthier
cca43e8489 aider: Add test case for undo command with dirty files not in last commit.
# Aider chat conversation:

USER: add a test case for this

ASSISTANT: To add a test case for the updated `/undo` command behavior, we need to modify the `tests/test_commands.py` file. The new test case will ensure that the `/undo` command only aborts if the files modified in the latest commit are dirty.

Here is the diff for the new test case:

```diff
--- tests/test_commands.py
+++ tests/test_commands.py
@@ ... @@
+    def test_cmd_undo_with_dirty_files_not_in_last_commit(self):
+        with GitTemporaryDirectory() as repo_dir:
+            repo = git.Repo(repo_dir)
+            io = InputOutput(pretty=False, yes=True)
+            coder = Coder.create(models.GPT35, None, io)
+            commands = Commands(io, coder)
+
+            # Create and commit a file
+            filename = "test_file.txt"
+            file_path = Path(repo_dir) / filename
+            file_path.write_text("Initial content")
+            repo.git.add(filename)
+            repo.git.commit("-m", "Initial commit")
+
+            # Modify the file and commit again
+            file_path.write_text("Modified content")
+            repo.git.add(filename)
+            repo.git.commit("-m", "aider: Modify test_file.txt")
+
+            # Store the commit hash
+            last_commit_hash = repo.head.commit.hexsha[:7]
+            coder.last_aider_commit_hash = last_commit_hash
+
+            # Create a dirty file that was not in the last commit
+            other_file = "other_file.txt"
+            other_file_path = Path(repo_dir) / other_file
+            other_file_path.write_text("This is an untracked file")
+
+            # Attempt to undo the last commit
+            output = commands.cmd_undo("")
+            self.assertIsNone(output, "Undo should not produce any output")
+
+            # Check that the last commit is still present
+            self.assertEqual(last_commit_hash, repo.head.commit.hexsha[:7])
+
+            # Check that the dirty file is still untracked
+            self.assertTrue(other_file_path.exists())
+            self.assertIn(other_file, repo.untracked_files)
```

This test case creates a repository with an initial commit, then modifies a file and commits that change with a message indicating it was done by `aider`. It then creates another file that is not tracked by git (making the repository dirty, but not with the file that was in the last commit). It then runs the `/undo` command and checks that the last commit is still present and that the untracked file is still untracked, confirming that `/undo` did not abort due to the untracked file.
2024-01-02 08:47:58 -08:00
Paul Gauthier
15c915e481 added basic test coverage for find_diffs 2023-12-31 09:54:01 -08:00
Paul Gauthier
cf83d5ecd2 aider: Added tests for key functionality of udiff coder.
# Aider chat conversation:

USER: write some basic tests for the key functionality of udiff coder

ASSISTANT: ```diff
--- tests/test_udiff.py
+++ tests/test_udiff.py
@@ ... @@
+import unittest
+from unittest.mock import MagicMock, patch
+from pathlib import Path
+from aider.coders.udiff_coder import UnifiedDiffCoder, do_replace, apply_hunk, find_diffs
+from aider.io import InputOutput
+
+class TestUnifiedDiffCoder(unittest.TestCase):
+    def setUp(self):
+        self.coder = UnifiedDiffCoder(io=InputOutput())
+
+    def test_do_replace_new_file(self):
+        # Test do_replace when it should create a new file
+        hunk = [
+            "--- /dev/null",
+            "+++ newfile.txt",
+            "@@ -0,0 +1 @@",
+            "+New content\n"
+        ]
+        result = do_replace('newfile.txt', None, hunk)
+        self.assertEqual(result, 'New content\n')
+
+    def test_apply_hunk_with_changes(self):
+        # Test apply_hunk with actual changes
+        content = "Original line 1\nOriginal line 2\n"
+        hunk = [
+            "@@ -1,2 +1,2 @@",
+            " Original line 1",
+            "-Original line 2",
+            "+Modified line 2"
+        ]
+        result = apply_hunk(content, hunk)
+        self.assertEqual(result, "Original line 1\nModified line 2\n")
+
+    def test_find_diffs_single_hunk(self):
+        # Test find_diffs with a single hunk
+        content = "```diff\n--- a/file.txt\n+++ b/file.txt\n@@ -1,2 +1,2 @@\n-Original\n+Modified\n```\n"
+        result = find_diffs(content)
+        self.assertEqual(len(result), 1)
+        self.assertEqual(result[0][0], 'b/file.txt')
+        self.assertEqual(result[0][1], ['@@ -1,2 +1,2 @@\n', '-Original\n', '+Modified\n'])
+
+if __name__ == '__main__':
+    unittest.main()
```
2023-12-31 09:45:33 -08:00
Joshua Vial
179b648864 merging from upstream main 2023-12-19 22:04:39 +13:00
Paul Gauthier
7113a30271 unified diffs 2023-12-17 12:54:34 -08:00
Joshua Vial
90d5071709 fix failing tests 2023-12-11 22:37:23 +13:00
Paul Gauthier
9d2f89dd75 fix test 2023-12-06 09:30:19 -08:00
Paul Gauthier
922a56b194 Merge branch 'main' into openai-upgrade 2023-12-06 09:26:05 -08:00
Paul Gauthier
57ab2cc9da Revert "implement deployment id"
This reverts commit b107db98fa.
2023-12-06 09:20:53 -08:00
Your Name
4692a689fe Improvements: flag -f (not -mf); unitest improvements. 2023-12-05 23:55:10 +01:00