-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_test_syntax.py
More file actions
executable file
·56 lines (48 loc) · 1.54 KB
/
check_test_syntax.py
File metadata and controls
executable file
·56 lines (48 loc) · 1.54 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
#!/usr/bin/env python3
"""
Syntax checker for test files.
"""
import ast
import os
import sys
def check_syntax(file_path):
"""Check syntax of a Python file."""
try:
with open(file_path, 'r') as f:
source = f.read()
ast.parse(source)
print(f"✓ {file_path} - Syntax OK")
return True
except SyntaxError as e:
print(f"✗ {file_path} - Syntax Error: {e}")
return False
except Exception as e:
print(f"✗ {file_path} - Error: {e}")
return False
def main():
"""Check syntax of all test files."""
test_dir = os.path.join(os.path.dirname(__file__), 'tests')
if not os.path.exists(test_dir):
print(f"Test directory not found: {test_dir}")
return False
success = True
# Check test files
for filename in os.listdir(test_dir):
if filename.startswith('test_') and filename.endswith('.py'):
file_path = os.path.join(test_dir, filename)
if not check_syntax(file_path):
success = False
# Check test runner
runner_path = os.path.join(os.path.dirname(__file__), 'run_tests.py')
if os.path.exists(runner_path):
if not check_syntax(runner_path):
success = False
# Check conftest
conftest_path = os.path.join(test_dir, 'conftest.py')
if os.path.exists(conftest_path):
if not check_syntax(conftest_path):
success = False
return success
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)