Commit graph

38 commits

Author SHA1 Message Date
Paul Gauthier
a2f6860e34 fixed tests 2024-04-22 14:14:06 -07:00
Paul Gauthier
9b26eeb9eb Added validate_environment=False to tests 2024-04-20 08:18:27 -07:00
Paul Gauthier
363b3202ab fixed test_repomap 2024-04-18 16:06:35 -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
7113a30271 unified diffs 2023-12-17 12:54:34 -08:00
Paul Gauthier
d54f883698 do not include added files in the repo map #315 2023-11-15 13:06:22 -08:00
Paul Gauthier
c0375d3328 fix tests; fix off-by-one bug in output of repomap 2023-10-18 15:42:38 -07:00
Paul Gauthier
e2a32fec7e linting 2023-07-21 16:08:50 -03:00
Paul Gauthier
86cea01434 aider: Change the relative import to an absolute import for the IgnorantTemporaryDirectory class in test_repomap.py.
# Aider chat conversation:

USER: ImportError: Failed to import test module: test_repomap
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/runner/work/aider/aider/tests/test_repomap.py", line 8, in <module>
    from .utils import IgnorantTemporaryDirectory
ImportError: attempted relative import with no known parent package

ASSISTANT: The error message indicates that Python is unable to find the `utils` module when it's being imported in `test_repomap.py`. This is because the import statement is using a relative import with the dot (`.`) prefix, which is not working in this context.

To fix this, we need to change the relative import to an absolute import. This means we need to specify the full path to the `utils` module from the project's root directory.

Here is the change you need to make:

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
from .utils import IgnorantTemporaryDirectory
=======
from tests.utils import IgnorantTemporaryDirectory
>>>>>>> UPDATED
```

This change tells Python to import the `IgnorantTemporaryDirectory` class from the `utils` module located in the `tests` directory, which is an absolute path from the project's root directory.
2023-07-16 09:05:18 -03:00
Paul Gauthier
cdf35cd122 refac 2023-07-16 09:02:35 -03:00
Paul Gauthier
719810b1a1 removed import 2023-07-13 17:47:24 -07:00
Paul Gauthier
b52a62190a Ignore errors when cleaning up temp dirs (Win) 2023-07-13 17:18:09 -07:00
Paul Gauthier
8e2b92febb close the open cache files, so Windows won't error 2023-07-13 16:02:29 -07:00
Paul Gauthier
24015dab5f Try and make test run on windows 2023-07-13 15:55:33 -07:00
Paul Gauthier
c8fb1ddaa7 refactor to use io.read_text 2023-07-05 20:46:15 -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
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