Skip to content

Commit 41a4493

Browse files
fix client flaky tests (#8481)
* fix client flaky tests * format * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 925a723 commit 41a4493

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

.changeset/crazy-turtles-sing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gradio": minor
3+
"gradio_client": minor
4+
---
5+
6+
feat:fix client flaky tests

client/python/gradio_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ def reduce_singleton_output(self, *data) -> Any:
13081308
else:
13091309
return data
13101310

1311-
def _upload_file(self, f: str | dict, data_index: int) -> dict[str, str]:
1311+
def _upload_file(self, f: dict, data_index: int) -> dict[str, str]:
13121312
file_path = f["path"]
13131313
orig_name = Path(file_path)
13141314
if not utils.is_http_url_like(file_path):

client/python/test/test_client.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,25 @@ def test_space_with_files_v4_sse_v2(self):
159159
space_id = "gradio-tests/space_with_files_v4_sse_v2"
160160
client = Client(space_id)
161161
payload = (
162-
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
162+
handle_file(
163+
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
164+
),
163165
{
164-
"video": "https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4",
166+
"video": handle_file(
167+
"https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4"
168+
),
165169
"subtitle": None,
166170
},
167-
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
171+
handle_file(
172+
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
173+
),
168174
)
169175
output = client.predict(*payload, api_name="/predict")
170176
assert output[0].endswith(".wav") # Audio files are converted to wav
171177
assert output[1]["video"].endswith(
172178
"world.mp4"
173179
) # Video files are not converted by default
174-
assert (
175-
output[2]
176-
== "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
177-
) # textbox string should remain exactly the same
180+
assert "sample-0.mp3" in output[2]
178181

179182
def test_state(self, increment_demo):
180183
with connect(increment_demo) as client:
@@ -890,8 +893,8 @@ def test_numerical_to_label_space(self):
890893
"label": "output",
891894
"type": {"type": {}, "description": "any valid json"},
892895
"python_type": {
893-
"type": "str",
894-
"description": "filepath to JSON file",
896+
"type": "Dict[Any, Any]",
897+
"description": "any valid json",
895898
},
896899
"component": "Label",
897900
"serializer": "JSONSerializable",
@@ -930,8 +933,8 @@ def test_numerical_to_label_space(self):
930933
"label": "output",
931934
"type": {"type": {}, "description": "any valid json"},
932935
"python_type": {
933-
"type": "str",
934-
"description": "filepath to JSON file",
936+
"type": "Dict[Any, Any]",
937+
"description": "any valid json",
935938
},
936939
"component": "Label",
937940
"serializer": "JSONSerializable",
@@ -970,8 +973,8 @@ def test_numerical_to_label_space(self):
970973
"label": "output",
971974
"type": {"type": {}, "description": "any valid json"},
972975
"python_type": {
973-
"type": "str",
974-
"description": "filepath to JSON file",
976+
"type": "Dict[Any, Any]",
977+
"description": "any valid json",
975978
},
976979
"component": "Label",
977980
"serializer": "JSONSerializable",
@@ -1266,7 +1269,9 @@ def test_download_private_file(self, gradio_temp_dir):
12661269
client = Client(
12671270
src="gradio/zip_files",
12681271
)
1269-
url_path = "https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
1272+
url_path = handle_file(
1273+
"https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
1274+
)
12701275
file = client.endpoints[0]._upload_file(url_path, 0) # type: ignore
12711276
assert file["path"].endswith(".jpg")
12721277

test/test_external.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,6 @@ def test_text_to_speech(self):
176176
assert isinstance(interface.input_components[0], gr.Textbox)
177177
assert isinstance(interface.output_components[0], gr.Audio)
178178

179-
def test_text_to_image(self):
180-
model_type = "text-to-image"
181-
interface = gr.load(
182-
"models/osanseviero/BigGAN-deep-128", hf_token=None, alias=model_type
183-
)
184-
assert interface.__name__ == model_type
185-
assert isinstance(interface.input_components[0], gr.Textbox)
186-
assert isinstance(interface.output_components[0], gr.Image)
187-
188179
def test_english_to_spanish(self):
189180
with pytest.raises(GradioVersionIncompatibleError):
190181
gr.load("spaces/gradio-tests/english_to_spanish", title="hi")
@@ -285,14 +276,6 @@ def test_speech_recognition_model(self):
285276
finally:
286277
io.close()
287278

288-
def test_text_to_image_model(self):
289-
io = gr.load("models/osanseviero/BigGAN-deep-128")
290-
try:
291-
filename = io("chest")
292-
assert filename.lower().endswith((".jpg", ".jpeg", ".png"))
293-
except TooManyRequestsError:
294-
pass
295-
296279
def test_private_space(self):
297280
io = gr.load(
298281
"spaces/gradio-tests/not-actually-private-spacev4-sse", hf_token=HF_TOKEN

0 commit comments

Comments
 (0)