itsluckysharma01's picture
Upload 5 files
83e3e20 verified
"""
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")