mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
d831040032
* Exclude `ruff` from the requirements list for Wasm env * Exclude `uvicorn` from the requirements list for Wasm env and fix the related modules not to try to import it when not used * add changeset * Fix tests * add changeset * Apply formatter * Remove a test case which became unnecessary in https://github.com/gradio-app/gradio/pull/5267, ref: https://github.com/gradio-app/gradio/pull/7744#issuecomment-2011332287 --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""Contains tests for networking.py and app.py"""
|
|
|
|
import os
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from gradio import Interface, networking
|
|
|
|
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
|
|
|
|
|
class TestInterfaceErrors:
|
|
def test_processing_error(self):
|
|
io = Interface(lambda x: 1 / x, "number", "number")
|
|
app, _, _ = io.launch(show_error=True, prevent_thread_lock=True)
|
|
client = TestClient(app)
|
|
response = client.post("/api/predict/", json={"data": [0], "fn_index": 0})
|
|
assert response.status_code == 500
|
|
assert "error" in response.json()
|
|
io.close()
|
|
|
|
def test_validation_error(self):
|
|
io = Interface(lambda x: 1 / x, "number", "number")
|
|
app, _, _ = io.launch(show_error=True, prevent_thread_lock=True)
|
|
client = TestClient(app)
|
|
response = client.post("/api/predict/", json={"fn_index": [0]})
|
|
assert response.status_code == 422
|
|
io.close()
|
|
|
|
|
|
class TestURLs:
|
|
def test_url_ok(self):
|
|
res = networking.url_ok("https://www.gradio.app")
|
|
assert res
|
|
|
|
|
|
def test_start_server_app_kwargs():
|
|
"""
|
|
Test that start_server accepts app_kwargs and they're propagated to FastAPI.
|
|
"""
|
|
io = Interface(lambda x: x, "number", "number")
|
|
app, _, _ = io.launch(
|
|
show_error=True,
|
|
prevent_thread_lock=True,
|
|
app_kwargs={
|
|
"docs_url": "/docs",
|
|
},
|
|
)
|
|
client = TestClient(app)
|
|
assert client.get("/docs").status_code == 200
|
|
io.close()
|