mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 20:35:00 +00:00
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
import os
|
|
import unittest
|
|
from unittest.mock import MagicMock
|
|
from aider.coder import Coder
|
|
|
|
|
|
class TestCoder(unittest.TestCase):
|
|
def test_check_for_file_mentions(self):
|
|
# Mock the IO object
|
|
mock_io = MagicMock()
|
|
|
|
# Initialize the Coder object with the mocked IO and mocked repo
|
|
coder = Coder(io=mock_io, openai_api_key="fake_key")
|
|
|
|
# Mock the git repo
|
|
mock_repo = MagicMock()
|
|
mock_repo.git.ls_files.return_value = "file1.txt\nfile2.py"
|
|
coder.repo = mock_repo
|
|
|
|
# Call the check_for_file_mentions method
|
|
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
|
|
|
# Check if coder.abs_fnames contains both files
|
|
expected_files = {os.path.abspath("file1.txt"), os.path.abspath("file2.py")}
|
|
self.assertEqual(coder.abs_fnames, expected_files)
|
|
|
|
def test_check_for_filename_mentions_of_longer_paths(self):
|
|
# Mock the IO object
|
|
mock_io = MagicMock()
|
|
|
|
# Initialize the Coder object with the mocked IO and mocked repo
|
|
coder = Coder(io=mock_io, openai_api_key="fake_key")
|
|
|
|
# Mock the git repo
|
|
mock_repo = MagicMock()
|
|
mock_repo.git.ls_files.return_value = "./file1.txt\n./file2.py"
|
|
coder.repo = mock_repo
|
|
|
|
# Call the check_for_file_mentions method
|
|
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
|
|
|
# Check if coder.abs_fnames contains both files
|
|
expected_files = {os.path.abspath("file1.txt"), os.path.abspath("file2.py")}
|
|
self.assertEqual(coder.abs_fnames, expected_files)
|
|
|
|
def test_check_for_ambiguous_filename_mentions_of_longer_paths(self):
|
|
# Mock the IO object
|
|
mock_io = MagicMock()
|
|
|
|
# Initialize the Coder object with the mocked IO and mocked repo
|
|
coder = Coder(io=mock_io, openai_api_key="fake_key")
|
|
|
|
# Mock the git repo
|
|
mock_repo = MagicMock()
|
|
mock_repo.git.ls_files.return_value = "./file1.txt\n./other/file1.txt"
|
|
coder.repo = mock_repo
|
|
|
|
# Call the check_for_file_mentions method
|
|
coder.check_for_file_mentions("Please check file1.txt!")
|
|
|
|
self.assertEqual(coder.abs_fnames, set())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|