Commit graph

650 commits

Author SHA1 Message Date
Paul Gauthier (aider)
24c8363aa8 Fix unused import of unittest in tests/basic/test_commands.py 2024-07-29 16:45:59 -03:00
Paul Gauthier
f90cd6b69b Add unit tests for the cmd_lint command 2024-07-29 16:45:57 -03:00
Paul Gauthier (aider)
cf35c2db4e Fix the test_cmd_lint_with_dirty_file test to use mocking instead of captured output 2024-07-29 16:45:21 -03:00
Paul Gauthier
bb7465e05d Modify test_commands.py to mock linter.lint method and assert it was called with the dirty file 2024-07-29 16:45:18 -03:00
Paul Gauthier (aider)
894eff4393 Add a test that checks if the cmd_lint command correctly identifies a dirty file in a repository. 2024-07-29 16:30:08 -03:00
Paul Gauthier (aider)
f04fb8d53a Add a test for get_commit_message that initializes a GitRepo with two models and ensures the commit message is correctly retrieved from the second model. 2024-07-28 17:13:35 -03:00
Paul Gauthier
5bf9dbb226 Fix test for self-signed url scrape 2024-07-28 16:49:32 -03:00
Paul Gauthier
8a9184cef9 Fix tests for check_for_urls 2024-07-28 16:48:59 -03:00
Paul Gauthier (aider)
a0eadb62c5 Add test case for check_for_urls to handle repeated URLs 2024-07-28 16:40:39 -03:00
Paul Gauthier (aider)
a03506046c Add test to fetch self-signed SSL site with and without verification 2024-07-28 16:37:47 -03:00
Paul Gauthier (aider)
b9d6fd16fc Added a test case for error handling in the scrape_with_playwright method. 2024-07-25 20:27:24 +02:00
Paul Gauthier
bb86fed9f6 disable ocaml test for now, until fixed 2024-07-24 09:41:25 +02:00
Paul Gauthier (aider)
9db28c0052 Added a new test case to ensure the RepoMap class can handle and include files from all supported languages. 2024-07-24 09:24:52 +02:00
Paul Gauthier (aider)
44376ee382 Added the print_error not called check in the test_cmd_web_imports_playwright method. 2024-07-23 11:45:17 +02:00
Paul Gauthier (aider)
f99dbc2c43 Replaced mocked Playwright usage with real Playwright implementation in the test suite. 2024-07-23 11:43:14 +02:00
Paul Gauthier (aider)
8a73346f66 Added a test to scrape an actual URL with Playwright and ensured that Scraper.print_error is never called in any of the scraper tests. 2024-07-23 11:42:01 +02:00
Paul Gauthier (aider)
d31eef3fc6 Mocked Path.home() in addition to setting os.environ["HOME"] in the test_env_file_override function. 2024-07-18 17:42:50 +01:00
Paul Gauthier
e36d47cfdb Added tests and fix for env file precedence #868 2024-07-18 17:20:58 +01:00
Paul Gauthier (aider)
c9bcc1aa57 Added a test to check the .env file override behavior as described in the documentation. 2024-07-18 17:07:38 +01:00
Paul Gauthier
397c5d5921 added a test for /tokens #863 2024-07-18 16:54:26 +01:00
Paul Gauthier (aider)
cdd45c7d28 Added a test for the cmd_tokens method that creates a small Git repository, adds files to the chat, and verifies that the output of cmd_tokens includes the repository map information and details about the added files. 2024-07-18 16:39:42 +01:00
Paul Gauthier
c99c5db35c updated coder test 2024-07-18 16:35:27 +01:00
Paul Gauthier (aider)
6fdb4f8214 Handled case where first commit cannot be undone 2024-07-18 16:32:47 +01:00
Paul Gauthier
3ce3799f8d Implemented checks to ensure files with uncommitted changes or not present in previous commit cannot be undone safely. 2024-07-18 16:32:45 +01:00
Paul Gauthier
e7f29c2dbc Added a new test case for cmd_undo with a newly committed file. 2024-07-18 16:17:20 +01:00
Paul Gauthier (aider)
9aeeaf383f Implemented a test that will trigger the bug described in issue #882. 2024-07-18 16:09:38 +01:00
Paul Gauthier (aider)
07550d6f5f Added tests to exercise all combinations of path formats for get_file_mentions and get_addable_relative_files, and updated the get_file_mentions method to handle both Unix and Windows path formats. 2024-07-18 15:19:32 +01:00
Paul Gauthier
96b1e1d04f finished scrape tests 2024-07-16 11:27:27 +01:00
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