Spaces:
Runtime error
Runtime error
# Exit on error | |
set -e | |
# Parse command line arguments | |
DEBUG=0 | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
--debug) DEBUG=1 ;; | |
*) echo "Unknown parameter: $1"; exit 1 ;; | |
esac | |
shift | |
done | |
# Check if auth_state.json exists | |
if [ ! -f "auth_state.json" ]; then | |
echo "Error: auth_state.json not found. Please run save_hf_storage_state.py first to save your Hugging Face login state." | |
exit 1 | |
fi | |
# Activate virtual environment if it exists, create if it doesn't | |
if [ ! -d "venv" ]; then | |
echo "Creating virtual environment..." | |
python -m venv venv | |
fi | |
echo "Activating virtual environment..." | |
source venv/bin/activate | |
# Install dependencies if needed | |
echo "Installing dependencies..." | |
if ! command -v uv &> /dev/null; then | |
echo "Installing uv package installer..." | |
curl -LsSf https://astral.sh/uv/install.sh | sh | |
fi | |
uv pip install -r requirements.txt | |
# Install Playwright browsers if needed | |
echo "Installing Playwright browsers..." | |
playwright install chromium | |
# Create a new test file specifically for server tests | |
cat > test_server.py << 'EOL' | |
import os | |
import pytest | |
import pytest_asyncio | |
from playwright.async_api import async_playwright, expect | |
import asyncio | |
@pytest_asyncio.fixture(scope="session") | |
def event_loop(): | |
policy = asyncio.get_event_loop_policy() | |
loop = policy.new_event_loop() | |
yield loop | |
loop.close() | |
@pytest.mark.asyncio | |
async def test_space_loads(): | |
"""Test that we can access the Space and see the heading""" | |
async with async_playwright() as playwright: | |
browser = await playwright.chromium.launch(headless=False) | |
page = await browser.new_page() | |
try: | |
# Navigate to the Space | |
await page.goto("https://huggingface.co/spaces/rawwerks/handwriting-ocr") | |
if os.getenv('PWDEBUG'): | |
await page.pause() | |
# Now look for the login button from Gradio | |
print("Looking for login button...") | |
login_button = page.get_by_role("button").filter(has_text="Login") | |
await login_button.wait_for(state="visible", timeout=5000) | |
print("Found login button, clicking...") | |
if os.getenv('PWDEBUG'): | |
await page.pause() | |
await login_button.click() | |
print("Clicked login button") | |
finally: | |
await browser.close() | |
EOL | |
# Run the server tests with or without Playwright Inspector based on debug flag | |
echo "Running server tests..." | |
if [ "$DEBUG" -eq 1 ]; then | |
echo "Debug mode enabled - launching Playwright Inspector..." | |
PWDEBUG=1 python -m pytest test_server.py -v | |
else | |
python -m pytest test_server.py -v | |
fi | |
# Cleanup | |
echo "Cleaning up..." | |
rm test_server.py | |
rm -f error.png | |
# Deactivate virtual environment | |
deactivate |