-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfix_remaining_tests.py
More file actions
executable file
·122 lines (96 loc) · 3.9 KB
/
fix_remaining_tests.py
File metadata and controls
executable file
·122 lines (96 loc) · 3.9 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""
Tool to fix remaining NorthwindMiscellaneousQueryMySqlTest failures.
This script:
1. Runs each failing test individually
2. Captures the actual MySQL-generated SQL from error output
3. Updates the test file with correct SQL assertions
Usage:
python3 fix_remaining_tests.py [--start-index INDEX] [--batch-size SIZE]
"""
import re
import subprocess
import sys
import time
def run_single_test(test_name):
"""Run a single test and capture output"""
cmd = [
"dotnet", "test",
"test/EFCore.MySql.FunctionalTests",
"-c", "Debug",
"--no-build",
"--filter", f"FullyQualifiedName~NorthwindMiscellaneousQueryMySqlTest.{test_name}",
"--logger", "console;verbosity=detailed"
]
result = subprocess.run(
cmd,
capture_output=True,
text=True,
env={"PATH": "/home/runner/.dotnet:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}
)
return result.stdout + result.stderr
def extract_actual_sql(output):
"""Extract actual SQL from test failure output"""
# Look for Actual SQL in detailed output
patterns = [
r'Actual:\s+"([^"]+(?:\\n[^"]*)*)"',
r'Collection: \["([^"]+(?:\\n[^"]*)*)"'
]
for pattern in patterns:
match = re.search(pattern, output, re.DOTALL)
if match:
sql = match.group(1)
# Decode escaped newlines and other escapes
sql = sql.replace('\\n', '\n')
sql = sql.replace('\\"', '"')
sql = sql.replace('\\\\', '\\')
# Remove truncation indicator
sql = sql.replace('···', '')
return sql.strip()
return None
def update_test_file(test_name, sql):
"""Update test file with correct SQL"""
test_file = 'test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs'
with open(test_file, 'r') as f:
content = f.read()
# Find and replace the AssertSql for this test
# Pattern matches test with existing SQL or empty AssertSql()
pattern = rf'(public override async Task {test_name}\(bool async\)[^{{]*\{{[^}}]*AssertSql\()(?:\(\);|"""[^"]*"""\);)'
replacement = rf'\1(\n"""\n{sql}\n""");'
new_content, count = re.subn(pattern, replacement, content, flags=re.MULTILINE | re.DOTALL)
if count > 0:
with open(test_file, 'w') as f:
f.write(new_content)
return True
return False
def main():
import argparse
parser = argparse.ArgumentParser(description='Fix remaining test SQL assertions')
parser.add_argument('--start-index', type=int, default=0, help='Start index in failing tests list')
parser.add_argument('--batch-size', type=int, default=10, help='Number of tests to process')
args = parser.parse_args()
# Read failing tests
with open('/tmp/test_output/failing_tests.txt', 'r') as f:
failing_tests = [line.strip() for line in f if line.strip() and not line.startswith('Check_all')]
start = args.start_index
end = min(start + args.batch_size, len(failing_tests))
print(f"Processing tests {start} to {end-1} (total {len(failing_tests)})")
for i, test_name in enumerate(failing_tests[start:end], start=start):
print(f"\n[{i+1}/{len(failing_tests)}] Processing {test_name}...")
# Run test
output = run_single_test(test_name)
# Extract SQL
sql = extract_actual_sql(output)
if sql:
# Update file
if update_test_file(test_name, sql):
print(f" ✓ Updated with SQL ({len(sql)} chars)")
else:
print(f" ✗ Could not update file")
else:
print(f" ⚠ Could not extract SQL")
# Small delay to avoid overwhelming the system
time.sleep(0.5)
print(f"\nProcessing complete")
if __name__ == '__main__':
main()