-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_gen_final.py
More file actions
37 lines (30 loc) · 1.24 KB
/
fix_gen_final.py
File metadata and controls
37 lines (30 loc) · 1.24 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
#!/usr/bin/env python3
"""
Properly fix the generator to handle newlines in test code
"""
import re
with open('generate_all_tests.py', 'r') as f:
content = f.read()
# Find and replace the problematic section
# The issue is that {test_code} contains literal \n strings that need to be split and indented
pattern = r"( for i, \(name, test_code\) in enumerate\(s\['tests'\], 1\):.*?code \+= f''')"
replacement = r""" for i, (name, test_code) in enumerate(s['tests'], 1):
# Properly indent multi-line test code
test_lines = test_code.split('\\n')
indented_test = '\\n '.join(test_lines)
code += f'''"""
# Replace the section
content_fixed = re.sub(
r"for i, \(name, test_code\) in enumerate\(s\['tests'\], 1\):\n code \+= f'''",
"""for i, (name, test_code) in enumerate(s['tests'], 1):
# Properly indent multi-line test code
test_lines = test_code.split('\\\\n')
indented_test = '\\\\n '.join(test_lines)
code += f'''""",
content
)
# Also replace {test_code} with {indented_test}
content_fixed = content_fixed.replace('{indented_code}', '{indented_test}')
with open('generate_all_tests.py', 'w') as f:
f.write(content_fixed)
print("Generator fixed!")