aider/tests/test_main.py
Paul Gauthier fa2f76c107 aider: Added subprocess module to run git init in the temporary directory before calling main in test_main_with_empty_git_dir_new_file.
# Context:
USER: in test_main_with_empty_git_dir_new_file, run git init in the new dir before calling main
ASSISTANT: To run `git init` in the new directory before calling `main`, you can use the `subprocess` module to execute the command. Here's the change you need to make in the `test_main_with_empty_git_dir_new_file` function:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            with open(os.devnull, 'r') as dev_null:
                save_stdin = sys.stdin
                sys.stdin = dev_null
                main(['foo.txt'])
                sys.stdin = save_stdin
=======
    import subprocess

    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            subprocess.run(["git", "init"])
            with open(os.devnull, 'r') as dev_null:
                save_stdin = sys.stdin
                sys.stdin = dev_null
                main(['foo.txt'])
                sys.stdin = save_stdin
>>>>>>> UPDATED
```

This change imports the `subprocess` module and adds the `subprocess.run(["git", "init"])` line to run `git init` in the temporary directory before calling `main`.
2023-05-11 17:36:33 -07:00

37 lines
1.2 KiB
Python

import os
import sys
import tempfile
from unittest import TestCase
from aider.main import main
class TestMain(TestCase):
def test_main_with_empty_dir_no_files_on_command(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
with open(os.devnull, 'r') as dev_null:
save_stdin = sys.stdin
sys.stdin = dev_null
main()
sys.stdin = save_stdin
def test_main_with_empty_dir_new_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
with open(os.devnull, 'r') as dev_null:
save_stdin = sys.stdin
sys.stdin = dev_null
main(['foo.txt'])
sys.stdin = save_stdin
self.assertTrue(os.path.exists('foo.txt'))
import subprocess
def test_main_with_empty_git_dir_new_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
subprocess.run(["git", "init"])
with open(os.devnull, 'r') as dev_null:
save_stdin = sys.stdin
sys.stdin = dev_null
main(['foo.txt'])
sys.stdin = save_stdin