added test cases for SRTFormmater
This commit is contained in:
		
							parent
							
								
									68ca703ae0
								
							
						
					
					
						commit
						a78f493386
					
				|  | @ -8,6 +8,7 @@ from youtube_transcript_api.formatters import ( | ||||||
|     Formatter, |     Formatter, | ||||||
|     JSONFormatter, |     JSONFormatter, | ||||||
|     TextFormatter, |     TextFormatter, | ||||||
|  |     SRTFormatter, | ||||||
|     WebVTTFormatter, |     WebVTTFormatter, | ||||||
|     PrettyPrintFormatter, FormatterLoader |     PrettyPrintFormatter, FormatterLoader | ||||||
| ) | ) | ||||||
|  | @ -28,6 +29,25 @@ class TestFormatters(TestCase): | ||||||
|         with self.assertRaises(NotImplementedError): |         with self.assertRaises(NotImplementedError): | ||||||
|             Formatter().format_transcripts([self.transcript]) |             Formatter().format_transcripts([self.transcript]) | ||||||
| 
 | 
 | ||||||
|  |     def test_srt_formatter(self): | ||||||
|  |         content = SRTFormatter().format_transcript(self.transcript) | ||||||
|  |         lines = content.split('\n') | ||||||
|  | 
 | ||||||
|  |         # test starting lines | ||||||
|  |         self.assertEqual(lines[0], "1") | ||||||
|  |         self.assertEqual(lines[1], "00:00:00,000 --> 00:00:01,500") | ||||||
|  | 
 | ||||||
|  |         # test end lines | ||||||
|  |         self.assertEqual(lines[-2], self.transcript[-1]['text']) | ||||||
|  |         self.assertEqual(lines[-1], "") | ||||||
|  | 
 | ||||||
|  |     def test_srt_formatter_many(self): | ||||||
|  |         formatter = SRTFormatter() | ||||||
|  |         content = formatter.format_transcripts(self.transcripts) | ||||||
|  |         formatted_single_transcript = formatter.format_transcript(self.transcript) | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(content, formatted_single_transcript + '\n\n\n' + formatted_single_transcript) | ||||||
|  | 
 | ||||||
|     def test_webvtt_formatter_starting(self): |     def test_webvtt_formatter_starting(self): | ||||||
|         content = WebVTTFormatter().format_transcript(self.transcript) |         content = WebVTTFormatter().format_transcript(self.transcript) | ||||||
|         lines = content.split('\n') |         lines = content.split('\n') | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue