Files
claudetools/tests/test_models_import.py
Mike Swanson 06f7617718 feat: Major directory reorganization and cleanup
Reorganized project structure for better maintainability and reduced
disk usage by 95.9% (11 GB -> 451 MB).

Directory Reorganization (85% reduction in root files):
- Created docs/ with subdirectories (deployment, testing, database, etc.)
- Created infrastructure/vpn-configs/ for VPN scripts
- Moved 90+ files from root to organized locations
- Archived obsolete documentation (context system, offline mode, zombie debugging)
- Moved all test files to tests/ directory
- Root directory: 119 files -> 18 files

Disk Cleanup (10.55 GB recovered):
- Deleted Rust build artifacts: 9.6 GB (target/ directories)
- Deleted Python virtual environments: 161 MB (venv/ directories)
- Deleted Python cache: 50 KB (__pycache__/)

New Structure:
- docs/ - All documentation organized by category
- docs/archives/ - Obsolete but preserved documentation
- infrastructure/ - VPN configs and SSH setup
- tests/ - All test files consolidated
- logs/ - Ready for future logs

Benefits:
- Cleaner root directory (18 vs 119 files)
- Logical organization of documentation
- 95.9% disk space reduction
- Faster navigation and discovery
- Better portability (build artifacts excluded)

Build artifacts can be regenerated:
- Rust: cargo build --release (5-15 min per project)
- Python: pip install -r requirements.txt (2-3 min)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-18 20:42:28 -07:00

128 lines
3.7 KiB
Python

"""Test script to import and validate all SQLAlchemy models."""
import sys
import traceback
import os
# Set UTF-8 encoding for Windows console
if os.name == 'nt':
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
def test_model_import():
"""Test importing all models from api.models."""
try:
import api.models
print("[SUCCESS] Import successful")
# Get all model classes (exclude private attributes and modules)
all_classes = [attr for attr in dir(api.models) if not attr.startswith('_') and attr[0].isupper()]
# Filter out base classes and mixins (they don't have __tablename__)
base_classes = {'Base', 'TimestampMixin', 'UUIDMixin'}
models = [m for m in all_classes if m not in base_classes]
print(f"\nTotal classes found: {len(all_classes)}")
print(f"Base classes/mixins: {len(base_classes)}")
print(f"Table models: {len(models)}")
print("\nTable Models:")
for m in sorted(models):
print(f" - {m}")
return models
except Exception as e:
print(f"[ERROR] Import failed: {e}")
traceback.print_exc()
return []
def test_model_structure(model_name):
"""Test individual model structure and configuration."""
import api.models
try:
model_cls = getattr(api.models, model_name)
# Check if it's actually a class
if not isinstance(model_cls, type):
return f"[FAIL] {model_name} - Not a class"
# Check for __tablename__
if not hasattr(model_cls, '__tablename__'):
return f"[FAIL] {model_name} - Missing __tablename__"
# Check for __table_args__ (optional but should exist if defined)
has_table_args = hasattr(model_cls, '__table_args__')
# Try to instantiate (without saving to DB)
try:
instance = model_cls()
can_instantiate = True
except Exception as inst_error:
can_instantiate = False
inst_msg = str(inst_error)
# Build result message
details = []
details.append(f"table={model_cls.__tablename__}")
if has_table_args:
details.append("has_table_args")
if can_instantiate:
details.append("instantiable")
else:
details.append(f"not_instantiable({inst_msg[:50]})")
return f"[PASS] {model_name} - {', '.join(details)}"
except Exception as e:
return f"[FAIL] {model_name} - {str(e)}"
def main():
print("=" * 70)
print("ClaudeTools - Model Import and Structure Test")
print("=" * 70)
# Test 1: Import all models
print("\n[TEST 1] Importing api.models module...")
models = test_model_import()
if not models:
print("\n[CRITICAL] Failed to import models module")
sys.exit(1)
# Test 2: Validate each model structure
print(f"\n[TEST 2] Validating structure of {len(models)} models...")
print("-" * 70)
passed = 0
failed = 0
results = []
for model_name in sorted(models):
result = test_model_structure(model_name)
results.append(result)
if result.startswith("[PASS]"):
passed += 1
else:
failed += 1
# Print all results
for result in results:
print(result)
# Summary
print("-" * 70)
print(f"\n[SUMMARY]")
print(f"Total models: {len(models)}")
print(f"[PASS] Passed: {passed}")
print(f"[FAIL] Failed: {failed}")
if failed == 0:
print(f"\n[SUCCESS] All {passed} models validated successfully!")
sys.exit(0)
else:
print(f"\n[WARNING] {failed} model(s) need attention")
sys.exit(1)
if __name__ == "__main__":
main()