From 2fff94af6c61530230d27c1a2e84ac1f1bc07c0c Mon Sep 17 00:00:00 2001 From: Karl Kroening <karlk@kralnet.us> Date: Sat, 27 Jan 2018 22:51:05 -0800 Subject: [PATCH] Fix probe exception handling and add test --- ffmpeg/_probe.py | 3 ++- ffmpeg/tests/test_ffmpeg.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ffmpeg/_probe.py b/ffmpeg/_probe.py index 0287939..ea3a52c 100755 --- a/ffmpeg/_probe.py +++ b/ffmpeg/_probe.py @@ -19,10 +19,11 @@ def probe(filename): p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if p.returncode != 0: - raise ExecException(err) + raise ProbeException(err) return json.loads(out.decode('utf-8')) __all__ = [ 'probe', + 'ProbeException', ] diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 2650f12..07c5c4b 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -16,6 +16,7 @@ TEST_INPUT_FILE1 = os.path.join(SAMPLE_DATA_DIR, 'in1.mp4') TEST_OVERLAY_FILE = os.path.join(SAMPLE_DATA_DIR, 'overlay.png') TEST_OUTPUT_FILE1 = os.path.join(SAMPLE_DATA_DIR, 'out1.mp4') TEST_OUTPUT_FILE2 = os.path.join(SAMPLE_DATA_DIR, 'out2.mp4') +BOGUS_INPUT_FILE = os.path.join(SAMPLE_DATA_DIR, 'bogus') subprocess.check_call(['ffmpeg', '-version']) @@ -359,3 +360,10 @@ def test_ffprobe(): data = ffmpeg.probe(TEST_INPUT_FILE1) assert set(data.keys()) == {'format', 'streams'} assert data['format']['duration'] == '7.036000' + + +def test_ffprobe_exception(): + with pytest.raises(ffmpeg.ProbeException) as excinfo: + ffmpeg.probe(BOGUS_INPUT_FILE) + assert excinfo.value.message == 'ffprobe error' + assert 'No such file or directory' in excinfo.value.stderr_output