mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-08-10 13:10:03 +08:00
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:
parent
82a00e4849
commit
2d3a078f24
@ -18,7 +18,10 @@ def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
|
|||||||
args += [filename]
|
args += [filename]
|
||||||
|
|
||||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
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:
|
if p.returncode != 0:
|
||||||
raise Error('ffprobe', out, err)
|
raise Error('ffprobe', out, err)
|
||||||
return json.loads(out.decode('utf-8'))
|
return json.loads(out.decode('utf-8'))
|
||||||
|
@ -8,6 +8,7 @@ import pytest
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import mock # python 2
|
import mock # python 2
|
||||||
@ -706,6 +707,13 @@ def test__probe():
|
|||||||
assert data['format']['duration'] == '7.036000'
|
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():
|
def test__probe__exception():
|
||||||
with pytest.raises(ffmpeg.Error) as excinfo:
|
with pytest.raises(ffmpeg.Error) as excinfo:
|
||||||
ffmpeg.probe(BOGUS_INPUT_FILE)
|
ffmpeg.probe(BOGUS_INPUT_FILE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user