mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-22 18:22:21 +00:00
tests: build the filename from the info_dict if the 'file' key is missing
It will need to have the 'id' and 'ext' keys to work.
This commit is contained in:
parent
369a759acc
commit
702665c085
2 changed files with 24 additions and 17 deletions
|
@ -60,8 +60,11 @@ def generator(test_case):
|
||||||
if not ie._WORKING:
|
if not ie._WORKING:
|
||||||
print_skipping('IE marked as not _WORKING')
|
print_skipping('IE marked as not _WORKING')
|
||||||
return
|
return
|
||||||
if 'playlist' not in test_case and not test_case['file']:
|
if 'playlist' not in test_case:
|
||||||
print_skipping('No output file specified')
|
info_dict = test_case.get('info_dict', {})
|
||||||
|
if not test_case.get('file') and not (info_dict.get('id') and info_dict.get('ext')):
|
||||||
|
print_skipping('The output file cannot be know, the "file" '
|
||||||
|
'key is missing or the info_dict is incomplete')
|
||||||
return
|
return
|
||||||
if 'skip' in test_case:
|
if 'skip' in test_case:
|
||||||
print_skipping(test_case['skip'])
|
print_skipping(test_case['skip'])
|
||||||
|
@ -77,11 +80,17 @@ def generator(test_case):
|
||||||
finished_hook_called.add(status['filename'])
|
finished_hook_called.add(status['filename'])
|
||||||
ydl.fd.add_progress_hook(_hook)
|
ydl.fd.add_progress_hook(_hook)
|
||||||
|
|
||||||
|
def get_tc_filename(tc):
|
||||||
|
return tc.get('file') or ydl.prepare_filename(tc.get('info_dict', {}))
|
||||||
|
|
||||||
test_cases = test_case.get('playlist', [test_case])
|
test_cases = test_case.get('playlist', [test_case])
|
||||||
|
def try_rm_tcs_files():
|
||||||
for tc in test_cases:
|
for tc in test_cases:
|
||||||
try_rm(tc['file'])
|
tc_filename = get_tc_filename(tc)
|
||||||
try_rm(tc['file'] + '.part')
|
try_rm(tc_filename)
|
||||||
try_rm(tc['file'] + '.info.json')
|
try_rm(tc_filename + '.part')
|
||||||
|
try_rm(tc_filename + '.info.json')
|
||||||
|
try_rm_tcs_files()
|
||||||
try:
|
try:
|
||||||
for retry in range(1, RETRIES + 1):
|
for retry in range(1, RETRIES + 1):
|
||||||
try:
|
try:
|
||||||
|
@ -98,14 +107,15 @@ def generator(test_case):
|
||||||
break
|
break
|
||||||
|
|
||||||
for tc in test_cases:
|
for tc in test_cases:
|
||||||
|
tc_filename = get_tc_filename(tc)
|
||||||
if not test_case.get('params', {}).get('skip_download', False):
|
if not test_case.get('params', {}).get('skip_download', False):
|
||||||
self.assertTrue(os.path.exists(tc['file']), msg='Missing file ' + tc['file'])
|
self.assertTrue(os.path.exists(tc_filename), msg='Missing file ' + tc_filename)
|
||||||
self.assertTrue(tc['file'] in finished_hook_called)
|
self.assertTrue(tc_filename in finished_hook_called)
|
||||||
self.assertTrue(os.path.exists(tc['file'] + '.info.json'))
|
self.assertTrue(os.path.exists(tc_filename + '.info.json'))
|
||||||
if 'md5' in tc:
|
if 'md5' in tc:
|
||||||
md5_for_file = _file_md5(tc['file'])
|
md5_for_file = _file_md5(tc_filename)
|
||||||
self.assertEqual(md5_for_file, tc['md5'])
|
self.assertEqual(md5_for_file, tc['md5'])
|
||||||
with io.open(tc['file'] + '.info.json', encoding='utf-8') as infof:
|
with io.open(tc_filename + '.info.json', encoding='utf-8') as infof:
|
||||||
info_dict = json.load(infof)
|
info_dict = json.load(infof)
|
||||||
for (info_field, expected) in tc.get('info_dict', {}).items():
|
for (info_field, expected) in tc.get('info_dict', {}).items():
|
||||||
if isinstance(expected, compat_str) and expected.startswith('md5:'):
|
if isinstance(expected, compat_str) and expected.startswith('md5:'):
|
||||||
|
@ -126,10 +136,7 @@ def generator(test_case):
|
||||||
for key in ('id', 'url', 'title', 'ext'):
|
for key in ('id', 'url', 'title', 'ext'):
|
||||||
self.assertTrue(key in info_dict.keys() and info_dict[key])
|
self.assertTrue(key in info_dict.keys() and info_dict[key])
|
||||||
finally:
|
finally:
|
||||||
for tc in test_cases:
|
try_rm_tcs_files()
|
||||||
try_rm(tc['file'])
|
|
||||||
try_rm(tc['file'] + '.part')
|
|
||||||
try_rm(tc['file'] + '.info.json')
|
|
||||||
|
|
||||||
return test_template
|
return test_template
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ class YoutubeDL(object):
|
||||||
autonumber_size = 5
|
autonumber_size = 5
|
||||||
autonumber_templ = u'%0' + str(autonumber_size) + u'd'
|
autonumber_templ = u'%0' + str(autonumber_size) + u'd'
|
||||||
template_dict['autonumber'] = autonumber_templ % self._num_downloads
|
template_dict['autonumber'] = autonumber_templ % self._num_downloads
|
||||||
if template_dict['playlist_index'] is not None:
|
if template_dict.get('playlist_index') is not None:
|
||||||
template_dict['playlist_index'] = u'%05d' % template_dict['playlist_index']
|
template_dict['playlist_index'] = u'%05d' % template_dict['playlist_index']
|
||||||
|
|
||||||
sanitize = lambda k, v: sanitize_filename(
|
sanitize = lambda k, v: sanitize_filename(
|
||||||
|
|
Loading…
Reference in a new issue