-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_tests.py
More file actions
86 lines (69 loc) · 2.12 KB
/
validate_tests.py
File metadata and controls
86 lines (69 loc) · 2.12 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
#!/usr/bin/env python3
"""
Grid Sampler CUDA 测试验证脚本
验证所有测试文件的基本语法和导入
"""
import sys
import os
import importlib.util
# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def validate_test_file(file_path):
"""验证测试文件"""
print(f"验证 {file_path}...")
if not os.path.exists(file_path):
print(f" ❌ 文件不存在: {file_path}")
return False
try:
# 尝试编译文件
with open(file_path, 'r', encoding='utf-8') as f:
source = f.read()
compile(source, file_path, 'exec')
print(f" ✓ 语法检查通过")
# 尝试导入模块
spec = importlib.util.spec_from_file_location("test_module", file_path)
if spec is None:
print(f" ❌ 无法创建模块规范")
return False
module = importlib.util.module_from_spec(spec)
if module is None:
print(f" ❌ 无法创建模块")
return False
# 不执行模块,只检查语法
print(f" ✓ 导入检查通过")
return True
except SyntaxError as e:
print(f" ❌ 语法错误: {e}")
return False
except Exception as e:
print(f" ❌ 其他错误: {e}")
return False
def main():
"""验证所有测试文件"""
print("Grid Sampler CUDA 测试验证")
print("=" * 40)
# 测试文件列表
test_files = [
"test_precision.py",
"test_edge_cases.py",
"test_align_corners.py",
"test_reference_comparison.py",
"test_extreme_values.py",
"run_all_precision_tests.py",
]
passed = 0
total = len(test_files)
for test_file in test_files:
if validate_test_file(test_file):
passed += 1
print()
print("验证结果:")
print(f" 通过: {passed}/{total}")
if passed == total:
print("🎉 所有测试文件验证通过!")
return 0
else:
print(f"❌ {total - passed} 个文件验证失败")
return 1
if __name__ == "__main__":
exit(main())