3 import io # for python 2
9 # Allow direct execution
11 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13 import youtube_dl.InfoExtractors
15 HEADER = u'''#!/usr/bin/env python
17 # DO NOT EDIT THIS FILE BY HAND!
18 # It is auto-generated from tests.json and gentests.py.
27 # Allow direct execution
29 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
31 from youtube_dl.FileDownloader import FileDownloader
32 import youtube_dl.InfoExtractors
35 with open(fn, 'rb') as f:
36 return hashlib.md5(f.read()).hexdigest()
38 def md5_for_file(filename, block_size=2**20):
39 with open(filename) as f:
42 data = f.read(block_size)
46 return md5.hexdigest()
47 _file_md5 = md5_for_file
49 class DownloadTest(unittest.TestCase):
50 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
56 with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf:
57 self.parameters = json.load(pf)
62 if __name__ == '__main__':
66 DEF_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tests.json')
67 TEST_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_download.py')
70 with io.open(DEF_FILE, encoding='utf-8') as deff:
71 defs = json.load(deff)
72 with io.open(TEST_FILE, 'w', encoding='utf-8') as testf:
75 write = lambda l: testf.write(spaces + l + '\n')
79 ie = getattr(youtube_dl.InfoExtractors, name + 'IE')
82 write('@unittest.skip("IE marked as not _WORKING")')
84 write('@unittest.skip("No output file specified")')
86 write('@unittest.skip(' + repr(d['skip']) + ')')
87 write('def test_' + name + '(self):')
88 write(' ' + name + 'IE = youtube_dl.InfoExtractors.' + name + 'IE')
89 write(' filename = ' + repr(d['file']))
90 write(' fd = FileDownloader(self.parameters)')
91 write(' fd.add_info_extractor(' + name + 'IE())')
92 for ien in d.get('addIEs', []):
93 write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + ien + 'IE())')
94 write(' fd.download([' + repr(d['url']) + '])')
95 write(' self.assertTrue(os.path.exists(filename))')
97 write(' self.assertEqual(os.path.getsize(filename), ' + repr(d['size']) + ')')
99 write(' md5_for_file = _file_md5(filename)')
100 write(' self.assertEqual(md5_for_file, ' + repr(d['md5']) + ')')
103 write('def tearDown(self):')
106 write(' if os.path.exists(' + repr(d['file']) + '):')
107 write(' os.remove(' + repr(d['file']) + ')')
109 write(' # No file specified for ' + d['name'])
113 if __name__ == '__main__':