| 73 | return result |
| 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 | """ |
| 103 | Evaluates the implementation on Human-Eval Python. |
| 104 | |
| 105 | probably should be written in a dataset-agnostic way but not now |
| 106 | """ |
| 107 | |
| 108 | code = f"""{func} |
| 109 | |
| 110 | {test} |
| 111 | |
| 112 | check({name}) |
| 113 | """ |
| 114 | try: |
| 115 | function_with_timeout(exec, (code, globals()), timeout) |
| 116 | return True |
| 117 | except Exception: |
| 118 | return False |
| 119 |
no outgoing calls
no test coverage detected