Commit graph

18 commits

Author SHA1 Message Date
Paul Gauthier
9a413d351d black formatting 2023-05-17 18:24:35 -07:00
Paul Gauthier
de69a3095a aider: Removed all the save_stdin stuff.
# Context:
USER: remove all the save_stdin stuff
ASSISTANT: ```python
tests/test_main.py
<<<<<<< ORIGINAL
            save_stdin = sys.stdin
            sys.stdin = pipe_input
            main([], input=pipe_input, output=DummyOutput())
            sys.stdin = save_stdin
=======
            main([], input=pipe_input, output=DummyOutput())
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            save_stdin = sys.stdin
            sys.stdin = pipe_input
            main(["foo.txt"], input=pipe_input, output=DummyOutput())
            sys.stdin = save_stdin
=======
            main(["foo.txt"], input=pipe_input, output=DummyOutput())
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            save_stdin = sys.stdin
            sys.stdin = pipe_input
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
            sys.stdin = save_stdin
=======
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
>>>>>>> UPDATED
```
2023-05-17 16:13:01 -07:00
Paul Gauthier
4bb043f5c0 aider: Replaced the usage of create_pipe_input() with create_input(StringIO('')) in the test cases.
# Context:
USER: try using create_input(StringIO('')) in the tests
ASSISTANT: I understand that you want to use `create_input(StringIO(''))` in the tests. However, I need more information about which test cases you want to apply this change to and how you want to use it. Please provide more details or examples.
USER: the ones that currently use create_pipe_input()
ASSISTANT: I see that you want to replace `create_pipe_input()` with `create_input(StringIO(''))` in the test cases. Here are the changes for the `tests/test_main.py` file:

```python
tests/test_main.py
<<<<<<< ORIGINAL
from prompt_toolkit.input import create_pipe_input
=======
from prompt_toolkit.input import create_input
from io import StringIO
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            pipe_input = create_pipe_input()
=======
            pipe_input = create_input(StringIO(''))
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            pipe_input = create_pipe_input()
=======
            pipe_input = create_input(StringIO(''))
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            pipe_input = create_pipe_input()
=======
            pipe_input = create_input(StringIO(''))
>>>>>>> UPDATED
```

These changes will replace the usage of `create_pipe_input()` with `create_input(StringIO(''))` in the test cases.
2023-05-13 07:53:28 -07:00
Paul Gauthier
6724fcd897 Added import statement for sys module in test_main.py. 2023-05-13 07:09:50 -07:00
Paul Gauthier
c177e29899 aider: Replaced usage of /dev/null with prompt_toolkit's input mocking functions in tests.
# Context:
USER: instead of using /dev/null to send no output in the main tests, can we use the prompt_toolkit input mocking functions?
ASSISTANT: Yes, we can use the `prompt_toolkit.input` module to mock the input in the tests. Here's how to modify the `tests/test_main.py` file:

```python
tests/test_main.py
<<<<<<< ORIGINAL
import os
import sys
import tempfile
from unittest import TestCase
from aider.main import main
import subprocess
=======
import os
import tempfile
from unittest import TestCase
from aider.main import main
import subprocess
from prompt_toolkit.input import create_pipe_input
from prompt_toolkit.output import DummyOutput
>>>>>>> UPDATED
```

Now, update the tests to use the `create_pipe_input` and `DummyOutput`:

```python
tests/test_main.py
<<<<<<< ORIGINAL
            with open(os.devnull, "r") as dev_null:
                save_stdin = sys.stdin
                sys.stdin = dev_null
                main([])
                sys.stdin = save_stdin
=======
            pipe_input = create_pipe_input()
            save_stdin = sys.stdin
            sys.stdin = pipe_input
            main([], input=pipe_input, output=DummyOutput())
            sys.stdin = save_stdin
            pipe_input.close()
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            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"))
=======
            pipe_input = create_pipe_input()
            save_stdin = sys.stdin
            sys.stdin = pipe_input
            main(["foo.txt"], input=pipe_input, output=DummyOutput())
            sys.stdin = save_stdin
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
            with open(os.devnull, "r") as dev_null:
                save_stdin = sys.stdin
                sys.stdin = dev_null
                main(["--yes", "foo.txt"])
                sys.stdin = save_stdin
                self.assertTrue(os.path.exists("foo.txt"))
=======
            pipe_input = create_pipe_input()
            save_stdin = sys.stdin
            sys.stdin = pipe_input
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
            sys.stdin = save_stdin
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))
>>>>>>> UPDATED
```

These changes will replace the usage of `/dev/null` with `prompt_toolkit`'s input mocking functions.
2023-05-13 07:09:03 -07:00
Paul Gauthier
5e593eb631 handle no args properly 2023-05-11 20:56:09 -07:00
Paul Gauthier
d44f732d3b main should use argv if args not provided 2023-05-11 20:34:46 -07:00
Paul Gauthier
3b0c5132f2 aider: Passed temp_dir as the cwd to subprocess in test_main_with_empty_git_dir_new_file.
# Context:
USER: pass temp_dir as the cwd to subprocess in test_main_with_empty_git_dir_new_file
ASSISTANT: Here's the change to pass `temp_dir` as the `cwd` to `subprocess` in the `test_main_with_empty_git_dir_new_file` function:

```python
tests/test_main.py
<<<<<<< ORIGINAL
            subprocess.run(["git", "init"])
=======
            subprocess.run(["git", "init"], cwd=temp_dir)
>>>>>>> UPDATED
```
2023-05-11 17:52:34 -07:00
Paul Gauthier
8a60462167 finished adding --yes 2023-05-11 17:51:50 -07:00
Paul Gauthier
09fbbc0dae wip: Added import subprocess to test_main.py. 2023-05-11 17:39:15 -07:00
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
Paul Gauthier
7a29a2911a aider: Added assertion to confirm that foo.txt exists after main exits in test_main_with_empty_dir_new_file.
# Context:
USER: in test_main_with_empty_dir_new_file, confirm that foo.txt exists after main exists
ASSISTANT: To confirm that `foo.txt` exists after `main` exits, you can add an assertion in the `test_main_with_empty_dir_new_file` test case. Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
                main(['foo.txt'])
                sys.stdin = save_stdin
=======
                main(['foo.txt'])
                sys.stdin = save_stdin
                self.assertTrue(os.path.exists('foo.txt'))
>>>>>>> UPDATED
```
2023-05-11 17:34:35 -07:00
Paul Gauthier
e500f8e37f wip: Refactor main function to include tests for empty directory with no files and new file creation. 2023-05-11 17:33:59 -07:00
Paul Gauthier
00b0369282 aider: Replaced usage of redirect_stdin with closing stdin before calling main.
# Context:
USER: ImportError: cannot import name 'redirect_stdin' from 'contextlib'. Maybe just close stdin before calling main?
ASSISTANT: To fix the ImportError, we can replace the usage of `redirect_stdin` with closing stdin before calling `main`. Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
from contextlib import redirect_stdin
=======
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
    with open(os.devnull, 'r') as dev_null:
        with redirect_stdin(dev_null):
                    main()
=======
    with open(os.devnull, 'r') as dev_null:
        sys.stdin.close()
        main()
>>>>>>> UPDATED
```
2023-05-11 17:26:48 -07:00
Paul Gauthier
ac8376c5bc wip: Changed import from redirect_stdout to redirect_stdin in test_main.py. 2023-05-11 17:25:32 -07:00
Paul Gauthier
fe5e313a75 aider: Replaced redirect_stdout with redirect_stdin and opened os.devnull in read mode ('r') instead of write mode ('w').
# Context:
USER: stdin not stdout
ASSISTANT: I apologize for the confusion. To redirect stdin instead of stdout, we need to use `contextlib.redirect_stdin` instead of `contextlib.redirect_stdout`. Here's the updated code change for tests/test_main.py:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    with open(os.devnull, 'w') as dev_null:
        with redirect_stdout(dev_null):
=======
    with open(os.devnull, 'r') as dev_null:
        with redirect_stdin(dev_null):
>>>>>>> UPDATED
            main()
```

This code change replaces `redirect_stdout` with `redirect_stdin` and opens os.devnull in read mode ('r') instead of write mode ('w').
2023-05-11 17:24:57 -07:00
Paul Gauthier
4928450ccf aider: Added a test case for main which creates a temporary directory, changes the current working directory, and invokes the main function with /dev/null piped to stdout.
# Context:
USER: add a test case for main which makes a new empty dir, makes it the cwd and invokes main() with /dev/null piped to stdin.
ASSISTANT: To add a test case for main, we need to import the necessary modules, create a temporary directory, change the current working directory, and invoke the main function with /dev/null piped to stdin. Here's the code change for tests/test_main.py:

```python
tests/test_main.py
<<<<<<< ORIGINAL

=======
import os
import sys
import tempfile
from contextlib import redirect_stdout
from unittest import TestCase
from aider.main import main

class TestMain(TestCase):
    def test_main_with_dev_null(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            with open(os.devnull, 'w') as dev_null:
                with redirect_stdout(dev_null):
                    main()
>>>>>>> UPDATED
```

This code change imports the necessary modules, creates a new test class `TestMain`, and adds a test method `test_main_with_dev_null`. The test method creates a temporary directory, changes the current working directory to the temporary directory, and invokes the `main` function with /dev/null piped to stdout.
2023-05-11 17:24:29 -07:00
Paul Gauthier
db7aa7cdf1 aider: Created and added tests/test_main.py to git. 2023-05-11 17:17:50 -07:00