mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
Use DummyInput in tests
This commit is contained in:
parent
9aaee49c51
commit
b31dc2ac71
1 changed files with 11 additions and 33 deletions
|
@ -5,7 +5,7 @@ import tempfile
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from prompt_toolkit.input import create_pipe_input
|
from prompt_toolkit.input import DummyInput
|
||||||
from prompt_toolkit.output import DummyOutput
|
from prompt_toolkit.output import DummyOutput
|
||||||
|
|
||||||
from aider.main import main
|
from aider.main import main
|
||||||
|
@ -27,75 +27,53 @@ class TestMain(TestCase):
|
||||||
self.patcher.stop()
|
self.patcher.stop()
|
||||||
|
|
||||||
def test_main_with_empty_dir_no_files_on_command(self):
|
def test_main_with_empty_dir_no_files_on_command(self):
|
||||||
with create_pipe_input() as pipe_input:
|
main([], input=DummyInput(), output=DummyOutput())
|
||||||
pipe_input.send_text("/exit\n")
|
|
||||||
try:
|
|
||||||
main([], input=pipe_input, output=DummyOutput())
|
|
||||||
except SystemExit:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_main_with_empty_dir_new_file(self):
|
def test_main_with_empty_dir_new_file(self):
|
||||||
with create_pipe_input() as pipe_input:
|
main(["foo.txt"], input=DummyInput(), output=DummyOutput())
|
||||||
pipe_input.send_text("/exit\n")
|
|
||||||
try:
|
|
||||||
main(["foo.txt"], input=pipe_input, output=DummyOutput())
|
|
||||||
except SystemExit:
|
|
||||||
pass
|
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
self.assertTrue(os.path.exists("foo.txt"))
|
||||||
|
|
||||||
def test_main_with_empty_git_dir_new_file(self):
|
def test_main_with_empty_git_dir_new_file(self):
|
||||||
subprocess.run(["git", "init"])
|
subprocess.run(["git", "init"])
|
||||||
subprocess.run(["git", "config", "user.email", "dummy@example.com"])
|
subprocess.run(["git", "config", "user.email", "dummy@example.com"])
|
||||||
subprocess.run(["git", "config", "user.name", "Dummy User"])
|
subprocess.run(["git", "config", "user.name", "Dummy User"])
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--yes", "foo.txt"], input=DummyInput(), output=DummyOutput())
|
||||||
pipe_input.send_text("/exit\n")
|
|
||||||
try:
|
|
||||||
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
|
|
||||||
except SystemExit:
|
|
||||||
pass
|
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
self.assertTrue(os.path.exists("foo.txt"))
|
||||||
|
|
||||||
def test_main_args(self):
|
def test_main_args(self):
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--no-auto-commits"], input=DummyInput())
|
||||||
main(["--no-auto-commits"], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["auto_commits"] is False
|
assert kwargs["auto_commits"] is False
|
||||||
|
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--auto-commits"], input=DummyInput())
|
||||||
main(["--auto-commits"], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["auto_commits"] is True
|
assert kwargs["auto_commits"] is True
|
||||||
|
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main([], input=DummyInput())
|
||||||
main([], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["dirty_commits"] is True
|
assert kwargs["dirty_commits"] is True
|
||||||
assert kwargs["auto_commits"] is True
|
assert kwargs["auto_commits"] is True
|
||||||
assert kwargs["pretty"] is True
|
assert kwargs["pretty"] is True
|
||||||
|
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--no-pretty"], input=DummyInput())
|
||||||
main(["--no-pretty"], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["pretty"] is False
|
assert kwargs["pretty"] is False
|
||||||
|
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--pretty"], input=DummyInput())
|
||||||
main(["--pretty"], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["pretty"] is True
|
assert kwargs["pretty"] is True
|
||||||
|
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--no-dirty-commits"], input=DummyInput())
|
||||||
main(["--no-dirty-commits"], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["dirty_commits"] is False
|
assert kwargs["dirty_commits"] is False
|
||||||
|
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
with create_pipe_input() as pipe_input:
|
main(["--dirty-commits"], input=DummyInput())
|
||||||
main(["--dirty-commits"], input=pipe_input)
|
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
assert kwargs["dirty_commits"] is True
|
assert kwargs["dirty_commits"] is True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue