X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=test%2Ftest_download.py;h=f1bccf58c5a2eaab0fbb8d60bb1185007eae0ee8;hb=b47bbac393be2b835ac5037def964f19305c28d4;hp=4a59f6638997df30864337f8473e9138463dbb80;hpb=511eda8eda5486ae7ea0ac685197d009164425f7;p=youtube-dl diff --git a/test/test_download.py b/test/test_download.py index 4a59f6638..f1bccf58c 100644 --- a/test/test_download.py +++ b/test/test_download.py @@ -26,6 +26,7 @@ cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar) proxy_handler = compat_urllib_request.ProxyHandler() opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) compat_urllib_request.install_opener(opener) +socket.setdefaulttimeout(10) def _try_rm(filename): """ Remove a file if it exists """ @@ -81,17 +82,24 @@ def generator(test_case): fd.add_info_extractor(ie()) for ien in test_case.get('add_ie', []): fd.add_info_extractor(getattr(youtube_dl.InfoExtractors, ien + 'IE')()) + finished_hook_called = set() + def _hook(status): + if status['status'] == 'finished': + finished_hook_called.add(status['filename']) + fd.add_progress_hook(_hook) test_cases = test_case.get('playlist', [test_case]) for tc in test_cases: _try_rm(tc['file']) + _try_rm(tc['file'] + '.part') _try_rm(tc['file'] + '.info.json') try: fd.download([test_case['url']]) for tc in test_cases: if not test_case.get('params', {}).get('skip_download', False): - self.assertTrue(os.path.exists(tc['file'])) + self.assertTrue(os.path.exists(tc['file']), msg='Missing file ' + tc['file']) + self.assertTrue(tc['file'] in finished_hook_called) self.assertTrue(os.path.exists(tc['file'] + '.info.json')) if 'md5' in tc: md5_for_file = _file_md5(tc['file']) @@ -99,14 +107,11 @@ def generator(test_case): with io.open(tc['file'] + '.info.json', encoding='utf-8') as infof: info_dict = json.load(infof) for (info_field, value) in tc.get('info_dict', {}).items(): - if value.startswith('md5:'): - md5_info_value = hashlib.md5(info_dict.get(info_field, '')).hexdigest() - self.assertEqual(value[3:], md5_info_value) - else: - self.assertEqual(value, info_dict.get(info_field)) + self.assertEqual(value, info_dict.get(info_field)) finally: for tc in test_cases: _try_rm(tc['file']) + _try_rm(tc['file'] + '.part') _try_rm(tc['file'] + '.info.json') return test_template