Add test for probe timeout and fix for Python2

Fix for Python2 so that timeout is only used as keyword argument if it
is provided

Added a test for the new timeout argument that will run for Python >
3.3.
This commit is contained in:
magnusvmt 2019-11-02 16:17:17 +01:00
parent 82a00e4849
commit 2d3a078f24
2 changed files with 12 additions and 1 deletions

View File

@ -18,7 +18,10 @@ def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
args += [filename]
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate(timeout=timeout)
communicate_kwargs = {}
if timeout is not None:
communicate_kwargs['timeout'] = timeout
out, err = p.communicate(**communicate_kwargs)
if p.returncode != 0:
raise Error('ffprobe', out, err)
return json.loads(out.decode('utf-8'))

View File

@ -8,6 +8,7 @@ import pytest
import random
import re
import subprocess
import sys
try:
import mock # python 2
@ -706,6 +707,13 @@ def test__probe():
assert data['format']['duration'] == '7.036000'
@pytest.mark.skipif(sys.version_info < (3, 3), reason="requires python3.3 or higher")
def test__probe_timeout():
with pytest.raises(subprocess.TimeoutExpired) as excinfo:
data = ffmpeg.probe(TEST_INPUT_FILE1, timeout=0)
assert 'timed out after 0 seconds' in str(excinfo.value)
def test__probe__exception():
with pytest.raises(ffmpeg.Error) as excinfo:
ffmpeg.probe(BOGUS_INPUT_FILE)