Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix exception params
  • Loading branch information
kkroening committed May 20, 2018
commit 9a487e8603bf881519cd04afe34c1272adfa7d15
2 changes: 1 addition & 1 deletion ffmpeg/_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def probe(filename):
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
raise Error(err)
raise Error('ffprobe', out, err)
return json.loads(out.decode('utf-8'))


Expand Down
7 changes: 3 additions & 4 deletions ffmpeg/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@


class Error(Exception):
def __init__(self, stream_spec, stdout, stderr):
super(Error, self).__init__('ffmpeg error (see stderr output for detail)')
self.stream_spec = stream_spec
def __init__(self, cmd, stdout, stderr):
super(Error, self).__init__('{} error (see stderr output for detail)'.format(cmd))
self.stdout = stdout
self.stderr = stderr

Expand Down Expand Up @@ -197,7 +196,7 @@ def run(
out, err = p.communicate(input)
retcode = p.poll()
if retcode:
raise Error(stream_spec, out, err)
raise Error('ffmpeg', out, err)
return out, err


Expand Down
33 changes: 17 additions & 16 deletions ffmpeg/tests/test_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_stream_repr():
assert repr(dummy_out) == 'dummy()[{!r}] <{}>'.format(dummy_out.label, dummy_out.node.short_hash)


def test_get_args_simple():
def test__get_args__simple():
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4')
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4']

Expand Down Expand Up @@ -138,7 +138,7 @@ def _get_complex_filter_example():
)


def test_get_args_complex_filter():
def test__get_args__complex_filter():
out = _get_complex_filter_example()
args = ffmpeg.get_args(out)
assert args == ['-i', TEST_INPUT_FILE1,
Expand Down Expand Up @@ -309,13 +309,13 @@ def _get_drawtext_text_repr(text):
# subprocess.check_call(['ffmpeg', '-version'])


def test_compile():
def test__compile():
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4')
assert out_file.compile() == ['ffmpeg', '-i', 'dummy.mp4', 'dummy2.mp4']
assert out_file.compile(cmd='ffmpeg.old') == ['ffmpeg.old', '-i', 'dummy.mp4', 'dummy2.mp4']


def test_run():
def test__run():
stream = _get_complex_filter_example()
out, err = ffmpeg.run(stream)
assert out is None
Expand All @@ -324,7 +324,7 @@ def test_run():

@pytest.mark.parametrize('capture_stdout', [True, False])
@pytest.mark.parametrize('capture_stderr', [True, False])
def test_run__capture_out(mocker, capture_stdout, capture_stderr):
def test__run__capture_out(mocker, capture_stdout, capture_stderr):
mocker.patch.object(ffmpeg._run, 'compile', return_value=['echo', 'test'])
stream = _get_simple_example()
out, err = ffmpeg.run(stream, capture_stdout=capture_stdout, capture_stderr=capture_stderr)
Expand All @@ -338,7 +338,7 @@ def test_run__capture_out(mocker, capture_stdout, capture_stderr):
assert err is None


def test_run__input_output(mocker):
def test__run__input_output(mocker):
mocker.patch.object(ffmpeg._run, 'compile', return_value=['cat'])
stream = _get_simple_example()
out, err = ffmpeg.run(stream, input='test', capture_stdout=True)
Expand All @@ -348,11 +348,12 @@ def test_run__input_output(mocker):

@pytest.mark.parametrize('capture_stdout', [True, False])
@pytest.mark.parametrize('capture_stderr', [True, False])
def test_run__error(mocker, capture_stdout, capture_stderr):
def test__run__error(mocker, capture_stdout, capture_stderr):
mocker.patch.object(ffmpeg._run, 'compile', return_value=['ffmpeg'])
stream = _get_complex_filter_example()
with pytest.raises(ffmpeg.Error) as excinfo:
out, err = ffmpeg.run(stream, capture_stdout=capture_stdout, capture_stderr=capture_stderr)
assert str(excinfo.value) == 'ffmpeg error (see stderr output for detail)'
out = excinfo.value.stdout
err = excinfo.value.stderr
if capture_stdout:
Expand All @@ -365,24 +366,24 @@ def test_run__error(mocker, capture_stdout, capture_stderr):
assert err is None


def test_run__multi_output():
def test__run__multi_output():
in_ = ffmpeg.input(TEST_INPUT_FILE1)
out1 = in_.output(TEST_OUTPUT_FILE1)
out2 = in_.output(TEST_OUTPUT_FILE2)
ffmpeg.run([out1, out2], overwrite_output=True)


def test_run__dummy_cmd():
def test__run__dummy_cmd():
stream = _get_complex_filter_example()
ffmpeg.run(stream, cmd='true')


def test_run__dummy_cmd_list():
def test__run__dummy_cmd_list():
stream = _get_complex_filter_example()
ffmpeg.run(stream, cmd=['true', 'ignored'])


def test_filter__custom():
def test__filter__custom():
stream = ffmpeg.input('dummy.mp4')
stream = ffmpeg.filter_(stream, 'custom_filter', 'a', 'b', kwarg1='c')
stream = ffmpeg.output(stream, 'dummy2.mp4')
Expand All @@ -394,7 +395,7 @@ def test_filter__custom():
]


def test_filter__custom_fluent():
def test__filter__custom_fluent():
stream = (ffmpeg
.input('dummy.mp4')
.filter_('custom_filter', 'a', 'b', kwarg1='c')
Expand All @@ -408,7 +409,7 @@ def test_filter__custom_fluent():
]


def test_merge_outputs():
def test__merge_outputs():
in_ = ffmpeg.input('in.mp4')
out1 = in_.output('out1.mp4')
out2 = in_.output('out2.mp4')
Expand Down Expand Up @@ -484,14 +485,14 @@ def test_pipe():
assert out_data == in_data[start_frame*frame_size:]


def test_ffprobe():
def test__probe():
data = ffmpeg.probe(TEST_INPUT_FILE1)
assert set(data.keys()) == {'format', 'streams'}
assert data['format']['duration'] == '7.036000'


def test_ffprobe_exception():
def test__probe__exception():
with pytest.raises(ffmpeg.Error) as excinfo:
ffmpeg.probe(BOGUS_INPUT_FILE)
assert str(excinfo.value) == 'ffprobe error'
assert str(excinfo.value) == 'ffprobe error (see stderr output for detail)'
assert 'No such file or directory'.encode() in excinfo.value.stderr