From 89c412ccfebbcc3970f3ee34e8ccaf9fbef98095 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 May 2023 05:18:26 -0700 Subject: [PATCH] aider: Added a new test method `test_main_pretty_from_env` to check if the `pretty` option is set to `False` by creating a temporary directory, writing a `.env` file with `AIDER_PRETTY=false`, and then calling `main` with no arguments. # Context: USER: add a test like test_main_args. it should test pretty by making a .env file with AIDER_PRETTY=false and then call main with no args. ASSISTANT: To add a new test for the `pretty` option, you can create a new test method in the `TestMain` class in the `tests/test_main.py` file. Here's the code for the new test: ```python tests/test_main.py <<<<<<< ORIGINAL def test_main_args(self): with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) with patch("aider.main.Coder") as MockCoder: main(["--no-auto-commits"]) _, kwargs = MockCoder.call_args assert kwargs["auto_commits"] is False ======= def test_main_args(self): with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) with patch("aider.main.Coder") as MockCoder: main(["--no-auto-commits"]) _, kwargs = MockCoder.call_args assert kwargs["auto_commits"] is False def test_main_pretty_from_env(self): with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) with open(".env", "w") as env_file: env_file.write("AIDER_PRETTY=false\n") with patch("aider.main.Coder") as MockCoder: main([]) _, kwargs = MockCoder.call_args assert kwargs["pretty"] is False >>>>>>> UPDATED ``` This new test method, `test_main_pretty_from_env`, creates a temporary directory, writes a `.env` file with `AIDER_PRETTY=false`, and then calls `main` with no arguments. It checks if the `pretty` option is set to `False` as expected. --- tests/test_main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 9cd6fd8d7..023ad9be9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -43,6 +43,17 @@ class TestMain(TestCase): _, kwargs = MockCoder.call_args assert kwargs["auto_commits"] is False + def test_main_pretty_from_env(self): + with tempfile.TemporaryDirectory() as temp_dir: + os.chdir(temp_dir) + with open(".env", "w") as env_file: + env_file.write("AIDER_PRETTY=false\n") + + with patch("aider.main.Coder") as MockCoder: + main([]) + _, kwargs = MockCoder.call_args + assert kwargs["pretty"] is False + with patch("aider.main.Coder") as MockCoder: main(["--auto-commits"]) _, kwargs = MockCoder.call_args