better testing for download_by_resolution
Browse files- tests/test_cli.py +19 -9
tests/test_cli.py
CHANGED
@@ -122,7 +122,7 @@ def test_parse_args_truthy():
|
|
122 |
assert args.list is True
|
123 |
|
124 |
|
125 |
-
@mock.patch("pytube.cli.YouTube
|
126 |
def test_main_download_by_itag(youtube):
|
127 |
parser = argparse.ArgumentParser()
|
128 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "--itag=10"])
|
@@ -133,7 +133,7 @@ def test_main_download_by_itag(youtube):
|
|
133 |
cli.download_by_itag.assert_called()
|
134 |
|
135 |
|
136 |
-
@mock.patch("pytube.cli.YouTube
|
137 |
def test_main_build_playback_report(youtube):
|
138 |
parser = argparse.ArgumentParser()
|
139 |
args = parse_args(
|
@@ -146,7 +146,7 @@ def test_main_build_playback_report(youtube):
|
|
146 |
cli.build_playback_report.assert_called()
|
147 |
|
148 |
|
149 |
-
@mock.patch("pytube.cli.YouTube
|
150 |
def test_main_display_streams(youtube):
|
151 |
parser = argparse.ArgumentParser()
|
152 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-l"])
|
@@ -157,7 +157,7 @@ def test_main_display_streams(youtube):
|
|
157 |
cli.display_streams.assert_called()
|
158 |
|
159 |
|
160 |
-
@mock.patch("pytube.cli.YouTube
|
161 |
def test_main_download_caption(youtube):
|
162 |
parser = argparse.ArgumentParser()
|
163 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-c"])
|
@@ -168,15 +168,15 @@ def test_main_download_caption(youtube):
|
|
168 |
cli.download_caption.assert_called()
|
169 |
|
170 |
|
171 |
-
@mock.patch("pytube.cli.YouTube
|
172 |
-
|
|
|
173 |
parser = argparse.ArgumentParser()
|
174 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-r", "320p"])
|
175 |
cli._parse_args = MagicMock(return_value=args)
|
176 |
-
cli.download_by_resolution = MagicMock()
|
177 |
cli.main()
|
178 |
youtube.assert_called()
|
179 |
-
|
180 |
|
181 |
|
182 |
@mock.patch("pytube.cli.Playlist")
|
@@ -185,6 +185,16 @@ def test_download_with_playlist(playlist):
|
|
185 |
parser = argparse.ArgumentParser()
|
186 |
args = parse_args(parser, ["https://www.youtube.com/playlist?list=PLyn"])
|
187 |
cli._parse_args = MagicMock(return_value=args)
|
188 |
-
cli.download_by_resolution = MagicMock()
|
189 |
cli.main()
|
190 |
playlist.assert_called()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
assert args.list is True
|
123 |
|
124 |
|
125 |
+
@mock.patch("pytube.cli.YouTube", return_value=None)
|
126 |
def test_main_download_by_itag(youtube):
|
127 |
parser = argparse.ArgumentParser()
|
128 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "--itag=10"])
|
|
|
133 |
cli.download_by_itag.assert_called()
|
134 |
|
135 |
|
136 |
+
@mock.patch("pytube.cli.YouTube", return_value=None)
|
137 |
def test_main_build_playback_report(youtube):
|
138 |
parser = argparse.ArgumentParser()
|
139 |
args = parse_args(
|
|
|
146 |
cli.build_playback_report.assert_called()
|
147 |
|
148 |
|
149 |
+
@mock.patch("pytube.cli.YouTube", return_value=None)
|
150 |
def test_main_display_streams(youtube):
|
151 |
parser = argparse.ArgumentParser()
|
152 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-l"])
|
|
|
157 |
cli.display_streams.assert_called()
|
158 |
|
159 |
|
160 |
+
@mock.patch("pytube.cli.YouTube", return_value=None)
|
161 |
def test_main_download_caption(youtube):
|
162 |
parser = argparse.ArgumentParser()
|
163 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-c"])
|
|
|
168 |
cli.download_caption.assert_called()
|
169 |
|
170 |
|
171 |
+
@mock.patch("pytube.cli.YouTube", return_value=None)
|
172 |
+
@mock.patch("pytube.cli.download_by_resolution")
|
173 |
+
def test_download_by_resolution_flag(youtube, download_by_resolution):
|
174 |
parser = argparse.ArgumentParser()
|
175 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-r", "320p"])
|
176 |
cli._parse_args = MagicMock(return_value=args)
|
|
|
177 |
cli.main()
|
178 |
youtube.assert_called()
|
179 |
+
download_by_resolution.assert_called()
|
180 |
|
181 |
|
182 |
@mock.patch("pytube.cli.Playlist")
|
|
|
185 |
parser = argparse.ArgumentParser()
|
186 |
args = parse_args(parser, ["https://www.youtube.com/playlist?list=PLyn"])
|
187 |
cli._parse_args = MagicMock(return_value=args)
|
|
|
188 |
cli.main()
|
189 |
playlist.assert_called()
|
190 |
+
|
191 |
+
|
192 |
+
@mock.patch("pytube.cli.YouTube")
|
193 |
+
@mock.patch("pytube.StreamQuery")
|
194 |
+
@mock.patch("pytube.Stream")
|
195 |
+
def test_download_by_resolution(youtube, stream_query, stream):
|
196 |
+
stream_query.get_by_resolution.return_value = stream
|
197 |
+
youtube.streams = stream_query
|
198 |
+
cli._download = MagicMock()
|
199 |
+
cli.download_by_resolution(youtube=youtube, resolution="320p", target="test_target")
|
200 |
+
cli._download.assert_called_with(stream, target="test_target")
|