refactor: simplify shell command tests and add TODOs for confirm_ask checks

This commit is contained in:
Paul Gauthier 2024-08-27 13:41:20 -07:00 committed by Paul Gauthier (aider)
parent 8735efc2b1
commit 1569995d26

View file

@ -641,42 +641,13 @@ class TestMain(TestCase):
output=DummyOutput(),
)
# Shell commands should not run with --no-suggest-shell-commands
self.assertFalse(Path("no_suggest_file.txt").exists())
# TODO: make sure confirm_ask is not called
def test_apply_shell_commands_with_no_suggest_explicit_approval(self):
with GitTemporaryDirectory():
shell_md = Path("shell.md")
shell_md.write_text("```bash\ntouch explicit_approval_file.txt\n```")
# Simulate user input for explicit approval
input_stream = StringIO("y\n")
main(
["--apply", "shell.md", "--no-suggest-shell-commands"],
input=input_stream,
["--apply", "shell.md", "--yes"],
input=DummyInput(),
output=DummyOutput(),
)
# Shell commands should still not run even with explicit approval
self.assertFalse(Path("explicit_approval_file.txt").exists())
def test_suggest_shell_commands_in_interactive_mode(self):
with GitTemporaryDirectory():
# Create a file with some content
test_file = Path("test_file.txt")
test_file.write_text("Hello, world!")
# Simulate user input
input_stream = StringIO("ls\nexit\n")
# Capture stdout to check if shell command suggestion is printed
with patch("sys.stdout", new=StringIO()) as fake_out:
main(
["--no-suggest-shell-commands"],
input=input_stream,
output=fake_out,
)
# Check that the shell command suggestion is not in the output
self.assertNotIn("Here's how you can run that shell command:", fake_out.getvalue())
# TODO: make sure confirm_ask IS called