mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04:59 +00:00

# Context: USER: I ran this command: pytest tests/test_main.py And got this output: ============================= test session starts ============================== platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0 rootdir: /Users/gauthier/Projects/aider collected 4 items tests/test_main.py F... [100%] =================================== FAILURES =================================== ______________________ TestMain.test_main_no_auto_commits ______________________ self = <tests.test_main.TestMain testMethod=test_main_no_auto_commits> def test_main_no_auto_commits(self): > with unittest.mock.patch("aider.main.Coder") as MockCoder: E NameError: name 'unittest' is not defined tests/test_main.py:37: NameError =========================== short test summary info ============================ FAILED tests/test_main.py::TestMain::test_main_no_auto_commits - NameError: n... ========================= 1 failed, 3 passed in 1.29s ========================== ASSISTANT: It looks like the `unittest` module is not imported in the `tests/test_main.py` file. To fix this issue, you need to add the import statement for the `unittest` module at the beginning of the file. Here's the change: ```python tests/test_main.py <<<<<<< ORIGINAL import os import tempfile from unittest import TestCase from aider.main import main ======= import os import tempfile import unittest from unittest import TestCase from aider.main import main >>>>>>> UPDATED ``` This will import the `unittest` module and resolve the `NameError`.
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
import os
|
|
import tempfile
|
|
import unittest
|
|
from unittest import TestCase
|
|
from aider.main import main
|
|
import subprocess
|
|
from prompt_toolkit.input import create_input
|
|
from io import StringIO
|
|
from prompt_toolkit.output import DummyOutput
|
|
|
|
|
|
class TestMain(TestCase):
|
|
def test_main_with_empty_dir_no_files_on_command(self):
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
os.chdir(temp_dir)
|
|
pipe_input = create_input(StringIO(""))
|
|
main([], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
|
|
def test_main_with_empty_dir_new_file(self):
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
os.chdir(temp_dir)
|
|
pipe_input = create_input(StringIO(""))
|
|
main(["foo.txt"], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
self.assertTrue(os.path.exists("foo.txt"))
|
|
|
|
def test_main_with_empty_git_dir_new_file(self):
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
os.chdir(temp_dir)
|
|
subprocess.run(["git", "init"], cwd=temp_dir)
|
|
pipe_input = create_input(StringIO(""))
|
|
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
self.assertTrue(os.path.exists("foo.txt"))
|
|
|
|
def test_main_no_auto_commits(self):
|
|
with unittest.mock.patch("aider.main.Coder") as MockCoder:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
os.chdir(temp_dir)
|
|
subprocess.run(["git", "init"], cwd=temp_dir)
|
|
pipe_input = create_input(StringIO(""))
|
|
main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
|
|
pipe_input.close()
|
|
|
|
mock_coder_instance = MockCoder.return_value
|
|
self.assertFalse(mock_coder_instance.auto_commits)
|