def test_invalid_transcript_format(self, input_format, output_format): """ Tests that transcript conversion raises `AssertionError` on invalid input/output formats. """ with self.assertRaises(AssertionError): Transcript.convert(self.sjson_transcript, input_format, output_format)
def test_convert_invalid_srt_to_sjson(self): """ Tests that TranscriptsGenerationException was raises on trying to convert invalid srt transcript to sjson. """ invalid_srt_transcript = 'invalid SubRip file content' with self.assertRaises(TranscriptsGenerationException): Transcript.convert(invalid_srt_transcript, 'srt', 'sjson')
def test_convert_invalid_srt_to_sjson(self): """ Tests that TranscriptsGenerationException was raises on trying to convert invalid srt transcript to sjson. """ invalid_srt_transcript = 'invalid SubRip file content' with self.assertRaises(TranscriptsGenerationException): Transcript.convert(invalid_srt_transcript, 'srt', 'sjson')
def create_transcript_file(video_id, language_code, file_format, resource_fs, static_dir): """ Writes transcript file to file system. Arguments: video_id (str): Video id of the video transcript file is attached. language_code (str): Language code of the transcript. file_format (str): File format of the transcript file. static_dir (str): The Directory to store transcript file. resource_fs (SubFS): The file system to store transcripts. """ transcript_filename = '{video_id}-{language_code}.srt'.format( video_id=video_id, language_code=language_code ) transcript_data = get_video_transcript_data(video_id, language_code) if transcript_data: transcript_content = Transcript.convert( transcript_data['content'], input_format=file_format, output_format=Transcript.SRT ) if not resource_fs.exists(static_dir): resource_fs.makedir(static_dir) create_file_in_fs(transcript_content, transcript_filename, resource_fs, static_dir) return transcript_filename
def test_convert_srt_to_sjson(self): """ Tests that the srt transcript is successfully converted into sjson format. """ expected = self.sjson_transcript.decode('utf-8') actual = Transcript.convert(self.srt_transcript, 'srt', 'sjson') self.assertDictEqual(json.loads(actual), json.loads(expected))
def test_convert_sjson_to_srt(self): """ Tests that the sjson transcript is successfully converted into srt format. """ expected = self.srt_transcript.decode('utf-8') actual = Transcript.convert(self.sjson_transcript, 'sjson', 'srt') self.assertEqual(actual, expected)
def test_convert_srt_to_srt(self): """ Tests that srt to srt conversion works as expected. """ expected = self.srt_transcript.decode('utf-8') actual = Transcript.convert(self.srt_transcript, 'srt', 'srt') self.assertEqual(actual, expected)
def create_transcript_file(video_id, language_code, file_format, resource_fs, static_dir): """ Writes transcript file to file system. Arguments: video_id (str): Video id of the video transcript file is attached. language_code (str): Language code of the transcript. file_format (str): File format of the transcript file. static_dir (str): The Directory to store transcript file. resource_fs (SubFS): The file system to store transcripts. """ transcript_filename = '{video_id}-{language_code}.srt'.format( video_id=video_id, language_code=language_code ) transcript_data = get_video_transcript_data(video_id, language_code) if transcript_data: transcript_content = Transcript.convert( transcript_data['content'], input_format=file_format, output_format=Transcript.SRT ) create_file_in_fs(transcript_content, transcript_filename, resource_fs, static_dir) return transcript_filename
def test_convert_srt_to_sjson(self): """ Tests that the srt transcript is successfully converted into sjson format. """ expected = self.sjson_transcript.decode('utf-8') actual = Transcript.convert(self.srt_transcript, 'srt', 'sjson') self.assertDictEqual(json.loads(actual), json.loads(expected))
def test_convert_sjson_to_srt(self): """ Tests that the sjson transcript is successfully converted into srt format. """ expected = self.srt_transcript.decode('utf-8') actual = Transcript.convert(self.sjson_transcript, 'sjson', 'srt') self.assertEqual(actual, expected)
def test_convert_srt_to_srt(self): """ Tests that srt to srt conversion works as expected. """ expected = self.srt_transcript.decode('utf-8') actual = Transcript.convert(self.srt_transcript, 'srt', 'srt') self.assertEqual(actual, expected)
def test_invalid_transcript_format(self, input_format, output_format): """ Tests that transcript conversion raises `AssertionError` on invalid input/output formats. """ with self.assertRaises(AssertionError): Transcript.convert(self.sjson_transcript, input_format, output_format)