(self, func: str, tests: List[str], timeout: int = 5, verbose: bool = True)
| 74 | |
| 75 | class PyExecutor(Executor): |
| 76 | def execute(self, func: str, tests: List[str], timeout: int = 5, verbose: bool = True) -> ExecuteResult: |
| 77 | |
| 78 | imports = 'from typing import *' |
| 79 | func_test_list = [f'{imports}\n{func}\n{test}' for test in tests] |
| 80 | |
| 81 | |
| 82 | success_tests = [] |
| 83 | failed_tests = [] |
| 84 | is_passing = True |
| 85 | num_tests = len(func_test_list) |
| 86 | for i in range(num_tests): |
| 87 | try: |
| 88 | function_with_timeout(exec, (func_test_list[i], globals()), timeout) |
| 89 | success_tests.append(tests[i]) |
| 90 | except Exception: |
| 91 | output = get_output(func, tests[i], timeout=timeout) |
| 92 | failed_tests.append(f"{tests[i]} # output: {output}") |
| 93 | is_passing = False |
| 94 | |
| 95 | state = [test in success_tests for test in tests] |
| 96 | |
| 97 | feedback = "Tests passed:\n" + "\n".join(success_tests) + "\n\nTests failed:" |
| 98 | feedback += "\n" + "\n".join(failed_tests) |
| 99 | return is_passing, feedback, tuple(state) |
| 100 | |
| 101 | def evaluate(self, name: str, func: str, test: str, timeout: int = 5) -> bool: |
| 102 | """ |
nothing calls this directly
no test coverage detected