add ffmpeg audio fallback tests
Browse files- tests/test_cli.py +37 -0
tests/test_cli.py
CHANGED
@@ -305,6 +305,43 @@ def test_ffmpeg_process_res_none_should_not_download(_ffmpeg_downloader, youtube
|
|
305 |
_ffmpeg_downloader.assert_not_called()
|
306 |
|
307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
@mock.patch("pytube.cli.os.unlink", return_value=None)
|
309 |
@mock.patch("pytube.cli.subprocess.run", return_value=None)
|
310 |
@mock.patch("pytube.cli._download", return_value=None)
|
|
|
305 |
_ffmpeg_downloader.assert_not_called()
|
306 |
|
307 |
|
308 |
+
@mock.patch("pytube.cli.YouTube")
|
309 |
+
@mock.patch("pytube.cli._ffmpeg_downloader")
|
310 |
+
def test_ffmpeg_process_audio_none_should_fallback_download(
|
311 |
+
_ffmpeg_downloader, youtube
|
312 |
+
):
|
313 |
+
# Given
|
314 |
+
target = "/target"
|
315 |
+
streams = MagicMock()
|
316 |
+
youtube.streams = streams
|
317 |
+
stream = MagicMock()
|
318 |
+
streams.filter.return_value.order_by.return_value.last.return_value = stream
|
319 |
+
streams.get_audio_only.return_value = None
|
320 |
+
# When
|
321 |
+
cli.ffmpeg_process(youtube, "best", target)
|
322 |
+
# Then
|
323 |
+
_ffmpeg_downloader.assert_called_with(
|
324 |
+
audio_stream=stream, video_stream=stream, target=target
|
325 |
+
)
|
326 |
+
|
327 |
+
|
328 |
+
@mock.patch("pytube.cli.YouTube")
|
329 |
+
@mock.patch("pytube.cli._ffmpeg_downloader")
|
330 |
+
def test_ffmpeg_process_audio_fallback_none_should_exit(_ffmpeg_downloader, youtube):
|
331 |
+
# Given
|
332 |
+
target = "/target"
|
333 |
+
streams = MagicMock()
|
334 |
+
youtube.streams = streams
|
335 |
+
stream = MagicMock()
|
336 |
+
streams.filter.return_value.order_by.return_value.last.side_effect = [stream, None]
|
337 |
+
streams.get_audio_only.return_value = None
|
338 |
+
# When
|
339 |
+
with pytest.raises(SystemExit):
|
340 |
+
cli.ffmpeg_process(youtube, "best", target)
|
341 |
+
# Then
|
342 |
+
_ffmpeg_downloader.assert_not_called()
|
343 |
+
|
344 |
+
|
345 |
@mock.patch("pytube.cli.os.unlink", return_value=None)
|
346 |
@mock.patch("pytube.cli.subprocess.run", return_value=None)
|
347 |
@mock.patch("pytube.cli._download", return_value=None)
|