style: format code and improve readability in test_io.py

This commit is contained in:
Paul Gauthier (aider) 2024-09-28 15:28:14 -07:00
parent d5b8a15410
commit c2b48b5256

View file

@ -20,17 +20,19 @@ class TestInputOutput(unittest.TestCase):
def test_autocompleter_get_command_completions(self): def test_autocompleter_get_command_completions(self):
# Step 3: Mock the commands object # Step 3: Mock the commands object
commands = MagicMock() commands = MagicMock()
commands.get_commands.return_value = ['/help', '/add', '/drop'] commands.get_commands.return_value = ["/help", "/add", "/drop"]
commands.matching_commands.side_effect = lambda inp: ( commands.matching_commands.side_effect = lambda inp: (
[cmd for cmd in commands.get_commands() if cmd.startswith(inp.strip().split()[0])], [cmd for cmd in commands.get_commands() if cmd.startswith(inp.strip().split()[0])],
inp.strip().split()[0], inp.strip().split()[0],
' '.join(inp.strip().split()[1:]), " ".join(inp.strip().split()[1:]),
) )
commands.get_raw_completions.return_value = None commands.get_raw_completions.return_value = None
commands.get_completions.side_effect = lambda cmd: ['file1.txt', 'file2.txt'] if cmd == '/add' else None commands.get_completions.side_effect = lambda cmd: (
["file1.txt", "file2.txt"] if cmd == "/add" else None
)
# Step 4: Create an instance of AutoCompleter # Step 4: Create an instance of AutoCompleter
root = '' root = ""
rel_fnames = [] rel_fnames = []
addable_rel_fnames = [] addable_rel_fnames = []
autocompleter = AutoCompleter( autocompleter = AutoCompleter(
@ -38,15 +40,15 @@ class TestInputOutput(unittest.TestCase):
rel_fnames=rel_fnames, rel_fnames=rel_fnames,
addable_rel_fnames=addable_rel_fnames, addable_rel_fnames=addable_rel_fnames,
commands=commands, commands=commands,
encoding='utf-8', encoding="utf-8",
) )
# Step 5: Set up test cases # Step 5: Set up test cases
test_cases = [ test_cases = [
# Input text, Expected completion texts # Input text, Expected completion texts
('/', ['/help', '/add', '/drop']), ("/", ["/help", "/add", "/drop"]),
('/a', ['/add']), ("/a", ["/add"]),
('/add ', ['file1.txt', 'file2.txt']), ("/add ", ["file1.txt", "file2.txt"]),
] ]
# Step 6: Iterate through test cases # Step 6: Iterate through test cases
@ -56,12 +58,14 @@ class TestInputOutput(unittest.TestCase):
words = text.strip().split() words = text.strip().split()
# Call get_command_completions # Call get_command_completions
completions = list(autocompleter.get_command_completions( completions = list(
document, autocompleter.get_command_completions(
complete_event, document,
text, complete_event,
words, text,
)) words,
)
)
# Extract completion texts # Extract completion texts
completion_texts = [comp.text for comp in completions] completion_texts = [comp.text for comp in completions]
@ -255,6 +259,5 @@ class TestInputOutput(unittest.TestCase):
self.assertNotIn(("Do you want to proceed?", None), io.never_prompts) self.assertNotIn(("Do you want to proceed?", None), io.never_prompts)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()