builder-app / test_local.py
Darveht's picture
Upload 12 files
5f54387 verified
Raw
History Blame Contribute Delete
3.66 kB
#!/usr/bin/env python3
"""
test_local.py — Prueba el generador de APK localmente antes de subir a HF.
Uso:
pip install gradio Pillow
cd apk-builder
python test_local.py
"""
import sys
import os
import tempfile
from pathlib import Path
# Asegurarse de que el módulo app sea importable
sys.path.insert(0, str(Path(__file__).parent / "app"))
def test_apk_generation():
"""Prueba la generación de APK con diferentes configuraciones."""
from app import build_apk, validate_url, sanitize_package
print("=" * 60)
print(" WebToAPK Builder — Test Suite")
print("=" * 60)
# Test 1: Validación de URLs
print("\n[1] Validando URLs...")
tests = [
("https://example.com", True),
("http://github.com", True),
("example.com", True), # debe agregar https://
("ftp://invalid", True), # URL técnicamente parseable
("", False), # vacío → inválido
]
for url, expected in tests:
ok, result = validate_url(url)
status = "✅" if ok == expected else "❌"
print(f" {status} '{url}' → valid={ok}, result={result}")
# Test 2: Package names
print("\n[2] Generando package names...")
names = ["My App", "GitHub", "123test", "Hello World!", "app"]
for name in names:
pkg = sanitize_package(name.replace(" ", "_"))
print(f" ✅ '{name}' → {pkg}")
# Test 3: Generación de APK completa
print("\n[3] Generando APK de prueba...")
apk_path, message = build_apk(
url="https://example.com",
app_name="Test App",
theme_color="Material Blue",
fullscreen=False,
allow_js=True,
allow_downloads=False,
allow_geolocation=False,
)
if apk_path and Path(apk_path).exists():
size = Path(apk_path).stat().st_size
print(f" ✅ APK generado: {apk_path}")
print(f" 📏 Tamaño: {size:,} bytes ({size//1024} KB)")
# Verificar estructura ZIP
import zipfile
with zipfile.ZipFile(apk_path, 'r') as z:
files = z.namelist()
print(f" 📦 Archivos en APK: {len(files)}")
for f in sorted(files)[:10]:
print(f" - {f}")
if len(files) > 10:
print(f" ... y {len(files)-10} más")
else:
print(f" ❌ Error: {message}")
return False
# Test 4: Múltiples colores
print("\n[4] Probando diferentes colores...")
colors = ["Material Blue", "Deep Purple", "Teal", "Red"]
for color in colors:
path, msg = build_apk(
url="https://example.com",
app_name=f"Test {color}",
theme_color=color,
fullscreen=False, allow_js=True,
allow_downloads=False, allow_geolocation=False,
)
status = "✅" if path else "❌"
print(f" {status} {color}")
print("\n" + "=" * 60)
print(" ✅ Todos los tests completados.")
print("=" * 60)
return True
def test_gradio_ui():
"""Levanta la UI de Gradio para prueba interactiva."""
print("\n🚀 Iniciando Gradio UI en http://localhost:7860 ...")
print(" Presiona Ctrl+C para detener.\n")
from app import build_ui
demo = build_ui()
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
if __name__ == "__main__":
import argparse
p = argparse.ArgumentParser()
p.add_argument("--ui", action="store_true", help="Lanzar UI de Gradio")
args = p.parse_args()
if args.ui:
test_gradio_ui()
else:
success = test_apk_generation()
sys.exit(0 if success else 1)