Files
wehub-resource-sync adf0d17497
publish / version_or_publish (push) Waiting to run
storybook-build / changes (push) Waiting to run
storybook-build / :storybook-build (push) Blocked by required conditions
Sync Gradio Skills to Hugging Face / sync-skills (push) Waiting to run
functional / changes (push) Waiting to run
functional / build-frontend (push) Blocked by required conditions
functional / functional-test-SSR=false (push) Blocked by required conditions
functional / functional-reload (push) Blocked by required conditions
functional / functional-test-SSR=true (push) Blocked by required conditions
hygiene / hygiene-test (push) Waiting to run
python / changes (push) Waiting to run
python / build (push) Blocked by required conditions
python / test-ubuntu-latest-flaky (push) Blocked by required conditions
python / test-ubuntu-latest-not-flaky (push) Blocked by required conditions
python / test-windows-latest-flaky (push) Blocked by required conditions
python / test-windows-latest-not-flaky (push) Blocked by required conditions
js / changes (push) Waiting to run
js / js-test (push) Blocked by required conditions
docs-build / changes (push) Waiting to run
docs-build / docs-build (push) Blocked by required conditions
docs-build / website-build (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 13:17:32 +08:00

38 lines
1.3 KiB
Python

import json
import os
import warnings
from unittest.mock import patch
from gradio import analytics
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
class TestAnalytics:
@patch("httpx.get")
def test_should_warn_with_unable_to_parse(self, mock_get, monkeypatch):
monkeypatch.setenv("GRADIO_ANALYTICS_ENABLED", "True")
mock_get.side_effect = json.decoder.JSONDecodeError("Expecting value", "", 0) # type: ignore
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
analytics.version_check()
assert (
str(w[-1].message)
== "unable to parse version details from package URL."
)
@patch("gradio.analytics._send_telemetry_in_thread")
def test_error_analytics_doesnt_crash_on_connection_error(
self, mock_send, monkeypatch
):
monkeypatch.setenv("GRADIO_ANALYTICS_ENABLED", "True")
mock_send.side_effect = Exception("Connection error")
analytics._do_normal_analytics_request("placeholder", {})
mock_send.assert_called()
@patch("gradio.analytics._send_telemetry_in_thread")
def test_error_analytics_successful(self, mock_post, monkeypatch):
monkeypatch.setenv("GRADIO_ANALYTICS_ENABLED", "True")
analytics.error_analytics("placeholder")