gradio/test/test_http_server.py
Yuichiro Tachibana (Tsuchiya) d831040032
Remove Ruff and Uvicorn in Wasm env (#7744)
* 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>
2024-03-22 17:32:59 +09:00

30 lines
918 B
Python

import urllib.parse
import pytest
import gradio as gr
from gradio import http_server
class TestStartServer:
# Test IPv4 and IPv6 hostnames as they would be passed from --server-name.
@pytest.mark.parametrize("host", ["127.0.0.1", "[::1]"])
def test_start_server(self, host):
io = gr.Interface(lambda x: x, "number", "number")
io.favicon_path = None
io.config = io.get_config_file()
io.show_error = True
io.flagging_callback.setup(gr.Number(), io.flagging_dir)
io.auth = None
_, _, local_path, _, server = http_server.start_server(io)
url = urllib.parse.urlparse(local_path)
assert url.scheme == "http"
assert url.port is not None
assert (
http_server.INITIAL_PORT_VALUE
<= url.port
<= http_server.INITIAL_PORT_VALUE + http_server.TRY_NUM_PORTS
)
server.close()