def test_convertible_substitles_ar_ttml(youtube_test_file): """ Regression test to make sure correct lang_code is detected from .ttml data. """ local_path = os.path.join("tests", "testcontent", "downloaded", "testsubtitles_ar.ttml") assert os.path.exists(local_path) subtitle_file = SubtitleFile(local_path, language='ar') filename = subtitle_file.process_file() assert filename, 'conferted filename must exit' assert filename.endswith( '.vtt'), 'conferted filename must have .vtt extension'
def test_convertible_substitles_ar_srt(): """ Basic check that srt --> vtt conversion works. """ local_path = os.path.join("tests", "testcontent", "samples", "testsubtitles_ar.srt") assert os.path.exists(local_path) subtitle_file = SubtitleFile(local_path, language='ar') filename = subtitle_file.process_file() assert filename, 'converted filename must exist' assert filename.endswith( '.vtt'), 'converted filename must have .vtt extension' storage_path = config.get_storage_path(filename) with open(storage_path) as converted_vtt: filecontents = converted_vtt.read() check_words = 'لناس على' assert check_words in filecontents, 'missing check word in converted subs'
def test_convertible_substitles_noext_subtitlesformat(): """ Check that we handle correctly cases when path doesn't contain extenstion. """ local_path = os.path.join("tests", "testcontent", "downloaded", "testsubtitles_ar.ttml") assert os.path.exists(local_path) local_path_no_ext = local_path.replace('.ttml', '') copyfile(local_path, local_path_no_ext) assert os.path.exists(local_path_no_ext) subtitle_file = SubtitleFile( local_path_no_ext, language='ar', subtitlesformat='ttml' # settting subtitlesformat becaue no ext ) filename = subtitle_file.process_file() assert filename, 'conferted filename must exit' assert filename.endswith( '.vtt'), 'conferted filename must have .vtt extension'
def test_convertible_substitles_from_pressurcooker(pressurcooker_test_files): """ Try to load all the test files used in pressurecooker as riceccooker `SubtitleFile`s. All subs have the appropriate extension so no need to specify `subtitlesformat`. """ for fixture in pressurcooker_test_files: localpath = fixture['localpath'] assert os.path.exists( localpath), 'Error mising local test file ' + localpath subtitle_file = SubtitleFile(localpath, language=fixture['language']) filename = subtitle_file.process_file() assert filename, 'conferted filename must exit' assert filename.endswith( '.vtt'), 'conferted filename must have .vtt extension' storage_path = config.get_storage_path(filename) with open(storage_path) as converted_vtt: filecontents = converted_vtt.read() assert fixture[ 'check_words'] in filecontents, 'missing check_words in converted subs'
def test_convertible_substitles_weirdext_subtitlesformat(): """ Check that we handle cases when ext cannot be guessed from URL or localpath. Passing `subtitlesformat` allows chef authors to manually specify subs format. """ subs_url = 'https://commons.wikimedia.org/w/api.php?' \ + 'action=timedtext&title=File%3AA_Is_for_Atom_1953.webm&lang=es&trackformat=srt' subtitle_file = SubtitleFile( subs_url, language='es', subtitlesformat= 'srt' # set subtitlesformat when can't inferr ext form url ) filename = subtitle_file.process_file() assert filename, 'conferted filename must exit' assert filename.endswith( '.vtt'), 'conferted filename must have .vtt extension' storage_path = config.get_storage_path(filename) with open(storage_path) as converted_vtt: filecontents = converted_vtt.read() assert 'El total de los protones y neutrones de un átomo' in filecontents, \ 'missing check words in converted subs'