added error message to assert statement
This commit is contained in:
parent
8c38df9939
commit
e884646c16
|
@ -92,6 +92,8 @@ class YouTubeTranscriptApi(object):
|
|||
video ids, which could not be retrieved
|
||||
:rtype ({str: [{'text': str, 'start': float, 'end': float}]}, [str]}):
|
||||
"""
|
||||
assert isinstance(video_ids, list), "`video_ids` must be a list of strings"
|
||||
|
||||
data = {}
|
||||
unretrievable_videos = []
|
||||
|
||||
|
@ -126,6 +128,7 @@ class YouTubeTranscriptApi(object):
|
|||
:return: a list of dictionaries containing the 'text', 'start' and 'duration' keys
|
||||
:rtype [{'text': str, 'start': float, 'end': float}]:
|
||||
"""
|
||||
assert isinstance(video_id, str), "`video_id` must be a string"
|
||||
return cls.list_transcripts(video_id, proxies, cookies).find_transcript(languages).fetch()
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from ast import Assert
|
||||
from unittest import TestCase
|
||||
from mock import patch
|
||||
|
||||
|
@ -254,6 +255,24 @@ class TestYouTubeTranscriptApi(TestCase):
|
|||
{'text': 'just something shorter, I made up for testing', 'start': 5.7, 'duration': 3.239}
|
||||
]
|
||||
)
|
||||
|
||||
def test_get_transcript__assertionerror_if_input_not_string(self):
|
||||
"""
|
||||
Raise Assertion error if not expected type
|
||||
"""
|
||||
with self.assertRaises(AssertionError):
|
||||
YouTubeTranscriptApi.get_transcript(['video_id_1', 'video_id_2'])
|
||||
# YouTubeTranscriptApi.get_transcripts(['video_id_1', 'video_id_2'])
|
||||
|
||||
def test_get_transcripts__assertionerror_if_input_not_list(self):
|
||||
"""
|
||||
Raise Assertion error if not expected type
|
||||
"""
|
||||
with self.assertRaises(AssertionError):
|
||||
YouTubeTranscriptApi.get_transcripts('video_id_1')
|
||||
# YouTubeTranscriptApi.get_transcripts(['video_id_1', 'video_id_2'])
|
||||
|
||||
|
||||
|
||||
@patch('youtube_transcript_api.YouTubeTranscriptApi.get_transcript')
|
||||
def test_get_transcripts(self, mock_get_transcript):
|
||||
|
|
Loading…
Reference in New Issue