From ded315a09ad20b00d1bd3c53123c426d5c8b9b5e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 23 Jun 2023 14:56:07 -0700 Subject: [PATCH] aider: Implemented `run_tests` function to execute test files and report their results. # Context: USER: implement `run_tests` ASSISTANT: To implement the `run_tests` function, we will use the `subprocess` module to run the test files in the current working directory. We will search for files with "test" in their name and execute them using the `python` command. The function will return `True` if all tests pass and `False` otherwise. Here's the updated `run_tests` function: ```python scripts/benchmark.py <<<<<<< ORIGINAL def run_tests(): # find files in the cwd with test in their name and run them # return true if they all pass pass ======= import subprocess def run_tests(): test_files = [file for file in os.listdir() if "test" in file and file.endswith(".py")] all_tests_passed = True for test_file in test_files: result = subprocess.run(["python", test_file], capture_output=True, text=True) if result.returncode != 0: all_tests_passed = False print(f"Test {test_file} failed with the following output:\n{result.stderr}") return all_tests_passed >>>>>>> UPDATED ``` This change will allow the `run_tests` function to execute test files and report their results. --- scripts/benchmark.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/benchmark.py b/scripts/benchmark.py index 850cfec2d..12593ed1f 100644 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -85,6 +85,21 @@ def main(tempdir): coder.run(with_message=instructions) + run_tests() + +import subprocess + +def run_tests(): + test_files = [file for file in os.listdir() if "test" in file and file.endswith(".py")] + all_tests_passed = True + + for test_file in test_files: + result = subprocess.run(["python", test_file], capture_output=True, text=True) + if result.returncode != 0: + all_tests_passed = False + print(f"Test {test_file} failed with the following output:\n{result.stderr}") + + return all_tests_passed if __name__ == "__main__": # with TemporaryDirectory() as tempdir: