Commit graph

53 commits

Author SHA1 Message Date
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