Merge pull request #866 from gradio-app/790-in-out

add test for output to input
This commit is contained in:
Abubakar Abid 2022-03-24 21:52:43 -07:00 committed by GitHub
commit bb0b965998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,47 @@
{
"mode": "blocks",
"components": [
{
"id": 1,
"type": "textbox",
"props": {
"lines": 1,
"placeholder": "None",
"default": "",
"name": "textbox",
"label": "None",
"css": {}
}
},
{
"id": 2,
"type": "button",
"props": {
"value": "Run",
"name": "button",
"label": "None",
"css": {}
}
}
],
"theme": "default",
"layout": {
"id": 0,
"children": [
{
"id": 1
},
{
"id": 2
}
]
},
"dependencies": [
{
"targets": [2],
"trigger": "click",
"inputs": [1],
"outputs": [1]
}
]
}

16
demo/input-output/run.py Normal file
View File

@ -0,0 +1,16 @@
import gradio as gr
def image_mod(text):
return text[::-1]
block = gr.Blocks()
with block:
text = gr.Textbox()
btn = gr.Button("Run")
btn.click(image_mod, text, text)
print(block.get_config_file())
if __name__ == "__main__":
block.launch()

View File

@ -0,0 +1,44 @@
import { test, expect, Page } from "@playwright/test";
function mock_demo(page: Page, demo: string) {
return page.route("http://localhost:7860/config", (route) => {
return route.fulfill({
headers: {
"Access-Control-Allow-Origin": "*"
},
path: `../../../demo/${demo}/config.json`
});
});
}
function mock_api(page: Page, body: Array<unknown>) {
return page.route("http://localhost:7860/api/predict/", (route) => {
const id = JSON.parse(route.request().postData()!).fn_index;
return route.fulfill({
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({
data: body[id]
})
});
});
}
test("a component acts as both input and output", async ({ page }) => {
await mock_demo(page, "input-output");
await mock_api(page, [["world hello"]]);
await page.goto("http://localhost:3000");
const textbox = await page.locator(".input-text");
const button = await page.locator("button");
await textbox.fill("hello world");
await Promise.all([
button.click(),
page.waitForResponse("http://localhost:7860/api/predict/")
]);
await expect(await page.inputValue(".input-text")).toEqual("world hello");
});