Skip to content

Commit

Permalink
V4: Set cache dir for some component tests (#5852)
Browse files Browse the repository at this point in the history
* Add code

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot authored Oct 9, 2023
1 parent 4ee02d7 commit 46e63d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/vast-terms-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:V4: Set cache dir for some component tests
1 change: 1 addition & 0 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def _move_to_cache(d: dict):
file_name=payload.name,
cache_dir=block.GRADIO_CACHE,
)
payload.is_file = True
block.temp_files.add(temp_file_path)
payload.name = temp_file_path
return payload.model_dump()
Expand Down
13 changes: 9 additions & 4 deletions test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def test_postprocess_altair(self):


class TestAudio:
def test_component_functions(self):
def test_component_functions(self, gradio_temp_dir):
"""
Preprocess, postprocess serialize, get_config, deserialize
type: filepath, numpy, file
Expand All @@ -755,10 +755,12 @@ def test_component_functions(self):
assert output1[0] == 8000
assert output1[1].shape == (8046,)

x_wav["is_file"] = True
x_wav["is_file"] = False
x_wav["name"] = "audio_sample.wav"
x_wav = processing_utils.move_files_to_cache([x_wav], audio_input)[0]
audio_input = gr.Audio(type="filepath")
output1 = audio_input.preprocess(x_wav)
assert Path(output1).name == "audio_sample-0-100.wav"
assert Path(output1).name.endswith("audio_sample-0-100.wav")

audio_input = gr.Audio(label="Upload Your Audio")
assert audio_input.get_config() == {
Expand Down Expand Up @@ -1233,8 +1235,11 @@ def test_component_functions(self):
"""
Preprocess, serialize, deserialize, get_config
"""
x_video = {"video": deepcopy(media_data.BASE64_VIDEO)}
x_video = {"video": deepcopy(media_data.BASE64_VIDEO), "is_file": False}
video_input = gr.Video()

x_video = processing_utils.move_files_to_cache([x_video], video_input)[0]

output1 = video_input.preprocess(x_video)
assert isinstance(output1, str)
output2 = video_input.preprocess(x_video)
Expand Down

0 comments on commit 46e63d6

Please sign in to comment.