Spaces:
Running on Zero
Running on Zero
Download tests/test_http.py from fffiloni/ZONOS3-Mini: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/fffiloni/ZONOS3-Mini/resolve/main/tests/test_http.py
- Command line
-
hf download hf://spaces/fffiloni/ZONOS3-Mini/tests/test_http.py
-
curl -L -o test_http.py https://huggingface.co/spaces/fffiloni/ZONOS3-Mini/resolve/main/tests/test_http.py
1.8 kB
| """Real Gradio HTTP transport, with a synthetic CPU engine. Never loads weights.""" | |
| import json | |
| import urllib.parse | |
| import urllib.request | |
| import pytest | |
| from gradio_client import Client | |
| from test_lifecycle import FakeEngine | |
| def test_http_session_injection_file_access_and_api_errors(monkeypatch, tmp_path): | |
| monkeypatch.setenv("ZONOS_UI_ONLY", "1") | |
| import app | |
| # The bound controller retains its identity in Gradio's registered callbacks. | |
| monkeypatch.setattr(app.controller, "engine", FakeEngine()) | |
| monkeypatch.setattr(app.controller, "outputs", tmp_path / "outputs") | |
| app.controller.outputs.mkdir() | |
| _, url, _ = app.demo.launch(prevent_thread_lock=True, quiet=True, | |
| allowed_paths=[str(app.controller.outputs.resolve())]) | |
| try: | |
| client = Client(url, verbose=False) | |
| args = ["A short test.", json.dumps({"voice":"Savannah", "language":"en_us"}), | |
| "Preset", None, False, True, 42, False, .75, .69, 80, 2.4, 0] | |
| result = client.predict(*args, api_name="/generate") | |
| take = json.loads(result[0]) | |
| with urllib.request.urlopen(urllib.parse.urljoin(url, take["url"])) as response: | |
| assert response.status == 200 and response.read(4) == b"RIFF" | |
| assert take["seed"] == 42 and app.controller.jobs.active() == 0 | |
| files = list(app.controller.outputs.glob("*.wav")) | |
| args[0] = "" | |
| with pytest.raises(Exception, match="Write something"): | |
| client.predict(*args, api_name="/generate") | |
| assert list(app.controller.outputs.glob("*.wav")) == files | |
| client.predict(api_name="/cancel") # Request injected with this client's session. | |
| assert app.controller.jobs.active() == 0 | |
| client.close() | |
| finally: | |
| app.demo.close() | |