style: Format test_io.py

This commit is contained in:
Paul Gauthier (aider) 2025-05-08 09:36:20 -07:00
parent 1307215b8f
commit f31128706d

View file

@ -5,9 +5,9 @@ from unittest.mock import MagicMock, patch
from prompt_toolkit.completion import CompleteEvent
from prompt_toolkit.document import Document
from rich.text import Text
from aider.dump import dump # noqa: F401
from rich.text import Text
from aider.io import AutoCompleter, ConfirmGroup, InputOutput
from aider.utils import ChdirTemporaryDirectory
@ -483,11 +483,7 @@ class TestInputOutputFormatFiles(unittest.TestCase):
rel_fnames = ["file1.txt", "file[markup].txt", "ro_file.txt"]
rel_read_only_fnames = ["ro_file.txt"]
expected_output = (
"file1.txt\n"
"file[markup].txt\n"
"ro_file.txt (read only)\n"
)
expected_output = "file1.txt\nfile[markup].txt\nro_file.txt (read only)\n"
# Sort the expected lines because the order of editable vs read-only might vary
# depending on internal sorting, but the content should be the same.
# The method sorts editable_files and read_only_files separately.
@ -499,11 +495,13 @@ class TestInputOutputFormatFiles(unittest.TestCase):
# output = "\n".join(read_only_files + editable_files) + "\n"
# Correct expected output based on implementation:
expected_output_lines = sorted([
"ro_file.txt (read only)",
"file1.txt",
"file[markup].txt",
])
expected_output_lines = sorted(
[
"ro_file.txt (read only)",
"file1.txt",
"file[markup].txt",
]
)
expected_output = "\n".join(expected_output_lines) + "\n"
actual_output = io.format_files_for_input(rel_fnames, rel_read_only_fnames)
@ -517,7 +515,9 @@ class TestInputOutputFormatFiles(unittest.TestCase):
@patch("rich.columns.Columns")
@patch("os.path.abspath")
@patch("os.path.join")
def test_format_files_for_input_pretty_true_no_files(self, mock_join, mock_abspath, mock_columns):
def test_format_files_for_input_pretty_true_no_files(
self, mock_join, mock_abspath, mock_columns
):
io = InputOutput(pretty=True, root="test_root")
io.format_files_for_input([], [])
mock_columns.assert_not_called()
@ -525,7 +525,9 @@ class TestInputOutputFormatFiles(unittest.TestCase):
@patch("rich.columns.Columns")
@patch("os.path.abspath")
@patch("os.path.join")
def test_format_files_for_input_pretty_true_editable_only(self, mock_join, mock_abspath, mock_columns):
def test_format_files_for_input_pretty_true_editable_only(
self, mock_join, mock_abspath, mock_columns
):
io = InputOutput(pretty=True, root="test_root")
rel_fnames = ["edit1.txt", "edit[markup].txt"]
@ -544,7 +546,9 @@ class TestInputOutputFormatFiles(unittest.TestCase):
@patch("rich.columns.Columns")
@patch("os.path.abspath")
@patch("os.path.join")
def test_format_files_for_input_pretty_true_readonly_only(self, mock_join, mock_abspath, mock_columns):
def test_format_files_for_input_pretty_true_readonly_only(
self, mock_join, mock_abspath, mock_columns
):
io = InputOutput(pretty=True, root="test_root")
# Mock path functions to ensure rel_path is chosen by the shortener logic
@ -553,7 +557,7 @@ class TestInputOutputFormatFiles(unittest.TestCase):
rel_read_only_fnames = ["ro1.txt", "ro[markup].txt"]
# When all files in chat are read-only
rel_fnames = list(rel_read_only_fnames)
rel_fnames = list(rel_read_only_fnames)
io.format_files_for_input(rel_fnames, rel_read_only_fnames)
@ -561,7 +565,7 @@ class TestInputOutputFormatFiles(unittest.TestCase):
args, _ = mock_columns.call_args
renderables = args[0]
self.assertEqual(len(renderables), 3) # Readonly: + 2 files
self.assertEqual(len(renderables), 3) # Readonly: + 2 files
self.assertIsInstance(renderables[0], Text)
self.assertEqual(renderables[0].plain, "Readonly:")
self.assertIsInstance(renderables[1], Text)
@ -572,7 +576,9 @@ class TestInputOutputFormatFiles(unittest.TestCase):
@patch("rich.columns.Columns")
@patch("os.path.abspath")
@patch("os.path.join")
def test_format_files_for_input_pretty_true_mixed_files(self, mock_join, mock_abspath, mock_columns):
def test_format_files_for_input_pretty_true_mixed_files(
self, mock_join, mock_abspath, mock_columns
):
io = InputOutput(pretty=True, root="test_root")
mock_join.side_effect = lambda *args: "/".join(args)
@ -588,12 +594,17 @@ class TestInputOutputFormatFiles(unittest.TestCase):
# First call for read-only files
args_ro, _ = mock_columns.call_args_list[0]
renderables_ro = args_ro[0]
self.assertEqual(renderables_ro, [Text("Readonly:"), Text("ro1.txt"), Text("ro[markup].txt")])
self.assertEqual(
renderables_ro, [Text("Readonly:"), Text("ro1.txt"), Text("ro[markup].txt")]
)
# Second call for editable files
args_ed, _ = mock_columns.call_args_list[1]
renderables_ed = args_ed[0]
self.assertEqual(renderables_ed, [Text("Editable:"), Text("edit1.txt"), Text("edit[markup].txt")])
self.assertEqual(
renderables_ed, [Text("Editable:"), Text("edit1.txt"), Text("edit[markup].txt")]
)
if __name__ == "__main__":
unittest.main()