additional tests
Browse files- tests/test_cli.py +26 -0
tests/test_cli.py
CHANGED
@@ -10,6 +10,15 @@ from pytube import cli, StreamQuery, Caption, CaptionQuery
|
|
10 |
parse_args = cli._parse_args
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
@mock.patch("pytube.cli.YouTube")
|
14 |
def test_download_when_itag_not_found(youtube):
|
15 |
youtube.streams = mock.Mock()
|
@@ -272,6 +281,23 @@ def test_ffmpeg_process_res_should_download(_ffmpeg_downloader, youtube):
|
|
272 |
)
|
273 |
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
@mock.patch("pytube.cli.YouTube.__init__", return_value=None)
|
276 |
def test_download_audio(youtube):
|
277 |
parser = argparse.ArgumentParser()
|
|
|
10 |
parse_args = cli._parse_args
|
11 |
|
12 |
|
13 |
+
@mock.patch("pytube.cli._parse_args")
|
14 |
+
def test_main_invalid_url(_parse_args):
|
15 |
+
parser = argparse.ArgumentParser()
|
16 |
+
args = parse_args(parser, ["crikey",],)
|
17 |
+
_parse_args.return_value = args
|
18 |
+
with pytest.raises(SystemExit):
|
19 |
+
cli.main()
|
20 |
+
|
21 |
+
|
22 |
@mock.patch("pytube.cli.YouTube")
|
23 |
def test_download_when_itag_not_found(youtube):
|
24 |
youtube.streams = mock.Mock()
|
|
|
281 |
)
|
282 |
|
283 |
|
284 |
+
@mock.patch("pytube.cli.YouTube")
|
285 |
+
@mock.patch("pytube.cli._ffmpeg_downloader")
|
286 |
+
def test_ffmpeg_process_res_none_should_not_download(_ffmpeg_downloader, youtube):
|
287 |
+
# Given
|
288 |
+
target = "/target"
|
289 |
+
streams = MagicMock()
|
290 |
+
youtube.streams = streams
|
291 |
+
streams.filter.return_value.first.return_value = None
|
292 |
+
audio_stream = MagicMock()
|
293 |
+
streams.get_audio_only.return_value = audio_stream
|
294 |
+
# When
|
295 |
+
with pytest.raises(SystemExit):
|
296 |
+
cli.ffmpeg_process(youtube, "XYZp", target)
|
297 |
+
# Then
|
298 |
+
_ffmpeg_downloader.assert_not_called()
|
299 |
+
|
300 |
+
|
301 |
@mock.patch("pytube.cli.YouTube.__init__", return_value=None)
|
302 |
def test_download_audio(youtube):
|
303 |
parser = argparse.ArgumentParser()
|