fix tests
Browse files- tests/test_cli.py +25 -18
tests/test_cli.py
CHANGED
@@ -10,14 +10,18 @@ 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()
|
16 |
-
youtube.streams.all.return_value = []
|
17 |
youtube.streams.get_by_itag.return_value = None
|
|
|
18 |
with pytest.raises(SystemExit):
|
19 |
cli.download_by_itag(youtube, 123)
|
|
|
20 |
youtube.streams.get_by_itag.assert_called_with(123)
|
|
|
21 |
|
22 |
|
23 |
@mock.patch("pytube.cli.YouTube")
|
@@ -37,26 +41,28 @@ def test_download_when_itag_is_found(youtube, stream):
|
|
37 |
@mock.patch("pytube.cli.YouTube")
|
38 |
@mock.patch("pytube.Stream")
|
39 |
def test_display_stream(youtube, stream):
|
|
|
40 |
stream.itag = 123
|
41 |
stream.__repr__ = MagicMock(return_value="")
|
42 |
youtube.streams = StreamQuery([stream])
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
|
|
|
49 |
@mock.patch("pytube.cli.YouTube")
|
50 |
-
def test_download_caption_with_none(youtube):
|
|
|
51 |
caption = Caption(
|
52 |
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
53 |
)
|
54 |
youtube.captions = CaptionQuery([caption])
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
wrapped_all.assert_called()
|
60 |
|
61 |
|
62 |
@mock.patch("pytube.cli.YouTube")
|
@@ -71,17 +77,18 @@ def test_download_caption_with_language_found(youtube):
|
|
71 |
caption.download.assert_called_with(title="video title", output_path=None)
|
72 |
|
73 |
|
|
|
74 |
@mock.patch("pytube.cli.YouTube")
|
75 |
-
def
|
|
|
76 |
caption = Caption(
|
77 |
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
78 |
)
|
79 |
youtube.captions = CaptionQuery([caption])
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
wrapped_all.assert_called()
|
85 |
|
86 |
|
87 |
def test_display_progress_bar(capsys):
|
|
|
10 |
parse_args = cli._parse_args
|
11 |
|
12 |
|
13 |
+
@mock.patch("pytube.cli.display_streams")
|
14 |
@mock.patch("pytube.cli.YouTube")
|
15 |
+
def test_download_when_itag_not_found(youtube, display_streams):
|
16 |
+
# Given
|
17 |
youtube.streams = mock.Mock()
|
|
|
18 |
youtube.streams.get_by_itag.return_value = None
|
19 |
+
# When
|
20 |
with pytest.raises(SystemExit):
|
21 |
cli.download_by_itag(youtube, 123)
|
22 |
+
# Then
|
23 |
youtube.streams.get_by_itag.assert_called_with(123)
|
24 |
+
display_streams.assert_called_with(youtube)
|
25 |
|
26 |
|
27 |
@mock.patch("pytube.cli.YouTube")
|
|
|
41 |
@mock.patch("pytube.cli.YouTube")
|
42 |
@mock.patch("pytube.Stream")
|
43 |
def test_display_stream(youtube, stream):
|
44 |
+
# Given
|
45 |
stream.itag = 123
|
46 |
stream.__repr__ = MagicMock(return_value="")
|
47 |
youtube.streams = StreamQuery([stream])
|
48 |
+
# When
|
49 |
+
cli.display_streams(youtube)
|
50 |
+
# Then
|
51 |
+
stream.__repr__.assert_called()
|
52 |
|
53 |
|
54 |
+
@mock.patch("pytube.cli._print_available_captions")
|
55 |
@mock.patch("pytube.cli.YouTube")
|
56 |
+
def test_download_caption_with_none(youtube, print_available):
|
57 |
+
# Given
|
58 |
caption = Caption(
|
59 |
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
60 |
)
|
61 |
youtube.captions = CaptionQuery([caption])
|
62 |
+
# When
|
63 |
+
cli.download_caption(youtube, None)
|
64 |
+
# Then
|
65 |
+
print_available.assert_called_with(youtube.captions)
|
|
|
66 |
|
67 |
|
68 |
@mock.patch("pytube.cli.YouTube")
|
|
|
77 |
caption.download.assert_called_with(title="video title", output_path=None)
|
78 |
|
79 |
|
80 |
+
@mock.patch("pytube.cli._print_available_captions")
|
81 |
@mock.patch("pytube.cli.YouTube")
|
82 |
+
def test_download_caption_with_none(youtube, print_available):
|
83 |
+
# Given
|
84 |
caption = Caption(
|
85 |
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
86 |
)
|
87 |
youtube.captions = CaptionQuery([caption])
|
88 |
+
# When
|
89 |
+
cli.download_caption(youtube, "blah")
|
90 |
+
# Then
|
91 |
+
print_available.assert_called_with(youtube.captions)
|
|
|
92 |
|
93 |
|
94 |
def test_display_progress_bar(capsys):
|