8000 Add test for probe timeout and fix for Python2 · Powercoder64/ffmpeg-python@2d3a078 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d3a078

Browse files
committed
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.
1 parent 82a00e4 commit 2d3a078

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ffmpeg/_probe.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
1818
args += [filename]
1919

2020
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
21-
out, err = p.communicate(timeout=timeout)
21+
communicate_kwargs = {}
22+
if timeout is not None:
23+
communicate_kwargs['timeout'] = timeout
24+
out, err = p.communicate(**communicate_kwargs)
2225
if p.returncode != 0:
2326
raise Error('ffprobe', out, err)
2427
return json.loads(out.decode('utf-8'))

ffmpeg/tests/test_ffmpeg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import random
99
import re
1010
import subprocess
11+
import sys
1112

1213
try:
1314
import mock # python 2
@@ -706,6 +707,13 @@ def test__probe():
706707
assert data['format']['duration'] == '7.036000'
707708

708709

710+
@pytest.mark.skipif(sys.version_info < (3, 3), reason="requires python3.3 or higher")
711+
def test__probe_timeout():
712+
with pytest.raises(subprocess.TimeoutExpired) as excinfo:
713+
data = ffmpeg.probe(TEST_INPUT_FILE1, timeout=0)
714+
assert 'timed out after 0 seconds' in str(excinfo.value)
715+
716+
709717
def test__probe__exception():
710718
with pytest.raises(ffmpeg.Error) as excinfo:
711719
ffmpeg.probe(BOGUS_INPUT_FILE)

0 commit comments

Comments
 (0)
0