""" Test script to verify app.py portability logic Simulates app.py being in different locations """ from pathlib import Path import sys def test_portability_logic(app_location): """Test the portability logic as if app.py was at app_location""" # Simulate app.py's __file__ being at app_location print(f"\nšŸ“ Testing with app.py at: {app_location}") print("-" * 60) # This is the exact logic from app.py webapp_parent = app_location.parent.parent if (webapp_parent / 'config').exists(): PROJECT_ROOT = webapp_parent location_type = "Original location (webapp/)" else: # app.py was moved - find project root by searching for config/ PROJECT_ROOT = app_location.parent while PROJECT_ROOT != PROJECT_ROOT.parent: # Until root of filesystem if (PROJECT_ROOT / 'config').exists() and (PROJECT_ROOT / 'src').exists(): break PROJECT_ROOT = PROJECT_ROOT.parent location_type = "Moved location (outside webapp/)" # Determine webapp folder (for templates/static/uploads) WEBAPP_FOLDER = PROJECT_ROOT / 'webapp' # Print results print(f"Location type: {location_type}") print(f"PROJECT_ROOT: {PROJECT_ROOT}") print(f"WEBAPP_FOLDER: {WEBAPP_FOLDER}") # Verify all required folders exist required_folders = ['config', 'src', 'webapp', 'ai_models', 'docs'] all_exist = True print(f"\nRequired folders check:") for folder in required_folders: exists = (PROJECT_ROOT / folder).exists() status = "āœ“" if exists else "āœ—" print(f" {status} {folder}") all_exist = all_exist and exists # Check template and static folders print(f"\nFlask folders check:") templates_exist = (WEBAPP_FOLDER / 'templates').exists() static_exist = (WEBAPP_FOLDER / 'static').exists() print(f" {'āœ“' if templates_exist else 'āœ—'} templates/") print(f" {'āœ“' if static_exist else 'āœ—'} static/") return all_exist and templates_exist and static_exist # Test 1: Original location (webapp/app.py) project_root = Path(__file__).parent result1 = test_portability_logic(project_root / 'webapp' / 'app.py') # Test 2: Moved to project root (app.py) result2 = test_portability_logic(project_root / 'app.py') # Test 3: Moved to src (src/app.py) result3 = test_portability_logic(project_root / 'src' / 'app.py') # Summary print("\n" + "=" * 60) print("PORTABILITY TEST SUMMARY") print("=" * 60) print(f"āœ“ Original location (webapp/app.py): {'PASS' if result1 else 'FAIL'}") print(f"{'āœ“' if result2 else 'āœ—'} Moved to root (app.py): {'PASS' if result2 else 'FAIL'}") print(f"{'āœ“' if result3 else 'āœ—'} Moved to src (src/app.py): {'PASS' if result3 else 'FAIL'}") if result1 and result2 and result3: print("\nāœ… app.py IS PORTABLE - Can be used anywhere in the project!") else: print("\nāŒ app.py is NOT fully portable")