Skip to content

Commit

Permalink
Quick fixes to video test (#4870)
Browse files Browse the repository at this point in the history
* push

* test components

* remove test file

* added monkeypatch
  • Loading branch information
abidlabs committed Jul 11, 2023
1 parent 3e9f540 commit a82eee5
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,8 @@ def test_with_waveform(self):
iface = gr.Interface(lambda x: gr.make_waveform(x), "audio", "video")
assert iface(x_audio).endswith(".mp4")

def test_video_postprocess_converts_to_playable_format(self):
def test_video_postprocess_converts_to_playable_format(self, monkeypatch, tmp_path):
monkeypatch.setenv("GRADIO_TEMP_DIR", str(tmp_path))
test_file_dir = Path(Path(__file__).parent, "test_files")
# This file has a playable container but not playable codec
with tempfile.NamedTemporaryFile(
Expand All @@ -1441,10 +1442,8 @@ def test_video_postprocess_converts_to_playable_format(self):
bad_vid = str(test_file_dir / "bad_video_sample.mp4")
assert not processing_utils.video_is_playable(bad_vid)
shutil.copy(bad_vid, tmp_not_playable_vid.name)
_ = gr.Video().postprocess(tmp_not_playable_vid.name)
# The original video gets converted to .mp4 format
full_path_to_output = Path(tmp_not_playable_vid.name).with_suffix(".mp4")
assert processing_utils.video_is_playable(str(full_path_to_output))
output = gr.Video().postprocess(tmp_not_playable_vid.name)
assert processing_utils.video_is_playable(output[0]["name"])

# This file has a playable codec but not a playable container
with tempfile.NamedTemporaryFile(
Expand All @@ -1453,18 +1452,8 @@ def test_video_postprocess_converts_to_playable_format(self):
bad_vid = str(test_file_dir / "playable_but_bad_container.mkv")
assert not processing_utils.video_is_playable(bad_vid)
shutil.copy(bad_vid, tmp_not_playable_vid.name)
_ = gr.Video().postprocess(tmp_not_playable_vid.name)
full_path_to_output = Path(tmp_not_playable_vid.name).with_suffix(".mp4")
assert processing_utils.video_is_playable(str(full_path_to_output))

def test_convert_video_to_playable_format(self, monkeypatch, tmp_path):
test_file_dir = Path(Path(__file__).parent, "test_files")
monkeypatch.setenv("GRADIO_TEMP_DIR", str(tmp_path))
video = gr.Video(format="mp4")
output = video.postprocess(
str(test_file_dir / "playable_but_bad_container.mkv")
)
assert Path(output[0]["name"]).suffix == ".mp4"
output = gr.Video().postprocess(tmp_not_playable_vid.name)
assert processing_utils.video_is_playable(output[0]["name"])

@patch("pathlib.Path.exists", MagicMock(return_value=False))
@patch("gradio.components.video.FFmpeg")
Expand Down

1 comment on commit a82eee5

@vercel
Copy link

@vercel vercel bot commented on a82eee5 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.