aider/tests/test_main.py
Paul Gauthier ca752f37af aider: Import unittest module in tests/test_main.py.
# 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`.
2023-05-27 04:36:54 -07:00

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)