update tests and test doc

add (partially escaped) italics to test doc
add new test for `preserve_formatting=True`
This commit is contained in:
E. Seiver 2023-03-15 18:21:34 -07:00
parent c1a037c39c
commit c1e5ce4ebb
3 changed files with 16 additions and 4 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<transcript> <transcript>
<text start="0" dur="1.54">Hey, this is just a test</text> <text start="0" dur="1.54">Hey, this is just a test</text>
<text start="1.54" dur="4.16">this is not the original transcript</text> <text start="1.54" dur="4.16">this is &lt;i>not&lt;/i> the original transcript</text>
<text start="5" dur="0.5"></text> <text start="5" dur="0.5"></text>
<text start="5.7" dur="3.239">just something shorter, I made up for testing</text> <text start="5.7" dur="3.239">just something shorter, I made up for testing</text>
</transcript> </transcript>

View File

@ -61,6 +61,18 @@ class TestYouTubeTranscriptApi(TestCase):
] ]
) )
def test_get_transcript_formatted(self):
transcript = YouTubeTranscriptApi.get_transcript('GJLlxj_dtq8', preserve_formatting=True)
self.assertEqual(
transcript,
[
{'text': 'Hey, this is just a test', 'start': 0.0, 'duration': 1.54},
{'text': 'this is <i>not</i> the original transcript', 'start': 1.54, 'duration': 4.16},
{'text': 'just something shorter, I made up for testing', 'start': 5.7, 'duration': 3.239}
]
)
def test_list_transcripts(self): def test_list_transcripts(self):
transcript_list = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8') transcript_list = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8')
@ -254,11 +266,11 @@ class TestYouTubeTranscriptApi(TestCase):
{'text': 'just something shorter, I made up for testing', 'start': 5.7, 'duration': 3.239} {'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): def test_get_transcript__assertionerror_if_input_not_string(self):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
YouTubeTranscriptApi.get_transcript(['video_id_1', 'video_id_2']) YouTubeTranscriptApi.get_transcript(['video_id_1', 'video_id_2'])
def test_get_transcripts__assertionerror_if_input_not_list(self): def test_get_transcripts__assertionerror_if_input_not_list(self):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
YouTubeTranscriptApi.get_transcripts('video_id_1') YouTubeTranscriptApi.get_transcripts('video_id_1')

View File

@ -12,7 +12,7 @@ class TestYouTubeTranscriptCli(TestCase):
self.transcript_mock = MagicMock() self.transcript_mock = MagicMock()
self.transcript_mock.fetch = MagicMock(return_value=[ self.transcript_mock.fetch = MagicMock(return_value=[
{'text': 'Hey, this is just a test', 'start': 0.0, 'duration': 1.54}, {'text': 'Hey, this is just a test', 'start': 0.0, 'duration': 1.54},
{'text': 'this is not the original transcript', 'start': 1.54, 'duration': 4.16}, {'text': 'this is <i>not</i> the original transcript', 'start': 1.54, 'duration': 4.16},
{'text': 'just something shorter, I made up for testing', 'start': 5.7, 'duration': 3.239} {'text': 'just something shorter, I made up for testing', 'start': 5.7, 'duration': 3.239}
]) ])
self.transcript_mock.translate = MagicMock(return_value=self.transcript_mock) self.transcript_mock.translate = MagicMock(return_value=self.transcript_mock)