mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-05 11:10:03 +08:00
fix client flaky tests (#8481)
* fix client flaky tests * format * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
925a723e71
commit
41a449383a
6
.changeset/crazy-turtles-sing.md
Normal file
6
.changeset/crazy-turtles-sing.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"gradio": minor
|
||||
"gradio_client": minor
|
||||
---
|
||||
|
||||
feat:fix client flaky tests
|
@ -1308,7 +1308,7 @@ class Endpoint:
|
||||
else:
|
||||
return data
|
||||
|
||||
def _upload_file(self, f: str | dict, data_index: int) -> dict[str, str]:
|
||||
def _upload_file(self, f: dict, data_index: int) -> dict[str, str]:
|
||||
file_path = f["path"]
|
||||
orig_name = Path(file_path)
|
||||
if not utils.is_http_url_like(file_path):
|
||||
|
@ -159,22 +159,25 @@ class TestClientPredictions:
|
||||
space_id = "gradio-tests/space_with_files_v4_sse_v2"
|
||||
client = Client(space_id)
|
||||
payload = (
|
||||
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
|
||||
handle_file(
|
||||
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
|
||||
),
|
||||
{
|
||||
"video": "https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4",
|
||||
"video": handle_file(
|
||||
"https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4"
|
||||
),
|
||||
"subtitle": None,
|
||||
},
|
||||
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
|
||||
handle_file(
|
||||
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
|
||||
),
|
||||
)
|
||||
output = client.predict(*payload, api_name="/predict")
|
||||
assert output[0].endswith(".wav") # Audio files are converted to wav
|
||||
assert output[1]["video"].endswith(
|
||||
"world.mp4"
|
||||
) # Video files are not converted by default
|
||||
assert (
|
||||
output[2]
|
||||
== "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
|
||||
) # textbox string should remain exactly the same
|
||||
assert "sample-0.mp3" in output[2]
|
||||
|
||||
def test_state(self, increment_demo):
|
||||
with connect(increment_demo) as client:
|
||||
@ -890,8 +893,8 @@ class TestAPIInfo:
|
||||
"label": "output",
|
||||
"type": {"type": {}, "description": "any valid json"},
|
||||
"python_type": {
|
||||
"type": "str",
|
||||
"description": "filepath to JSON file",
|
||||
"type": "Dict[Any, Any]",
|
||||
"description": "any valid json",
|
||||
},
|
||||
"component": "Label",
|
||||
"serializer": "JSONSerializable",
|
||||
@ -930,8 +933,8 @@ class TestAPIInfo:
|
||||
"label": "output",
|
||||
"type": {"type": {}, "description": "any valid json"},
|
||||
"python_type": {
|
||||
"type": "str",
|
||||
"description": "filepath to JSON file",
|
||||
"type": "Dict[Any, Any]",
|
||||
"description": "any valid json",
|
||||
},
|
||||
"component": "Label",
|
||||
"serializer": "JSONSerializable",
|
||||
@ -970,8 +973,8 @@ class TestAPIInfo:
|
||||
"label": "output",
|
||||
"type": {"type": {}, "description": "any valid json"},
|
||||
"python_type": {
|
||||
"type": "str",
|
||||
"description": "filepath to JSON file",
|
||||
"type": "Dict[Any, Any]",
|
||||
"description": "any valid json",
|
||||
},
|
||||
"component": "Label",
|
||||
"serializer": "JSONSerializable",
|
||||
@ -1266,7 +1269,9 @@ class TestEndpoints:
|
||||
client = Client(
|
||||
src="gradio/zip_files",
|
||||
)
|
||||
url_path = "https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
|
||||
url_path = handle_file(
|
||||
"https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
|
||||
)
|
||||
file = client.endpoints[0]._upload_file(url_path, 0) # type: ignore
|
||||
assert file["path"].endswith(".jpg")
|
||||
|
||||
|
@ -176,15 +176,6 @@ class TestLoadInterface:
|
||||
assert isinstance(interface.input_components[0], gr.Textbox)
|
||||
assert isinstance(interface.output_components[0], gr.Audio)
|
||||
|
||||
def test_text_to_image(self):
|
||||
model_type = "text-to-image"
|
||||
interface = gr.load(
|
||||
"models/osanseviero/BigGAN-deep-128", hf_token=None, alias=model_type
|
||||
)
|
||||
assert interface.__name__ == model_type
|
||||
assert isinstance(interface.input_components[0], gr.Textbox)
|
||||
assert isinstance(interface.output_components[0], gr.Image)
|
||||
|
||||
def test_english_to_spanish(self):
|
||||
with pytest.raises(GradioVersionIncompatibleError):
|
||||
gr.load("spaces/gradio-tests/english_to_spanish", title="hi")
|
||||
@ -285,14 +276,6 @@ class TestLoadInterface:
|
||||
finally:
|
||||
io.close()
|
||||
|
||||
def test_text_to_image_model(self):
|
||||
io = gr.load("models/osanseviero/BigGAN-deep-128")
|
||||
try:
|
||||
filename = io("chest")
|
||||
assert filename.lower().endswith((".jpg", ".jpeg", ".png"))
|
||||
except TooManyRequestsError:
|
||||
pass
|
||||
|
||||
def test_private_space(self):
|
||||
io = gr.load(
|
||||
"spaces/gradio-tests/not-actually-private-spacev4-sse", hf_token=HF_TOKEN
|
||||
|
Loading…
Reference in New Issue
Block a user