test reprs
Browse files- pytube/contrib/playlist.py +1 -1
- pytube/query.py +8 -6
- tests/contrib/test_playlist.py +23 -0
- tests/test_captions.py +3 -0
- tests/test_mixins.py +0 -3
- tests/test_query.py +12 -0
pytube/contrib/playlist.py
CHANGED
@@ -155,7 +155,7 @@ class Playlist(Sequence):
|
|
155 |
@deprecated(
|
156 |
"This call is unnecessary, you can directly access .video_urls or .videos"
|
157 |
)
|
158 |
-
def populate_video_urls(self) -> List[str]:
|
159 |
"""Complete links of all the videos in playlist
|
160 |
|
161 |
:rtype: List[str]
|
|
|
155 |
@deprecated(
|
156 |
"This call is unnecessary, you can directly access .video_urls or .videos"
|
157 |
)
|
158 |
+
def populate_video_urls(self) -> List[str]: # pragma: no cover
|
159 |
"""Complete links of all the videos in playlist
|
160 |
|
161 |
:rtype: List[str]
|
pytube/query.py
CHANGED
@@ -327,16 +327,18 @@ class StreamQuery(Sequence):
|
|
327 |
pass
|
328 |
|
329 |
@deprecated("Get the size of this list directly using len()")
|
330 |
-
def count(self) -> int:
|
331 |
-
"""Get the count
|
332 |
|
333 |
:rtype: int
|
334 |
-
|
335 |
"""
|
336 |
-
|
|
|
|
|
|
|
337 |
|
338 |
@deprecated("This object can be treated as a list, all() is useless")
|
339 |
-
def all(self) -> List[Stream]:
|
340 |
"""Get all the results represented by this query as a list.
|
341 |
|
342 |
:rtype: list
|
@@ -380,7 +382,7 @@ class CaptionQuery(Sequence):
|
|
380 |
return self.lang_code_index.get(lang_code)
|
381 |
|
382 |
@deprecated("This object can be treated as a list, all() is useless")
|
383 |
-
def all(self) -> List[Caption]:
|
384 |
"""Get all the results represented by this query as a list.
|
385 |
|
386 |
:rtype: list
|
|
|
327 |
pass
|
328 |
|
329 |
@deprecated("Get the size of this list directly using len()")
|
330 |
+
def count(self, value: Optional[str] = None) -> int: # pragma: no cover
|
331 |
+
"""Get the count of items in the list.
|
332 |
|
333 |
:rtype: int
|
|
|
334 |
"""
|
335 |
+
if value:
|
336 |
+
return self.fmt_streams.count(value)
|
337 |
+
else:
|
338 |
+
return len(self)
|
339 |
|
340 |
@deprecated("This object can be treated as a list, all() is useless")
|
341 |
+
def all(self) -> List[Stream]: # pragma: no cover
|
342 |
"""Get all the results represented by this query as a list.
|
343 |
|
344 |
:rtype: list
|
|
|
382 |
return self.lang_code_index.get(lang_code)
|
383 |
|
384 |
@deprecated("This object can be treated as a list, all() is useless")
|
385 |
+
def all(self) -> List[Caption]: # pragma: no cover
|
386 |
"""Get all the results represented by this query as a list.
|
387 |
|
388 |
:rtype: list
|
tests/contrib/test_playlist.py
CHANGED
@@ -81,6 +81,29 @@ def test_video_urls(request_get, playlist_html):
|
|
81 |
]
|
82 |
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
@mock.patch("pytube.contrib.playlist.request.get")
|
85 |
def test_sequence(request_get, playlist_html):
|
86 |
url = "https://www.fakeurl.com/playlist?list=whatever"
|
|
|
81 |
]
|
82 |
|
83 |
|
84 |
+
@mock.patch("pytube.contrib.playlist.request.get")
|
85 |
+
def test_repr(request_get, playlist_html):
|
86 |
+
url = "https://www.fakeurl.com/playlist?list=whatever"
|
87 |
+
request_get.return_value = playlist_html
|
88 |
+
playlist = Playlist(url)
|
89 |
+
playlist._find_load_more_url = MagicMock(return_value=None)
|
90 |
+
request_get.assert_called()
|
91 |
+
assert (
|
92 |
+
repr(playlist) == "['https://www.youtube.com/watch?v=ujTCoH21GlA', "
|
93 |
+
"'https://www.youtube.com/watch?v=45ryDIPHdGg', "
|
94 |
+
"'https://www.youtube.com/watch?v=1BYu65vLKdA', "
|
95 |
+
"'https://www.youtube.com/watch?v=3AQ_74xrch8', "
|
96 |
+
"'https://www.youtube.com/watch?v=ddqQUz9mZaM', "
|
97 |
+
"'https://www.youtube.com/watch?v=vwLT6bZrHEE', "
|
98 |
+
"'https://www.youtube.com/watch?v=TQKI0KE-JYY', "
|
99 |
+
"'https://www.youtube.com/watch?v=dNBvQ38MlT8', "
|
100 |
+
"'https://www.youtube.com/watch?v=JHxyrMgOUWI', "
|
101 |
+
"'https://www.youtube.com/watch?v=l2I8NycJMCY', "
|
102 |
+
"'https://www.youtube.com/watch?v=g1Zbuk1gAfk', "
|
103 |
+
"'https://www.youtube.com/watch?v=zixd-si9Q-o']"
|
104 |
+
)
|
105 |
+
|
106 |
+
|
107 |
@mock.patch("pytube.contrib.playlist.request.get")
|
108 |
def test_sequence(request_get, playlist_html):
|
109 |
url = "https://www.fakeurl.com/playlist?list=whatever"
|
tests/test_captions.py
CHANGED
@@ -103,6 +103,9 @@ def test_repr():
|
|
103 |
)
|
104 |
assert str(caption) == '<Caption lang="name1" code="en">'
|
105 |
|
|
|
|
|
|
|
106 |
|
107 |
@mock.patch("pytube.request.get")
|
108 |
def test_xml_captions(request_get):
|
|
|
103 |
)
|
104 |
assert str(caption) == '<Caption lang="name1" code="en">'
|
105 |
|
106 |
+
caption_query = CaptionQuery(captions=[caption])
|
107 |
+
assert repr(caption_query) == '[<Caption lang="name1" code="en">]'
|
108 |
+
|
109 |
|
110 |
@mock.patch("pytube.request.get")
|
111 |
def test_xml_captions(request_get):
|
tests/test_mixins.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
def test_pre_signed_video(presigned_video):
|
3 |
-
assert presigned_video.streams.count() == 12
|
|
|
|
|
|
|
|
tests/test_query.py
CHANGED
@@ -159,3 +159,15 @@ def test_otf(cipher_signature):
|
|
159 |
|
160 |
otf = cipher_signature.streams.otf(True).all()
|
161 |
assert len(otf) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
otf = cipher_signature.streams.otf(True).all()
|
161 |
assert len(otf) == 0
|
162 |
+
|
163 |
+
|
164 |
+
def test_repr(cipher_signature):
|
165 |
+
assert repr(
|
166 |
+
cipher_signature.streams.filter(
|
167 |
+
progressive=True, subtype="mp4", resolution="360p"
|
168 |
+
)
|
169 |
+
) == (
|
170 |
+
'[<Stream: itag="18" mime_type="video/mp4" '
|
171 |
+
'res="360p" fps="30fps" vcodec="avc1.42001E" '
|
172 |
+
'acodec="mp4a.40.2" progressive="True" type="video">]'
|
173 |
+
)
|