From 4928450ccf611b1395a48b421f2c41bdbfc36ec3 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 17:24:29 -0700 Subject: [PATCH] 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. --- tests/test_main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index e69de29bb..b0dbe9ed5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -0,0 +1,14 @@ +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()