| import importlib |
| import sys |
| from types import SimpleNamespace |
|
|
| import gradio as gr |
|
|
|
|
| def test_app_module_exposes_top_level_server_demo() -> None: |
| sys.modules.pop("app", None) |
|
|
| module = importlib.import_module("app") |
|
|
| assert isinstance(module.app, gr.Server) |
| assert hasattr(module, "demo") |
| assert isinstance(module.demo, gr.Blocks) |
| assert module.demo.mode == "server" |
|
|
|
|
| def test_launch_app_disables_ssr_for_custom_server_mode(monkeypatch) -> None: |
| sys.modules.pop("app", None) |
| module = importlib.import_module("app") |
| captured = {} |
|
|
| def fake_launch(**kwargs): |
| captured.update(kwargs) |
|
|
| monkeypatch.setattr(module.demo, "launch", fake_launch) |
|
|
| module._launch_app(7860) |
|
|
| assert captured["server_name"] == "0.0.0.0" |
| assert captured["server_port"] == 7860 |
| assert captured["ssr_mode"] is False |
| assert captured["_app"] is module.app |
|
|
|
|
| def test_app_import_warns_for_modal_dashboard_url(monkeypatch) -> None: |
| sys.modules.pop("app", None) |
| printed = [] |
|
|
| monkeypatch.setenv( |
| "SCRIPTORIUM_MODAL_BASE_URL", |
| "https://modal.com/apps/mattkevan/main/deployed/scriptorium-tts", |
| ) |
| monkeypatch.setattr("builtins.print", lambda *args, **kwargs: printed.append(" ".join(str(arg) for arg in args))) |
|
|
| importlib.import_module("app") |
|
|
| assert any("SCRIPTORIUM_MODAL_BASE_URL" in line for line in printed) |
| assert any("modal.run" in line for line in printed) |
|
|
|
|
| def test_app_import_reports_modal_runtime_configuration(monkeypatch) -> None: |
| sys.modules.pop("app", None) |
| printed = [] |
|
|
| monkeypatch.setenv( |
| "SCRIPTORIUM_MODAL_BASE_URL", |
| "https://scriptorium-tts--mattkevan.modal.run", |
| ) |
| monkeypatch.setenv("SCRIPTORIUM_MODAL_TIMEOUT_SECONDS", "300") |
| monkeypatch.setattr("builtins.print", lambda *args, **kwargs: printed.append(" ".join(str(arg) for arg in args))) |
|
|
| importlib.import_module("app") |
|
|
| assert any("Modal backend configured" in line for line in printed) |
| assert any("timeout=300.0s" in line for line in printed) |
|
|