mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
Catch IndexError, KeyError in video_is_playable (#2113)
This commit is contained in:
parent
4d58ae79b3
commit
85229a7058
0
demo/color_generator/requirements.txt
Normal file
0
demo/color_generator/requirements.txt
Normal file
@ -605,7 +605,7 @@ def video_is_playable(video_filepath: str) -> bool:
|
||||
(".webm", "vp9"),
|
||||
]
|
||||
# If anything goes wrong, assume the video can be played to not convert downstream
|
||||
except FFRuntimeError:
|
||||
except (FFRuntimeError, IndexError, KeyError):
|
||||
return True
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ from unittest.mock import patch
|
||||
import ffmpy
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
import gradio as gr
|
||||
@ -150,6 +151,24 @@ def test_video_has_playable_codecs(test_file_dir):
|
||||
)
|
||||
|
||||
|
||||
def raise_ffmpy_runtime_exception(*args, **kwargs):
|
||||
raise ffmpy.FFRuntimeError("", "", "", "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"exception_to_raise", [raise_ffmpy_runtime_exception, KeyError(), IndexError()]
|
||||
)
|
||||
def test_video_has_playable_codecs_catches_exceptions(
|
||||
exception_to_raise, test_file_dir
|
||||
):
|
||||
with patch("ffmpy.FFprobe.run", side_effect=exception_to_raise):
|
||||
with tempfile.NamedTemporaryFile(suffix="out.avi") as tmp_not_playable_vid:
|
||||
shutil.copy(
|
||||
str(test_file_dir / "bad_video_sample.mp4"), tmp_not_playable_vid.name
|
||||
)
|
||||
assert gr.processing_utils.video_is_playable(tmp_not_playable_vid.name)
|
||||
|
||||
|
||||
def test_convert_video_to_playable_mp4(test_file_dir):
|
||||
with tempfile.NamedTemporaryFile(suffix="out.avi") as tmp_not_playable_vid:
|
||||
shutil.copy(
|
||||
@ -161,10 +180,6 @@ def test_convert_video_to_playable_mp4(test_file_dir):
|
||||
assert gr.processing_utils.video_is_playable(playable_vid)
|
||||
|
||||
|
||||
def raise_ffmpy_runtime_exception():
|
||||
raise ffmpy.FFRuntimeError("", "", "", "")
|
||||
|
||||
|
||||
@patch("ffmpy.FFmpeg.run", side_effect=raise_ffmpy_runtime_exception)
|
||||
def test_video_conversion_returns_original_video_if_fails(mock_run, test_file_dir):
|
||||
with tempfile.NamedTemporaryFile(suffix="out.avi") as tmp_not_playable_vid:
|
||||
|
Loading…
Reference in New Issue
Block a user