8 from youtube_dl.FileDownloader import FileDownloader
9 #import all the info extractor
12 DEF_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tests.json')
13 PARAM_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'parameters.json'
17 class TestDownload(unittest.TestCase):
21 def md5_for_file(filename, block_size=2**20):
22 with open(filename) as f:
25 data = f.read(block_size)
29 return md5.hexdigest()
32 def generator(name, url, md5, file, ie_param, optional_ie):
33 def test_template(self):
34 fd = FileDownloader(ie_param)
35 fd.add_info_extractor(getattr(youtube_dl, name + "IE")())
37 self.assertTrue(os.path.exists(file))
38 self.assertEqual(md5_for_file(file), md5)
42 def clean_generator(files):
43 def clean_template(self):
44 for file_name in files:
45 if os.path.exists(file_name):
49 with open(DEF_FILE, "r") as f:
50 with open(PARAM_FILE) as fp:
52 test_param = json.load(f)
54 for test_case in test_param:
55 if test_case.get("broken", False):
58 files.add(test_case["file"])
59 test_method = generator(test_case['name'], test_case['url'], test_case['md5'], test_case['file'], p, test_case.get('add_ie', []))
60 test_method.__name__ = "test_{0}".format(test_case["name"])
61 setattr(TestDownload, test_method.__name__, test_method)
64 sys.stderr.write("Issue with the parameters of test {0}.\n".format(test_case.get("name", "unknown test")))
66 ff = clean_generator(files)
67 ff.__name__ = "tearDown"
68 setattr(TestDownload, ff.__name__, ff)
72 if __name__ == '__main__':