Spaces:
Runtime error
Runtime error
Raymond Weitekamp
commited on
Commit
·
37cf6e7
1
Parent(s):
ffec248
stuck on server test
Browse files- error_screenshot.png +3 -0
- test_server.py +42 -0
- test_server.sh +34 -22
error_screenshot.png
ADDED
![]() |
Git LFS Details
|
test_server.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pytest
|
3 |
+
import pytest_asyncio
|
4 |
+
from playwright.async_api import async_playwright, expect
|
5 |
+
import asyncio
|
6 |
+
|
7 |
+
@pytest_asyncio.fixture(scope="session")
|
8 |
+
def event_loop():
|
9 |
+
policy = asyncio.get_event_loop_policy()
|
10 |
+
loop = policy.new_event_loop()
|
11 |
+
yield loop
|
12 |
+
loop.close()
|
13 |
+
|
14 |
+
@pytest.mark.asyncio
|
15 |
+
async def test_space_loads():
|
16 |
+
"""Test that we can access the Space and see the heading"""
|
17 |
+
async with async_playwright() as playwright:
|
18 |
+
browser = await playwright.chromium.launch(headless=False)
|
19 |
+
page = await browser.new_page()
|
20 |
+
|
21 |
+
try:
|
22 |
+
# Navigate to the Space
|
23 |
+
await page.goto("https://huggingface.co/spaces/rawwerks/handwriting-ocr")
|
24 |
+
|
25 |
+
if os.getenv('PWDEBUG'):
|
26 |
+
await page.pause()
|
27 |
+
|
28 |
+
# Now look for the login button from Gradio
|
29 |
+
print("Looking for login button...")
|
30 |
+
login_button = page.get_by_role("button").filter(has_text="Login")
|
31 |
+
await login_button.wait_for(state="visible", timeout=5000)
|
32 |
+
print("Found login button, clicking...")
|
33 |
+
|
34 |
+
if os.getenv('PWDEBUG'):
|
35 |
+
await page.pause()
|
36 |
+
|
37 |
+
await login_button.click()
|
38 |
+
print("Clicked login button")
|
39 |
+
|
40 |
+
finally:
|
41 |
+
await browser.close()
|
42 |
+
|
test_server.sh
CHANGED
@@ -3,6 +3,16 @@
|
|
3 |
# Exit on error
|
4 |
set -e
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Check if auth_state.json exists
|
7 |
if [ ! -f "auth_state.json" ]; then
|
8 |
echo "Error: auth_state.json not found. Please run save_hf_storage_state.py first to save your Hugging Face login state."
|
@@ -40,53 +50,55 @@ import asyncio
|
|
40 |
|
41 |
@pytest_asyncio.fixture(scope="session")
|
42 |
def event_loop():
|
43 |
-
"""Create an instance of the default event loop for each test case."""
|
44 |
policy = asyncio.get_event_loop_policy()
|
45 |
loop = policy.new_event_loop()
|
46 |
yield loop
|
47 |
loop.close()
|
48 |
|
49 |
@pytest.mark.asyncio
|
50 |
-
async def
|
51 |
-
"""Test that we can access the Space
|
52 |
-
auth_state_path = "auth_state.json"
|
53 |
-
assert os.path.exists(auth_state_path), f"Authentication state file not found at {auth_state_path}"
|
54 |
-
|
55 |
async with async_playwright() as playwright:
|
56 |
-
# Launch browser with stored authentication state
|
57 |
browser = await playwright.chromium.launch(headless=False)
|
58 |
-
|
59 |
-
page = await context.new_page()
|
60 |
|
61 |
try:
|
62 |
# Navigate to the Space
|
63 |
await page.goto("https://huggingface.co/spaces/rawwerks/handwriting-ocr")
|
64 |
-
await page.wait_for_load_state("networkidle")
|
65 |
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
await expect(page.get_by_label("Upload Handwritten Image")).to_be_visible()
|
75 |
-
await expect(page.get_by_role("button", name="Submit")).to_be_visible()
|
76 |
-
await expect(page.get_by_role("button", name="Skip")).to_be_visible()
|
77 |
|
78 |
finally:
|
79 |
-
await context.close()
|
80 |
await browser.close()
|
|
|
81 |
EOL
|
82 |
|
83 |
-
# Run the server tests
|
84 |
echo "Running server tests..."
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# Cleanup
|
88 |
echo "Cleaning up..."
|
89 |
rm test_server.py
|
|
|
90 |
|
91 |
# Deactivate virtual environment
|
92 |
deactivate
|
|
|
3 |
# Exit on error
|
4 |
set -e
|
5 |
|
6 |
+
# Parse command line arguments
|
7 |
+
DEBUG=0
|
8 |
+
while [[ "$#" -gt 0 ]]; do
|
9 |
+
case $1 in
|
10 |
+
--debug) DEBUG=1 ;;
|
11 |
+
*) echo "Unknown parameter: $1"; exit 1 ;;
|
12 |
+
esac
|
13 |
+
shift
|
14 |
+
done
|
15 |
+
|
16 |
# Check if auth_state.json exists
|
17 |
if [ ! -f "auth_state.json" ]; then
|
18 |
echo "Error: auth_state.json not found. Please run save_hf_storage_state.py first to save your Hugging Face login state."
|
|
|
50 |
|
51 |
@pytest_asyncio.fixture(scope="session")
|
52 |
def event_loop():
|
|
|
53 |
policy = asyncio.get_event_loop_policy()
|
54 |
loop = policy.new_event_loop()
|
55 |
yield loop
|
56 |
loop.close()
|
57 |
|
58 |
@pytest.mark.asyncio
|
59 |
+
async def test_space_loads():
|
60 |
+
"""Test that we can access the Space and see the heading"""
|
|
|
|
|
|
|
61 |
async with async_playwright() as playwright:
|
|
|
62 |
browser = await playwright.chromium.launch(headless=False)
|
63 |
+
page = await browser.new_page()
|
|
|
64 |
|
65 |
try:
|
66 |
# Navigate to the Space
|
67 |
await page.goto("https://huggingface.co/spaces/rawwerks/handwriting-ocr")
|
|
|
68 |
|
69 |
+
if os.getenv('PWDEBUG'):
|
70 |
+
await page.pause()
|
71 |
+
|
72 |
+
# Now look for the login button from Gradio
|
73 |
+
print("Looking for login button...")
|
74 |
+
login_button = page.get_by_role("button").filter(has_text="Login")
|
75 |
+
await login_button.wait_for(state="visible", timeout=5000)
|
76 |
+
print("Found login button, clicking...")
|
77 |
|
78 |
+
if os.getenv('PWDEBUG'):
|
79 |
+
await page.pause()
|
80 |
|
81 |
+
await login_button.click()
|
82 |
+
print("Clicked login button")
|
|
|
|
|
|
|
83 |
|
84 |
finally:
|
|
|
85 |
await browser.close()
|
86 |
+
|
87 |
EOL
|
88 |
|
89 |
+
# Run the server tests with or without Playwright Inspector based on debug flag
|
90 |
echo "Running server tests..."
|
91 |
+
if [ "$DEBUG" -eq 1 ]; then
|
92 |
+
echo "Debug mode enabled - launching Playwright Inspector..."
|
93 |
+
PWDEBUG=1 python -m pytest test_server.py -v
|
94 |
+
else
|
95 |
+
python -m pytest test_server.py -v
|
96 |
+
fi
|
97 |
|
98 |
# Cleanup
|
99 |
echo "Cleaning up..."
|
100 |
rm test_server.py
|
101 |
+
rm -f error.png
|
102 |
|
103 |
# Deactivate virtual environment
|
104 |
deactivate
|