MCPcopy Index your code
hub / github.com/FastMAS/KVCOMM / execute

Method execute

KVCOMM/tools/coding/python_executor.py:76–99  ·  view source on GitHub ↗
(self, func: str, tests: List[str], timeout: int = 5, verbose: bool = True)

Source from the content-addressed store, hash-verified

74
75class 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 """

Callers

nothing calls this directly

Calls 3

function_with_timeoutFunction · 0.90
get_outputFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected