mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 00:05:01 +00:00
Armor AutoCompleter against unicode errors #305
This commit is contained in:
parent
efb3f03a62
commit
f3d3815201
3 changed files with 42 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
|||
import os
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from aider.io import AutoCompleter, InputOutput
|
||||
from tests.utils import ChdirTemporaryDirectory
|
||||
|
||||
|
||||
class TestInputOutput(unittest.TestCase):
|
||||
|
@ -19,6 +21,28 @@ class TestInputOutput(unittest.TestCase):
|
|||
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))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue