File size: 1,178 Bytes
3bc3287 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import runpy
from pathlib import Path
from app.ui.gradio_app import build_app, choose_example, launch_app
def test_choose_example_returns_repo_url():
assert choose_example("Requests") == "https://github.com/psf/requests"
def test_choose_example_returns_empty_string_for_unknown_choice():
assert choose_example("Unknown") == ""
def test_build_app_creates_gradio_blocks():
demo = build_app()
assert demo is not None
def test_root_app_py_exposes_demo_for_spaces():
namespace = runpy.run_path(str(Path(__file__).parents[1] / "app.py"))
assert "demo" in namespace
def test_launch_app_uses_spaces_friendly_defaults(monkeypatch):
calls = {}
class FakeQueuedApp:
def launch(self, **kwargs):
calls.update(kwargs)
class FakeApp:
def queue(self):
return FakeQueuedApp()
monkeypatch.setattr("app.ui.gradio_app.build_app", lambda: FakeApp())
monkeypatch.delenv("PORT", raising=False)
monkeypatch.delenv("GRADIO_SERVER_PORT", raising=False)
monkeypatch.delenv("GRADIO_SERVER_NAME", raising=False)
launch_app()
assert calls == {"server_name": "0.0.0.0", "server_port": 7860}
|