Commit graph

21 commits

Author SHA1 Message Date
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
92cd2f3ce6 isort 2023-05-28 22:47:38 -07:00
Paul Gauthier
03f300ec75 aider: Updated test_repomap.py to put the JSON string on one line in the test_check_for_ctags_success method.
# Context:
USER: put all that json on one line
ASSISTANT: I will update the `tests/test_repomap.py` file to put the JSON string on one line in the `test_check_for_ctags_success` method.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            mock_run.return_value = CompletedProcess(args=["ctags", "--version"], returncode=0, stdout=b'''{
  "_type": "tag",
  "name": "status",
  "path": "aider/main.py",
  "pattern": "/^    status = main()$/",
  "kind": "variable"
}''')
=======
            mock_run.return_value = CompletedProcess(args=["ctags", "--version"], returncode=0, stdout=b'{"_type": "tag", "name": "status", "path": "aider/main.py", "pattern": "/^    status = main()$/", "kind": "variable"}')
>>>>>>> UPDATED
```

Now the JSON string is on one line in the `test_check_for_ctags_success` method.
2023-05-28 22:19:44 -07:00
Paul Gauthier
346eb7a834 aider: Replaced string with bytes object in test_check_for_ctags_success to fix 'decode' method issue.
# Context:
USER: running test_check_for_ctags_success i get: tests/test_repomap.py 'str' object has no attribute 'decode'
ASSISTANT: It seems like the issue is with the `decode` method being called on a string object. I'll fix this issue for you. Here's the change you need to make in the `tests/test_repomap.py` file:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            mock_run.return_value = CompletedProcess(args=["ctags", "--version"], returncode=0, stdout='''{
  "_type": "tag",
  "name": "status",
  "path": "aider/main.py",
  "pattern": "/^    status = main()$/",
  "kind": "variable"
}''')
=======
            mock_run.return_value = CompletedProcess(args=["ctags", "--version"], returncode=0, stdout=b'''{
  "_type": "tag",
  "name": "status",
  "path": "aider/main.py",
  "pattern": "/^    status = main()$/",
  "kind": "variable"
}''')
>>>>>>> UPDATED
```

This change replaces the string with a bytes object, so the `decode` method can be called without any issues.
2023-05-28 22:18:18 -07:00
Paul Gauthier
f5de27ccdd aider: Updated test_check_for_ctags_success to return valid JSON output for get_tags.
# Context:
USER: the output of the subprocess.run needs to be valid json like this:

{
  "_type": "tag",
  "name": "status",
  "path": "aider/main.py",
  "pattern": "/^    status = main()$/",
  "kind": "variable"
}

ASSISTANT: To update the test `test_check_for_ctags_success` to return valid JSON output for `get_tags`, modify the `tests/test_repomap.py` file. Here's the change:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
    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="Exuberant Ctags 5.8")
=======
    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='''{
  "_type": "tag",
  "name": "status",
  "path": "aider/main.py",
  "pattern": "/^    status = main()$/",
  "kind": "variable"
}''')
>>>>>>> UPDATED
```

This change updates the `stdout` value of the `CompletedProcess` object to return valid JSON output as specified. After making this change, run the tests again to ensure they pass.
2023-05-28 17:09:45 -07:00
Paul Gauthier
c2e8fee3d9 aider: Import CompletedProcess from the subprocess module to fix NameError in test_check_for_ctags_success.
# Context:
USER: pytest tests/test_repomap.py
ASSISTANT: I'm an AI language model and cannot execute commands directly. However,
^C KeyboardInterrupt
USER: I ran this command:

 pytest tests/test_repomap.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 5 items

tests/test_repomap.py .F...                                              [100%]

=================================== FAILURES ===================================
___________________ TestRepoMap.test_check_for_ctags_success ___________________

self = <tests.test_repomap.TestRepoMap testMethod=test_check_for_ctags_success>

    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="Exuberant Ctags 5.8")
E           NameError: name 'CompletedProcess' is not defined

tests/test_repomap.py:67: NameError
=========================== short test summary info ============================
FAILED tests/test_repomap.py::TestRepoMap::test_check_for_ctags_success - Nam...
========================= 1 failed, 4 passed in 0.43s ==========================

ASSISTANT: It looks like there's a `NameError` because `CompletedProcess` is not defined. To fix this, you need to import `CompletedProcess` from the `subprocess` module. Here's the change:

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

This change imports `CompletedProcess` from the `subprocess` module, which should resolve the `NameError`. After making this change, try running the tests again.
2023-05-28 17:08:28 -07:00
Paul Gauthier
6ead145c17 aider: Added test method test_check_for_ctags_success that patches subprocess.run to return a CompletedProcess object with a successful return code and sensible output, and checks if check_for_ctags returns True.
# Context:
USER: add another like that, but the patched subprocess should return sensible output for get_tags
ASSISTANT: To add another test for `check_for_ctags` that patches `subprocess` to return sensible output for `get_tags`, we'll modify the `tests/test_repomap.py` file. We'll use the `unittest.mock` library to patch the `subprocess.run` function to simulate a successful execution.

Here's the change:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
    def test_get_tags_map_without_ctags(self):
=======
    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="Exuberant Ctags 5.8")
            repo_map = RepoMap(use_ctags=True)
            result = repo_map.check_for_ctags()
            self.assertTrue(result)

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

This adds a new test method `test_check_for_ctags_success` that patches `subprocess.run` to return a `CompletedProcess` object with a successful return code and sensible output. The test then checks if `check_for_ctags` returns `True`.
2023-05-28 17:07:49 -07:00
Paul Gauthier
8b3b4a2e26 Added import of unittest.mock to test_repomap.py. 2023-05-28 17:07:05 -07:00
Paul Gauthier
f2a116e0e1 aider: Added test method test_check_for_ctags_failure that patches subprocess.run to raise an exception, simulating a failure, and checks if check_for_ctags returns False.
# Context:
USER: in tests/test_repomap.py add a test for check_for_ctags which patches subprocess to fail. check_for_ctags should return false
ASSISTANT: To add a test for `check_for_ctags` that patches `subprocess` to fail, we'll modify the `tests/test_repomap.py` file. We'll use the `unittest.mock` library to patch the `subprocess.run` function to simulate a failure.

Here's the change:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
    def test_get_tags_map_without_ctags(self):
=======
    from unittest.mock import patch

    def test_check_for_ctags_failure(self):
        with patch("subprocess.run") as mock_run:
            mock_run.side_effect = Exception("ctags not found")
            repo_map = RepoMap(use_ctags=True)
            result = repo_map.check_for_ctags()
            self.assertFalse(result)

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

This adds a new test method `test_check_for_ctags_failure` that patches `subprocess.run` to raise an exception, simulating a failure. The test then checks if `check_for_ctags` returns `False`.
2023-05-28 17:06:09 -07:00
Paul Gauthier
60031ecd29 fixed bug found by testing 2023-05-24 19:09:05 -07:00
Paul Gauthier
82804e2a6c aider: Updated test to check for correct format of file in result.
# Context:
USER: I ran this command:

 pytest tests/test_repomap.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 3 items

tests/test_repomap.py ..F                                                [100%]

=================================== FAILURES ===================================
_________________ TestRepoMap.test_get_tags_map_without_ctags __________________

self = <tests.test_repomap.TestRepoMap testMethod=test_get_tags_map_without_ctags>

    def test_get_tags_map_without_ctags(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_files = [
            "test_file_without_ctags.py",
            "test_file1.txt",
            "test_file2.md",
            "test_file3.json",
            "test_file4.html",
            "test_file5.css",
            "test_file6.js",
        ]

        with tempfile.TemporaryDirectory() as temp_dir:
            for file in test_files:
                with open(os.path.join(temp_dir, file), "w") as f:
                    f.write("")

            repo_map = RepoMap(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, file) for file in test_files]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains each specific file in the expected tags map without ctags
            for file in test_files:
>               self.assertIn(f"{os.path.splitext(file)[0]}:", result)
E               AssertionError: 'test_file_without_ctags:' not found in 'test_file1.txt:\ntest_file4.html:\ntest_file5.css:\ntest_file6.js:\ntest_file_without_ctags.py:\n'

tests/test_repomap.py:80: AssertionError
=========================== short test summary info ============================
FAILED tests/test_repomap.py::TestRepoMap::test_get_tags_map_without_ctags - ...
========================= 1 failed, 2 passed in 0.39s ==========================

ASSISTANT: It seems that the test `test_get_tags_map_without_ctags` is failing because the expected string 'test_file_without_ctags:' is not found in the result. The result contains 'test_file_without_ctags.py:', which is the correct format. I will update the test to fix this issue.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            for file in test_files:
                self.assertIn(f"{os.path.splitext(file)[0]}:", result)
=======
            for file in test_files:
                self.assertIn(f"{os.path.splitext(file)[0]}.{os.path.splitext(file)[1][1:]}:", result)
>>>>>>> UPDATED
```

This update changes the test to check for the correct format of the file in the result. Now you can run the test again with the `pytest tests/test_repomap.py` command.
2023-05-24 19:06:39 -07:00
Paul Gauthier
0fa1345ed0 aider: Updated test_get_tags_map_without_ctags test in tests/test_repomap.py to check if each specific file is in the result.
# Context:
USER: that test needs to check if each specific file is in the result, not test_get_tags_map_without_ctags
ASSISTANT: I will update the `test_get_tags_map_without_ctags` test in the `tests/test_repomap.py` file to check if each specific file is in the result.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            # Check if the result contains the expected tags map without ctags
            self.assertIn("test_file_without_ctags.py:", result)
=======
            # Check if the result contains each specific file in the expected tags map without ctags
            for file in test_files:
                self.assertIn(f"{os.path.splitext(file)[0]}:", result)
>>>>>>> UPDATED
```

This update checks if each specific file is in the result of the `get_tags_map` function when `ctags=False`.
2023-05-24 19:05:55 -07:00
Paul Gauthier
ec4b5dc2c3 aider: Updated test to not put anything in the file and add more files of various kinds.
# Context:
USER: update that test to not put anything in the file. add a bunch more files of various kinds. check them all.
ASSISTANT: I will update the `test_get_tags_map_without_ctags` test in the `tests/test_repomap.py` file to not put any content in the Python file and add more files of various kinds.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
        test_file = "test_file_without_ctags.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(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file)]
            result = repo_map.get_tags_map(other_files)
=======
        test_files = [
            "test_file_without_ctags.py",
            "test_file1.txt",
            "test_file2.md",
            "test_file3.json",
            "test_file4.html",
            "test_file5.css",
            "test_file6.js",
        ]

        with tempfile.TemporaryDirectory() as temp_dir:
            for file in test_files:
                with open(os.path.join(temp_dir, file), "w") as f:
                    f.write("")

            repo_map = RepoMap(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, file) for file in test_files]
            result = repo_map.get_tags_map(other_files)
>>>>>>> UPDATED
```

This update removes the content from the Python file and adds more files of various kinds. The test checks if the `get_tags_map` function returns the expected tags map containing all the files when `ctags=False`.
2023-05-24 19:04:43 -07:00
Paul Gauthier
45442b99e1 aider: Added test to check if get_tags_map function returns the expected tags map containing the file when ctags=False.
# Context:
USER: add another like that, but with ctags=False. just make sure the file is in the result.
ASSISTANT: I will add a new test to the `tests/test_repomap.py` file that checks if the file is in the result when `ctags=False`.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            self.assertIn("my_function", result)

if __name__ == "__main__":
    unittest.main()
=======
            self.assertIn("my_function", result)

    def test_get_tags_map_without_ctags(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_file = "test_file_without_ctags.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(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file)]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains the expected tags map without ctags
            self.assertIn("test_file_without_ctags.py:", result)

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

This new test creates a temporary directory with a sample Python file containing a class, a method, and a function. It then checks if the `get_tags_map` function returns the expected tags map containing the file when `ctags=False`.
2023-05-24 19:02:37 -07:00
Paul Gauthier
8f2447078c aider: Added a new test to check if the get_tags_map function returns the expected tags map containing the identifiers from a Python file.
# Context:
USER: add another test. pass in a python file which defines a few identifiers. make sure they appear in the map.
ASSISTANT: I will add a new test to the `tests/test_repomap.py` file that checks if the identifiers from a Python file appear in the map.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            self.assertNotIn("test_file4.json:", result)

if __name__ == "__main__":
    unittest.main()
=======
            self.assertNotIn("test_file4.json:", result)

    def test_get_tags_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)]
            result = repo_map.get_tags_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)

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

This new test creates a temporary directory with a sample Python file containing a class, a method, and a function. It then checks if the `get_tags_map` function returns the expected tags map containing the identifiers from the Python file.
2023-05-24 19:01:02 -07:00
Paul Gauthier
c8c0e6232f aider: Added import statement for tempfile module in tests/test_repomap.py.
# Context:
USER: I ran this command:

 pytest tests/test_repomap.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_repomap.py F                                                  [100%]

=================================== FAILURES ===================================
________________________ TestRepoMap.test_get_tags_map _________________________

self = <tests.test_repomap.TestRepoMap testMethod=test_get_tags_map>

    def test_get_tags_map(self):
        # Create a temporary directory with sample files for testing
        test_files = [
            "test_file1.py",
            "test_file2.py",
            "test_file3.md",
            "test_file4.json",
        ]

>       with tempfile.TemporaryDirectory() as temp_dir:
E       NameError: name 'tempfile' is not defined

tests/test_repomap.py:15: NameError
=========================== short test summary info ============================
FAILED tests/test_repomap.py::TestRepoMap::test_get_tags_map - NameError: nam...
============================== 1 failed in 0.05s ===============================

ASSISTANT: It looks like the `tempfile` module is not imported in the `tests/test_repomap.py` file. I will add the import statement for you.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
import os
import unittest
from aider.repomap import RepoMap
=======
import os
import tempfile
import unittest
from aider.repomap import RepoMap
>>>>>>> UPDATED
```

Now, you can run the test again with the `pytest tests/test_repomap.py` command.
2023-05-24 18:59:12 -07:00
Paul Gauthier
452d31089b aider: Added a test for the get_tags_map function in the aider/repomap.py file.
# Context:
USER: write a test for get_tags_map
ASSISTANT: I need to know the expected behavior of the `get_tags_map` function in the `repomap.py` file. Please provide a brief description of the function and its expected output for a given input.
USER: I added the content of these additional files: aider/repomap.py
ASSISTANT: Thank you. I will now write a test for the `get_tags_map` function in the `aider/repomap.py` file.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
=======
import os
import unittest
from aider.repomap import RepoMap

class TestRepoMap(unittest.TestCase):
    def test_get_tags_map(self):
        # Create a temporary directory with sample files for testing
        test_files = [
            "test_file1.py",
            "test_file2.py",
            "test_file3.md",
            "test_file4.json",
        ]

        with tempfile.TemporaryDirectory() as temp_dir:
            for file in test_files:
                with open(os.path.join(temp_dir, file), "w") as f:
                    f.write("")

            repo_map = RepoMap(root=temp_dir)
            other_files = [os.path.join(temp_dir, file) for file in test_files]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains the expected tags map
            self.assertIn("test_file1.py:", result)
            self.assertIn("test_file2.py:", result)
            self.assertNotIn("test_file3.md:", result)
            self.assertNotIn("test_file4.json:", result)

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

This test creates a temporary directory with sample files and checks if the `get_tags_map` function returns the expected tags map for the given input. The test checks if the result contains the tags map for `.py` files and does not contain the tags map for `.md` and `.json` files.
2023-05-24 18:58:29 -07:00
Paul Gauthier
507d7c0444 Added new files to the git repo: tests/test_repomap.py 2023-05-24 18:56:03 -07:00