aider/tests/test_main.py
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

13 lines
333 B
Python

import os
import sys
import tempfile
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, 'r') as dev_null:
sys.stdin.close()
main()