mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
fix tests; fix off-by-one bug in output of repomap
This commit is contained in:
parent
10b856e0af
commit
c0375d3328
2 changed files with 14 additions and 32 deletions
|
@ -28,12 +28,17 @@ def to_tree(tags):
|
||||||
cur_fname = None
|
cur_fname = None
|
||||||
context = None
|
context = None
|
||||||
output = ""
|
output = ""
|
||||||
for tag in tags:
|
|
||||||
if type(tag) is tuple:
|
# add a bogus tag at the end so we trip the this_fname != cur_fname...
|
||||||
|
for tag in tags + [None]:
|
||||||
|
if tag is None:
|
||||||
|
this_fname = None
|
||||||
|
elif type(tag) is tuple:
|
||||||
this_fname = tag[0]
|
this_fname = tag[0]
|
||||||
else:
|
else:
|
||||||
this_fname = tag.rel_fname
|
this_fname = tag.rel_fname
|
||||||
|
|
||||||
|
# ... here ... to output the final real entry in the list
|
||||||
if this_fname != cur_fname:
|
if this_fname != cur_fname:
|
||||||
if context:
|
if context:
|
||||||
context.add_context()
|
context.add_context()
|
||||||
|
@ -45,7 +50,7 @@ def to_tree(tags):
|
||||||
elif cur_fname:
|
elif cur_fname:
|
||||||
output += cur_fname + "\n"
|
output += cur_fname + "\n"
|
||||||
|
|
||||||
if type(tag) is not tuple:
|
if type(tag) is Tag:
|
||||||
context = TreeContext(
|
context = TreeContext(
|
||||||
tag.rel_fname,
|
tag.rel_fname,
|
||||||
Path(tag.fname).read_text(), # TODO: encoding
|
Path(tag.fname).read_text(), # TODO: encoding
|
||||||
|
@ -120,7 +125,7 @@ class RepoMap:
|
||||||
|
|
||||||
num_tokens = self.token_count(files_listing)
|
num_tokens = self.token_count(files_listing)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.io.tool_output(f"ctags map: {num_tokens/1024:.1f} k-tokens")
|
self.io.tool_output(f"ast map: {num_tokens/1024:.1f} k-tokens")
|
||||||
|
|
||||||
if chat_files:
|
if chat_files:
|
||||||
other = "other "
|
other = "other "
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.io import InputOutput
|
from aider.io import InputOutput
|
||||||
from aider.repomap import RepoMap
|
from aider.repomap import RepoMap
|
||||||
from tests.utils import IgnorantTemporaryDirectory
|
from tests.utils import IgnorantTemporaryDirectory
|
||||||
|
@ -89,33 +89,9 @@ print(my_function(3, 4))
|
||||||
# close the open cache files, so Windows won't error
|
# close the open cache files, so Windows won't error
|
||||||
del repo_map
|
del repo_map
|
||||||
|
|
||||||
def test_check_for_ctags_failure(self):
|
def test_get_repo_map_all_files(self):
|
||||||
with patch("subprocess.run") as mock_run:
|
|
||||||
mock_run.side_effect = Exception("ctags not found")
|
|
||||||
repo_map = RepoMap(io=InputOutput())
|
|
||||||
self.assertFalse(repo_map.has_ctags)
|
|
||||||
|
|
||||||
def test_check_for_ctags_success(self):
|
|
||||||
with patch("subprocess.check_output") as mock_run:
|
|
||||||
mock_run.side_effect = [
|
|
||||||
(
|
|
||||||
b"Universal Ctags 0.0.0(f25b4bb7)\n Optional compiled features: +wildcards,"
|
|
||||||
b" +regex, +gnulib_fnmatch, +gnulib_regex, +iconv, +option-directory, +xpath,"
|
|
||||||
b" +json, +interactive, +yaml, +case-insensitive-filenames, +packcc,"
|
|
||||||
b" +optscript, +pcre2"
|
|
||||||
),
|
|
||||||
(
|
|
||||||
b'{"_type": "tag", "name": "status", "path": "aider/main.py", "pattern": "/^ '
|
|
||||||
b' status = main()$/", "kind": "variable"}'
|
|
||||||
),
|
|
||||||
]
|
|
||||||
repo_map = RepoMap(io=InputOutput())
|
|
||||||
self.assertTrue(repo_map.has_ctags)
|
|
||||||
|
|
||||||
def test_get_repo_map_without_ctags(self):
|
|
||||||
# Create a temporary directory with a sample Python file containing identifiers
|
|
||||||
test_files = [
|
test_files = [
|
||||||
"test_file_without_ctags.py",
|
"test_file0.py",
|
||||||
"test_file1.txt",
|
"test_file1.txt",
|
||||||
"test_file2.md",
|
"test_file2.md",
|
||||||
"test_file3.json",
|
"test_file3.json",
|
||||||
|
@ -130,10 +106,11 @@ print(my_function(3, 4))
|
||||||
f.write("")
|
f.write("")
|
||||||
|
|
||||||
repo_map = RepoMap(root=temp_dir, io=InputOutput())
|
repo_map = RepoMap(root=temp_dir, io=InputOutput())
|
||||||
repo_map.has_ctags = False # force it off
|
|
||||||
|
|
||||||
other_files = [os.path.join(temp_dir, file) for file in test_files]
|
other_files = [os.path.join(temp_dir, file) for file in test_files]
|
||||||
result = repo_map.get_repo_map([], other_files)
|
result = repo_map.get_repo_map([], other_files)
|
||||||
|
dump(other_files)
|
||||||
|
dump(repr(result))
|
||||||
|
|
||||||
# Check if the result contains each specific file in the expected tags map without ctags
|
# Check if the result contains each specific file in the expected tags map without ctags
|
||||||
for file in test_files:
|
for file in test_files:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue