-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (31 loc) · 1.07 KB
/
utils.py
File metadata and controls
39 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# utils.py
import subprocess
from pathlib import Path
def load_code(path):
with open(path, "r") as f:
return f.read()
def save_code(path, code):
Path(path).parent.mkdir(parents=True, exist_ok=True)
with open(path, "w") as f:
f.write(code)
import pytest
import io
from contextlib import redirect_stdout
def validate_fix_with_tester(algo_name, flag):
"""Run tester.py and return True if fixed code passes all tests, else False."""
# Run tester.py with the algorithm name as argument
result = subprocess.run(
["python", "tester.py", algo_name, flag],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# Capture full output (stdout + stderr)
output = result.stdout + "\n" + result.stderr
for line in output.splitlines():
if "Passed:" in line:
parts = line.split(":")[1].strip().split("/")
passed = int(parts[0])
total = int(parts[1])
print(f"Total test cases passed = {passed}/{total}")
return passed == total, passed, total