From e500f8e37fc13cc604c69a2e6b88768a0d83e5eb Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 17:33:59 -0700 Subject: [PATCH] wip: Refactor main function to include tests for empty directory with no files and new file creation. --- tests/test_main.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 5c876684a..e699d3684 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,9 +5,20 @@ from unittest import TestCase from aider.main import main class TestMain(TestCase): - def test_main_with_dev_null(self): + 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: - sys.stdin.close() - main() + 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