mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-12 12:40:29 +08:00
Update HF token used in CI tests (#6671)
* fix tests * format * fixes * add changeset * fixes * fix * fix * update * update * test client * format * hf token 2 * add changeset * add env * add envs * tests * env * fixes * test external * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
523805360b
commit
299f5e238b
5
.changeset/full-hairs-shine.md
Normal file
5
.changeset/full-hairs-shine.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": minor
|
||||
---
|
||||
|
||||
feat:Update HF token used in CI tests
|
1
.github/workflows/backend.yml
vendored
1
.github/workflows/backend.yml
vendored
@ -13,6 +13,7 @@ concurrency:
|
||||
|
||||
env:
|
||||
NODE_OPTIONS: "--max-old-space-size=4096"
|
||||
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
|
@ -1,4 +1,5 @@
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import tempfile
|
||||
import time
|
||||
@ -15,13 +16,14 @@ import pytest
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from gradio.networking import Server
|
||||
from huggingface_hub import HfFolder
|
||||
from huggingface_hub.utils import RepositoryNotFoundError
|
||||
|
||||
from gradio_client import Client
|
||||
from gradio_client.client import DEFAULT_TEMP_DIR
|
||||
from gradio_client.utils import Communicator, ProgressUnit, Status, StatusUpdate
|
||||
|
||||
HF_TOKEN = "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" # Intentionally revealing this key for testing purposes
|
||||
HF_TOKEN = os.getenv("HF_TOKEN") or HfFolder.get_token()
|
||||
|
||||
|
||||
@contextmanager
|
||||
@ -76,18 +78,20 @@ class TestClientPredictions:
|
||||
@pytest.mark.flaky
|
||||
def test_private_space(self):
|
||||
space_id = "gradio-tests/not-actually-private-space"
|
||||
api = huggingface_hub.HfApi(token=HF_TOKEN)
|
||||
api = huggingface_hub.HfApi()
|
||||
assert api.space_info(space_id).private
|
||||
client = Client(space_id, hf_token=HF_TOKEN)
|
||||
client = Client(space_id)
|
||||
output = client.predict("abc", api_name="/predict")
|
||||
assert output == "abc"
|
||||
|
||||
@pytest.mark.flaky
|
||||
def test_private_space_v4(self):
|
||||
space_id = "gradio-tests/not-actually-private-spacev4-sse"
|
||||
api = huggingface_hub.HfApi(token=HF_TOKEN)
|
||||
api = huggingface_hub.HfApi()
|
||||
assert api.space_info(space_id).private
|
||||
client = Client(space_id, hf_token=HF_TOKEN)
|
||||
client = Client(
|
||||
space_id,
|
||||
)
|
||||
output = client.predict("abc", api_name="/predict")
|
||||
assert output == "abc"
|
||||
|
||||
@ -307,7 +311,7 @@ class TestClientPredictions:
|
||||
@pytest.mark.xfail
|
||||
def test_upload_file_private_space_v4(self):
|
||||
client = Client(
|
||||
src="gradio-tests/not-actually-private-file-uploadv4-sse", hf_token=HF_TOKEN
|
||||
src="gradio-tests/not-actually-private-file-uploadv4-sse",
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
@ -360,7 +364,8 @@ class TestClientPredictions:
|
||||
@pytest.mark.flaky
|
||||
def test_upload_file_private_space(self):
|
||||
client = Client(
|
||||
src="gradio-tests/not-actually-private-file-upload", hf_token=HF_TOKEN
|
||||
src="gradio-tests/not-actually-private-file-upload",
|
||||
hf_token=HF_TOKEN,
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
@ -783,7 +788,9 @@ class TestAPIInfo:
|
||||
|
||||
@pytest.mark.flaky
|
||||
def test_private_space(self):
|
||||
client = Client("gradio-tests/not-actually-private-space", hf_token=HF_TOKEN)
|
||||
client = Client(
|
||||
"gradio-tests/not-actually-private-space",
|
||||
)
|
||||
assert len(client.endpoints) == 3
|
||||
assert len([e for e in client.endpoints if e.is_valid]) == 2
|
||||
assert len([e for e in client.endpoints if e.is_valid and e.api_name]) == 1
|
||||
@ -1008,9 +1015,10 @@ class TestAPIInfo:
|
||||
|
||||
|
||||
class TestEndpoints:
|
||||
@pytest.mark.flaky
|
||||
def test_upload(self):
|
||||
client = Client(
|
||||
src="gradio-tests/not-actually-private-file-upload", hf_token=HF_TOKEN
|
||||
src="gradio-tests/not-actually-private-file-upload",
|
||||
)
|
||||
response = MagicMock(status_code=200)
|
||||
response.json.return_value = [
|
||||
@ -1044,9 +1052,10 @@ class TestEndpoints:
|
||||
"file7",
|
||||
]
|
||||
|
||||
@pytest.mark.flaky
|
||||
def test_upload_v4(self):
|
||||
client = Client(
|
||||
src="gradio-tests/not-actually-private-file-uploadv4-sse", hf_token=HF_TOKEN
|
||||
src="gradio-tests/not-actually-private-file-uploadv4-sse",
|
||||
)
|
||||
response = MagicMock(status_code=200)
|
||||
response.json.return_value = [
|
||||
@ -1089,18 +1098,20 @@ class TestDuplication:
|
||||
@patch("huggingface_hub.get_space_runtime", return_value=MagicMock(hardware=cpu))
|
||||
@patch("gradio_client.client.Client.__init__", return_value=None)
|
||||
def test_new_space_id(self, mock_init, mock_runtime):
|
||||
Client.duplicate("gradio/calculator", "test", hf_token=HF_TOKEN)
|
||||
mock_runtime.assert_any_call("gradio/calculator", token=HF_TOKEN)
|
||||
mock_runtime.assert_any_call("gradio-tests/test", token=HF_TOKEN)
|
||||
mock_init.assert_called_with(
|
||||
"gradio-tests/test", hf_token=HF_TOKEN, max_workers=40, verbose=True
|
||||
Client.duplicate(
|
||||
"gradio/calculator",
|
||||
"test",
|
||||
hf_token=HF_TOKEN,
|
||||
)
|
||||
Client.duplicate("gradio/calculator", "gradio-tests/test", hf_token=HF_TOKEN)
|
||||
mock_runtime.assert_any_call("gradio/calculator", token=HF_TOKEN)
|
||||
mock_runtime.assert_any_call("gradio-tests/test", token=HF_TOKEN)
|
||||
mock_init.assert_called_with(
|
||||
"gradio-tests/test", hf_token=HF_TOKEN, max_workers=40, verbose=True
|
||||
mock_init.assert_called()
|
||||
Client.duplicate(
|
||||
"gradio/calculator",
|
||||
"gradio-tests/test",
|
||||
hf_token=HF_TOKEN,
|
||||
)
|
||||
mock_runtime.assert_any_call("gradio/calculator", token=HF_TOKEN)
|
||||
mock_init.assert_called()
|
||||
|
||||
@pytest.mark.flaky
|
||||
@patch("gradio_client.utils.set_space_timeout")
|
||||
@ -1109,7 +1120,10 @@ class TestDuplication:
|
||||
def test_dont_set_timeout_if_default_hardware(
|
||||
self, mock_init, mock_runtime, mock_set_timeout
|
||||
):
|
||||
Client.duplicate("gradio/calculator", "test", hf_token=HF_TOKEN)
|
||||
Client.duplicate(
|
||||
"gradio/calculator",
|
||||
"test",
|
||||
)
|
||||
mock_set_timeout.assert_not_called()
|
||||
|
||||
@pytest.mark.flaky
|
||||
@ -1126,24 +1140,13 @@ class TestDuplication:
|
||||
Client.duplicate(
|
||||
"gradio/calculator",
|
||||
"test",
|
||||
hf_token=HF_TOKEN,
|
||||
hardware="cpu-upgrade",
|
||||
sleep_timeout=15,
|
||||
hf_token=HF_TOKEN,
|
||||
)
|
||||
mock_set_timeout.assert_called_once_with(
|
||||
"gradio-tests/test", hf_token=HF_TOKEN, timeout_in_seconds=15 * 60
|
||||
)
|
||||
|
||||
@pytest.mark.flaky
|
||||
@patch("huggingface_hub.get_space_runtime", return_value=MagicMock(hardware=cpu))
|
||||
@patch("gradio_client.client.Client.__init__", return_value=None)
|
||||
def test_default_space_id(self, mock_init, mock_runtime):
|
||||
Client.duplicate("gradio/calculator", hf_token=HF_TOKEN)
|
||||
mock_runtime.assert_any_call("gradio/calculator", token=HF_TOKEN)
|
||||
mock_runtime.assert_any_call("gradio-tests/calculator", token=HF_TOKEN)
|
||||
mock_init.assert_called_with(
|
||||
"gradio-tests/calculator", hf_token=HF_TOKEN, max_workers=40, verbose=True
|
||||
)
|
||||
assert mock_set_timeout.call_count == 1
|
||||
_, called_kwargs = mock_set_timeout.call_args
|
||||
assert called_kwargs["timeout_in_seconds"] == 15 * 60
|
||||
|
||||
@pytest.mark.flaky
|
||||
@patch("huggingface_hub.add_space_secret")
|
||||
|
@ -1,5 +1,6 @@
|
||||
import importlib.resources
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
@ -7,6 +8,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from huggingface_hub import HfFolder
|
||||
|
||||
from gradio_client import media_data, utils
|
||||
|
||||
@ -18,6 +20,9 @@ types["MultipleFile"] = {
|
||||
types["SingleFile"] = {"type": "string", "description": "filepath or URL to file"}
|
||||
|
||||
|
||||
HF_TOKEN = os.getenv("HF_TOKEN") or HfFolder.get_token()
|
||||
|
||||
|
||||
def test_encode_url_or_file_to_base64():
|
||||
output_base64 = utils.encode_url_or_file_to_base64(
|
||||
Path(__file__).parent / "../../../gradio/test_data/test_image.png"
|
||||
@ -66,13 +71,13 @@ def test_decode_base64_to_file():
|
||||
assert isinstance(temp_file, tempfile._TemporaryFileWrapper)
|
||||
|
||||
|
||||
@pytest.mark.flaky
|
||||
def test_download_private_file(gradio_temp_dir):
|
||||
url_path = (
|
||||
"https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
|
||||
)
|
||||
hf_token = "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" # Intentionally revealing this key for testing purposes
|
||||
file = utils.download_file(
|
||||
url_path=url_path, hf_token=hf_token, dir=str(gradio_temp_dir)
|
||||
url_path=url_path, hf_token=HF_TOKEN, dir=str(gradio_temp_dir)
|
||||
)
|
||||
assert Path(file).name.endswith(".jpg")
|
||||
|
||||
|
@ -57,7 +57,7 @@ from gradio.components import (
|
||||
Video,
|
||||
component,
|
||||
)
|
||||
from gradio.components.audio import WaveformOptions
|
||||
from gradio.components.audio import WaveformOptions # type: ignore
|
||||
from gradio.data_classes import FileData
|
||||
from gradio.events import EventData, LikeData, SelectData, on
|
||||
from gradio.exceptions import Error
|
||||
|
@ -7,6 +7,7 @@ from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from gradio_client import media_data
|
||||
from huggingface_hub import HfFolder
|
||||
|
||||
import gradio as gr
|
||||
from gradio.context import Context
|
||||
@ -22,11 +23,13 @@ These tests actually test gr.load() and gr.Blocks.load() but are
|
||||
included in a separate file because of the above-mentioned dependency.
|
||||
"""
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
# Mark the whole module as flaky
|
||||
pytestmark = pytest.mark.flaky
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
HF_TOKEN = os.getenv("HF_TOKEN") or HfFolder.get_token()
|
||||
|
||||
|
||||
class TestLoadInterface:
|
||||
def test_audio_to_audio(self):
|
||||
@ -292,9 +295,8 @@ class TestLoadInterface:
|
||||
pass
|
||||
|
||||
def test_private_space(self):
|
||||
hf_token = "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" # Intentionally revealing this key for testing purposes
|
||||
io = gr.load(
|
||||
"spaces/gradio-tests/not-actually-private-spacev4-sse", hf_token=hf_token
|
||||
"spaces/gradio-tests/not-actually-private-spacev4-sse", hf_token=HF_TOKEN
|
||||
)
|
||||
try:
|
||||
output = io("abc")
|
||||
@ -305,10 +307,9 @@ class TestLoadInterface:
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_private_space_audio(self):
|
||||
hf_token = "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" # Intentionally revealing this key for testing purposes
|
||||
io = gr.load(
|
||||
"spaces/gradio-tests/not-actually-private-space-audiov4-sse",
|
||||
hf_token=hf_token,
|
||||
hf_token=HF_TOKEN,
|
||||
)
|
||||
try:
|
||||
output = io(media_data.BASE64_AUDIO["path"])
|
||||
@ -317,21 +318,19 @@ class TestLoadInterface:
|
||||
pass
|
||||
|
||||
def test_multiple_spaces_one_private(self):
|
||||
hf_token = "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" # Intentionally revealing this key for testing purposes
|
||||
with gr.Blocks():
|
||||
gr.load(
|
||||
"spaces/gradio-tests/not-actually-private-spacev4-sse",
|
||||
hf_token=hf_token,
|
||||
hf_token=HF_TOKEN,
|
||||
)
|
||||
gr.load(
|
||||
"spaces/gradio/test-loading-examplesv4-sse",
|
||||
)
|
||||
assert Context.hf_token == hf_token
|
||||
assert Context.hf_token == HF_TOKEN
|
||||
|
||||
def test_loading_files_via_proxy_works(self):
|
||||
hf_token = "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" # Intentionally revealing this key for testing purposes
|
||||
io = gr.load(
|
||||
"spaces/gradio-tests/test-loading-examples-privatev4-sse", hf_token=hf_token
|
||||
"spaces/gradio-tests/test-loading-examples-privatev4-sse", hf_token=HF_TOKEN
|
||||
)
|
||||
assert io.theme.name == "default"
|
||||
app, _, _ = io.launch(prevent_thread_lock=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user