style: Format code according to linter rules

This commit is contained in:
Paul Gauthier (aider) 2025-03-22 13:23:52 -07:00
parent 3b376a15b7
commit 7e51c68fde

View file

@ -284,12 +284,12 @@ class TestCoder(unittest.TestCase):
coder.check_for_file_mentions(f"Please check `{fname}`") coder.check_for_file_mentions(f"Please check `{fname}`")
self.assertEqual(coder.abs_fnames, set([str(fname.resolve())])) self.assertEqual(coder.abs_fnames, set([str(fname.resolve())]))
def test_get_file_mentions_various_formats(self): def test_get_file_mentions_various_formats(self):
with GitTemporaryDirectory(): with GitTemporaryDirectory():
io = InputOutput(pretty=False, yes=True) io = InputOutput(pretty=False, yes=True)
coder = Coder.create(self.GPT35, None, io) coder = Coder.create(self.GPT35, None, io)
# Create test files # Create test files
test_files = [ test_files = [
"file1.txt", "file1.txt",
@ -299,65 +299,66 @@ class TestCoder(unittest.TestCase):
"file with spaces.txt", "file with spaces.txt",
"special_chars!@#.md", "special_chars!@#.md",
] ]
for fname in test_files: for fname in test_files:
fpath = Path(fname) fpath = Path(fname)
fpath.parent.mkdir(parents=True, exist_ok=True) fpath.parent.mkdir(parents=True, exist_ok=True)
fpath.touch() fpath.touch()
# Mock get_addable_relative_files to return our test files # Mock get_addable_relative_files to return our test files
coder.get_addable_relative_files = MagicMock(return_value=set(test_files)) coder.get_addable_relative_files = MagicMock(return_value=set(test_files))
# Test different mention formats # Test different mention formats
test_cases = [ test_cases = [
# Simple plain text mentions # Simple plain text mentions
(f"You should edit {test_files[0]} first", {test_files[0]}), (f"You should edit {test_files[0]} first", {test_files[0]}),
# Multiple files in plain text # Multiple files in plain text
(f"Edit both {test_files[0]} and {test_files[1]}", {test_files[0], test_files[1]}), (f"Edit both {test_files[0]} and {test_files[1]}", {test_files[0], test_files[1]}),
# Files in backticks # Files in backticks
(f"Check the file `{test_files[2]}`", {test_files[2]}), (f"Check the file `{test_files[2]}`", {test_files[2]}),
# Files in code blocks # Files in code blocks
(f"```\n{test_files[3]}\n```", {test_files[3]}), (f"```\n{test_files[3]}\n```", {test_files[3]}),
# Files in code blocks with language specifier # Files in code blocks with language specifier
(f"```python\nwith open('{test_files[1]}', 'r') as f:\n data = f.read()\n```", {test_files[1]}), (
f"```python\nwith open('{test_files[1]}', 'r') as f:\n data = f.read()\n```",
{test_files[1]},
),
# Files with Windows-style paths # Files with Windows-style paths
(f"Edit the file {test_files[2].replace('/', '\\')}", {test_files[2]}), (f"Edit the file {test_files[2].replace('/', '\\')}", {test_files[2]}),
# Files with spaces # Files with spaces
(f"Look at '{test_files[4]}'", {test_files[4]}), (f"Look at '{test_files[4]}'", {test_files[4]}),
# Files with different quote styles # Files with different quote styles
(f'Check "{test_files[5]}" now', {test_files[5]}), (f'Check "{test_files[5]}" now', {test_files[5]}),
# Files mentioned in markdown links # Files mentioned in markdown links
(f"See the file [{test_files[0]}]({test_files[0]})", {test_files[0]}), (f"See the file [{test_files[0]}]({test_files[0]})", {test_files[0]}),
# All files in one complex message # All files in one complex message
( (
f"First, edit `{test_files[0]}`. Then modify {test_files[1]}.\n" (
f"```js\n// Update this file\nconst file = '{test_files[2]}';\n```\n" f"First, edit `{test_files[0]}`. Then modify {test_files[1]}.\n"
f"Finally check {test_files[3].replace('/', '\\')}", f"```js\n// Update this file\nconst file = '{test_files[2]}';\n```\n"
{test_files[0], test_files[1], test_files[2], test_files[3]} f"Finally check {test_files[3].replace('/', '\\')}"
),
{test_files[0], test_files[1], test_files[2], test_files[3]},
), ),
# Mention with SEARCH/REPLACE format # Mention with SEARCH/REPLACE format
( (
f"{test_files[1]}\n````python\n<<<<<<< SEARCH\ndef old_function():\n pass\n=======\n" (
f"def new_function():\n return True\n>>>>>>> REPLACE\n````", f"{test_files[1]}\n````python\n<<<<<<< SEARCH\ndef old_function():\n "
{test_files[1]} " pass\n=======\ndef new_function():\n return True\n>>>>>>>"
" REPLACE\n````"
),
{test_files[1]},
), ),
] ]
for content, expected_mentions in test_cases: for content, expected_mentions in test_cases:
with self.subTest(content=content): with self.subTest(content=content):
mentioned_files = coder.get_file_mentions(content) mentioned_files = coder.get_file_mentions(content)
self.assertEqual(mentioned_files, expected_mentions, self.assertEqual(
f"Failed to extract mentions from: {content}") mentioned_files,
expected_mentions,
f"Failed to extract mentions from: {content}",
)
def test_get_file_mentions_path_formats(self): def test_get_file_mentions_path_formats(self):
with GitTemporaryDirectory(): with GitTemporaryDirectory():