62 lines
1.6 KiB
Python
Executable File
62 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Test that all module imports work correctly."""
|
|
|
|
import sys
|
|
import os
|
|
import ast
|
|
|
|
def check_missing_imports():
|
|
"""Check for missing imports that would cause NameError."""
|
|
errors = []
|
|
|
|
# Check engine.py
|
|
engine_path = os.path.join(os.path.dirname(__file__), 'engine.py')
|
|
with open(engine_path, 'r') as f:
|
|
engine_content = f.read()
|
|
|
|
# Parse the file to find all names used
|
|
tree = ast.parse(engine_content)
|
|
|
|
# Collect all names that are used (not defined)
|
|
names_used = set()
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Name):
|
|
names_used.add(node.id)
|
|
|
|
# Check for common missing imports
|
|
common_modules = {
|
|
'random',
|
|
're',
|
|
'json',
|
|
'traceback',
|
|
'datetime',
|
|
'time',
|
|
'os',
|
|
'sys',
|
|
'pathlib',
|
|
'functools',
|
|
'collections',
|
|
'typing',
|
|
'io',
|
|
'string',
|
|
}
|
|
|
|
for module in common_modules:
|
|
if module in names_used and not hasattr(sys.modules.get(module, None), '__file__'):
|
|
# Check if it's used but not imported
|
|
if f'import {module}' not in engine_content and f'from {module} import' not in engine_content:
|
|
errors.append(f"Missing import: {module}")
|
|
|
|
return errors
|
|
|
|
if __name__ == '__main__':
|
|
errors = check_missing_imports()
|
|
if errors:
|
|
print("ERROR: Missing imports detected:")
|
|
for error in errors:
|
|
print(f" - {error}")
|
|
sys.exit(1)
|
|
else:
|
|
print("✓ All imports present")
|
|
sys.exit(0)
|