Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Lite E2E tests and fix a networking problem on Lite #9333

Merged
merged 9 commits into from
Sep 13, 2024
5 changes: 5 additions & 0 deletions .changeset/fancy-pianos-dig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Enhance Lite E2E tests and fix a networking problem on Lite
3 changes: 2 additions & 1 deletion .config/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const lite = defineConfig(base, {
"**/file_component_events.spec.ts",
"**/kitchen_sink.spec.ts",
"**/gallery_component_events.spec.ts",
"**/image_remote_url.spec.ts" // To detect the bugs on Lite fixed in https://github.com/gradio-app/gradio/pull/8011 and https://github.com/gradio-app/gradio/pull/8026
"**/image_remote_url.spec.ts", // To detect the bugs on Lite fixed in https://github.com/gradio-app/gradio/pull/8011 and https://github.com/gradio-app/gradio/pull/8026
"**/outbreak_forecast.spec.ts" // To test matplotlib on Lite
],
workers: 1,
retries: 3,
Expand Down
13 changes: 10 additions & 3 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import socket
import subprocess
import tempfile
import urllib.request
import warnings
from functools import lru_cache
from io import BytesIO
Expand Down Expand Up @@ -278,8 +277,16 @@ def save_file_to_cache(file_path: str | Path, cache_dir: str) -> str:
def resolve_with_google_dns(hostname: str) -> str | None:
url = f"https://dns.google/resolve?name={hostname}&type=A"

with urllib.request.urlopen(url) as response:
data = json.loads(response.read().decode())
if wasm_utils.IS_WASM:
import pyodide.http

content = pyodide.http.open_url(url)
data = json.load(content)
else:
import urllib.request
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we used urllib originally because it was compatible with lite. Just wondering what the root cause is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing but network requests through urllib don't work on Pyodide by default, where urllib3 works.


with urllib.request.urlopen(url) as response:
data = json.loads(response.read().decode())

if data.get("Status") == 0 and "Answer" in data:
for answer in data["Answer"]:
Expand Down
30 changes: 30 additions & 0 deletions js/spa/test/image_remote_url.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test, expect } from "@self/tootils";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it got deleted?


test("Image displays remote image correctly", async ({ page }) => {
const example_image = page.locator(
'div.block:has(div.label:has-text("Examples")) img'
);
const input_image = page.locator(
'div.block:has(label:has-text("InputImage")) img'
);
const loopback_image = page.locator(
'div.block:has(label:has-text("Loopback")) img'
);
const remote_output_image = page.locator(
'div.block:has(label:has-text("RemoteImage")) img'
);
const submit_button = page.locator('button:has-text("Submit")');

await expect(example_image).toHaveJSProperty("complete", true);
await expect(example_image).not.toHaveJSProperty("naturalWidth", 0);

await expect(input_image).toHaveJSProperty("complete", true);
await expect(input_image).not.toHaveJSProperty("naturalWidth", 0);

await submit_button.click();

await expect(loopback_image).toHaveJSProperty("complete", true);
await expect(loopback_image).not.toHaveJSProperty("naturalWidth", 0);
await expect(remote_output_image).toHaveJSProperty("complete", true);
await expect(remote_output_image).not.toHaveJSProperty("naturalWidth", 0);
});
Loading