mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
import os
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from aider.io import AutoCompleter, InputOutput
|
|
from aider.utils import ChdirTemporaryDirectory
|
|
|
|
|
|
class TestInputOutput(unittest.TestCase):
|
|
def test_no_color_environment_variable(self):
|
|
with patch.dict(os.environ, {"NO_COLOR": "1"}):
|
|
io = InputOutput()
|
|
self.assertFalse(io.pretty)
|
|
|
|
def test_autocompleter_with_non_existent_file(self):
|
|
root = ""
|
|
rel_fnames = ["non_existent_file.txt"]
|
|
addable_rel_fnames = []
|
|
commands = None
|
|
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
|
|
self.assertEqual(autocompleter.words, set(rel_fnames))
|
|
|
|
def test_autocompleter_with_unicode_file(self):
|
|
with ChdirTemporaryDirectory():
|
|
root = ""
|
|
fname = "file.py"
|
|
rel_fnames = [fname]
|
|
addable_rel_fnames = []
|
|
commands = None
|
|
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
|
|
self.assertEqual(autocompleter.words, set(rel_fnames))
|
|
|
|
Path(fname).write_text("def hello(): pass\n")
|
|
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
|
|
self.assertEqual(autocompleter.words, set(rel_fnames + ["hello"]))
|
|
|
|
encoding = "utf-16"
|
|
some_content_which_will_error_if_read_with_encoding_utf8 = "ÅÍÎÏ".encode(encoding)
|
|
with open(fname, "wb") as f:
|
|
f.write(some_content_which_will_error_if_read_with_encoding_utf8)
|
|
|
|
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
|
|
self.assertEqual(autocompleter.words, set(rel_fnames))
|
|
|
|
@patch("aider.io.PromptSession")
|
|
def test_get_input_is_a_directory_error(self, MockPromptSession):
|
|
# Mock the PromptSession to simulate user input
|
|
mock_session = MockPromptSession.return_value
|
|
mock_session.prompt.return_value = "test input"
|
|
|
|
io = InputOutput(pretty=False) # Windows tests throw UnicodeDecodeError
|
|
root = "/"
|
|
rel_fnames = ["existing_file.txt"]
|
|
addable_rel_fnames = ["new_file.txt"]
|
|
commands = MagicMock()
|
|
|
|
# Simulate IsADirectoryError
|
|
with patch("aider.io.open", side_effect=IsADirectoryError):
|
|
result = io.get_input(root, rel_fnames, addable_rel_fnames, commands)
|
|
self.assertEqual(result, "test input")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|