[test/YoutubeDL] Add test for subtitles
Updated the offlinetest make target to not skip it
This commit is contained in:
parent
03091e372f
commit
ab84349b16
2
Makefile
2
Makefile
|
@ -43,7 +43,7 @@ test:
|
||||||
ot: offlinetest
|
ot: offlinetest
|
||||||
|
|
||||||
offlinetest: codetest
|
offlinetest: codetest
|
||||||
nosetests --verbose test --exclude test_download --exclude test_age_restriction --exclude test_subtitles --exclude test_write_annotations --exclude test_youtube_lists
|
nosetests --verbose test --exclude test_download.py --exclude test_age_restriction.py --exclude test_subtitles.py --exclude test_write_annotations.py --exclude test_youtube_lists.py
|
||||||
|
|
||||||
tar: youtube-dl.tar.gz
|
tar: youtube-dl.tar.gz
|
||||||
|
|
||||||
|
|
|
@ -337,6 +337,58 @@ class TestFormatSelection(unittest.TestCase):
|
||||||
downloaded = ydl.downloaded_info_dicts[0]
|
downloaded = ydl.downloaded_info_dicts[0]
|
||||||
self.assertEqual(downloaded['format_id'], 'G')
|
self.assertEqual(downloaded['format_id'], 'G')
|
||||||
|
|
||||||
|
def test_subtitles(self):
|
||||||
|
def s_formats(lang, autocaption=False):
|
||||||
|
return [{
|
||||||
|
'ext': ext,
|
||||||
|
'url': 'http://localhost/video.%s.%s' % (lang, ext),
|
||||||
|
'_auto': autocaption,
|
||||||
|
} for ext in ['vtt', 'srt', 'ass']]
|
||||||
|
subtitles = dict((l, s_formats(l)) for l in ['en', 'fr', 'es'])
|
||||||
|
auto_captions = dict((l, s_formats(l, True)) for l in ['it', 'pt', 'es'])
|
||||||
|
info_dict = {
|
||||||
|
'id': 'test',
|
||||||
|
'title': 'Test',
|
||||||
|
'url': 'http://localhost/video.mp4',
|
||||||
|
'subtitles': subtitles,
|
||||||
|
'automatic_captions': auto_captions,
|
||||||
|
'extractor': 'TEST',
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_info(params={}):
|
||||||
|
params.setdefault('simulate', True)
|
||||||
|
ydl = YDL(params)
|
||||||
|
ydl.report_warning = lambda *args, **kargs: None
|
||||||
|
return ydl.process_video_result(info_dict, download=False)
|
||||||
|
|
||||||
|
result = get_info()
|
||||||
|
self.assertFalse(result.get('requested_subtitles'))
|
||||||
|
self.assertEqual(result['subtitles'], subtitles)
|
||||||
|
self.assertEqual(result['automatic_captions'], auto_captions)
|
||||||
|
|
||||||
|
result = get_info({'writesubtitles': True})
|
||||||
|
subs = result['requested_subtitles']
|
||||||
|
self.assertTrue(subs)
|
||||||
|
self.assertEqual(set(subs.keys()), set(['en']))
|
||||||
|
self.assertTrue(subs['en'].get('data') is None)
|
||||||
|
self.assertEqual(subs['en']['ext'], 'ass')
|
||||||
|
|
||||||
|
result = get_info({'writesubtitles': True, 'subtitlesformat': 'foo/srt'})
|
||||||
|
subs = result['requested_subtitles']
|
||||||
|
self.assertEqual(subs['en']['ext'], 'srt')
|
||||||
|
|
||||||
|
result = get_info({'writesubtitles': True, 'subtitleslangs': ['es', 'fr', 'it']})
|
||||||
|
subs = result['requested_subtitles']
|
||||||
|
self.assertTrue(subs)
|
||||||
|
self.assertEqual(set(subs.keys()), set(['es', 'fr']))
|
||||||
|
|
||||||
|
result = get_info({'writesubtitles': True, 'writeautomaticsub': True, 'subtitleslangs': ['es', 'pt']})
|
||||||
|
subs = result['requested_subtitles']
|
||||||
|
self.assertTrue(subs)
|
||||||
|
self.assertEqual(set(subs.keys()), set(['es', 'pt']))
|
||||||
|
self.assertFalse(subs['es']['_auto'])
|
||||||
|
self.assertTrue(subs['pt']['_auto'])
|
||||||
|
|
||||||
def test_add_extra_info(self):
|
def test_add_extra_info(self):
|
||||||
test_dict = {
|
test_dict = {
|
||||||
'extractor': 'Foo',
|
'extractor': 'Foo',
|
||||||
|
|
Loading…
Reference in New Issue