mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
Fix the frontend test for gallery
This commit is contained in:
parent
4e2aa3fff1
commit
007caa23e7
@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, List, Literal, Optional
|
||||
from typing import Any, Callable, List, Literal, Optional, Tuple, Union
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import numpy as np
|
||||
@ -28,6 +28,10 @@ class GalleryData(GradioRootModel):
|
||||
root: List[GalleryImage]
|
||||
|
||||
|
||||
GalleryImageType = Union[np.ndarray, _Image.Image, Path, str]
|
||||
CaptionedGalleryImageType = Tuple[GalleryImageType, str]
|
||||
|
||||
|
||||
@document()
|
||||
class Gallery(Component):
|
||||
"""
|
||||
@ -126,9 +130,7 @@ class Gallery(Component):
|
||||
|
||||
def postprocess(
|
||||
self,
|
||||
value: list[np.ndarray | _Image.Image | str]
|
||||
| list[tuple[np.ndarray | _Image.Image | str, str]]
|
||||
| None,
|
||||
value: list[GalleryImageType | CaptionedGalleryImageType] | None,
|
||||
) -> GalleryData:
|
||||
"""
|
||||
Parameters:
|
||||
|
@ -1,24 +1,27 @@
|
||||
import { test, expect } from "@gradio/tootils";
|
||||
|
||||
const regexLocalHostFileURL = (basename: string) =>
|
||||
new RegExp(`^http://localhost:7860/(\\w+/)*file=(.*\\/)?${basename}$`);
|
||||
|
||||
test("Gallery preview mode displays all images correctly.", async ({
|
||||
page
|
||||
}) => {
|
||||
await page.getByRole("button", { name: "Run" }).click();
|
||||
await page.getByLabel("Thumbnail 2 of 3").click();
|
||||
|
||||
await expect(
|
||||
await page.getByTestId("detailed-image").getAttribute("src")
|
||||
).toEqual("https://gradio-builds.s3.amazonaws.com/assets/lite-logo.png");
|
||||
expect(await page.getByTestId("detailed-image").getAttribute("src")).toMatch(
|
||||
regexLocalHostFileURL("lite-logo.png")
|
||||
);
|
||||
|
||||
await expect(
|
||||
await page.getByTestId("thumbnail 1").getAttribute("src")
|
||||
).toEqual("https://gradio-builds.s3.amazonaws.com/assets/cheetah-003.jpg");
|
||||
expect(await page.getByTestId("thumbnail 1").getAttribute("src")).toMatch(
|
||||
regexLocalHostFileURL("cheetah-003.jpg")
|
||||
);
|
||||
});
|
||||
|
||||
test("Gallery select event returns the right value", async ({ page }) => {
|
||||
await page.getByRole("button", { name: "Run" }).click();
|
||||
await page.getByLabel("Thumbnail 2 of 3").click();
|
||||
await expect(page.getByLabel("Select Data")).toHaveValue(
|
||||
"https://gradio-builds.s3.amazonaws.com/assets/lite-logo.png"
|
||||
regexLocalHostFileURL("lite-logo.png")
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user