]>
jfr.im git - yt-dlp.git/blob - test/gentests.py
9352d6d94931812f1cfb79519801d52bd1a5456d
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 _skip_unless = unittest.skipUnless
39 except AttributeError: # Python 2.6
40 def _skip_unless(cond, reason='No reason given'):
42 # Start the function name with test to appease nosetests-2.6
43 def test_wfunc(*args, **kwargs):
45 return f(*args, **kwargs)
51 _skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs)
53 class DownloadTest(unittest.TestCase):
54 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
60 with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf:
61 self.parameters = json.load(pf)
66 if __name__ == '__main__':
70 DEF_FILE
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'tests.json')
71 TEST_FILE
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'test_download.py')
74 with io
.open(DEF_FILE
, encoding
='utf-8') as deff
:
75 defs
= json
.load(deff
)
76 with io
.open(TEST_FILE
, 'w', encoding
='utf-8') as testf
:
79 write
= lambda l
: testf
.write(spaces
+ l
+ '\n')
83 ie
= getattr(youtube_dl
.InfoExtractors
, name
+ 'IE')
85 write('@_skip_unless(youtube_dl.InfoExtractors.' + name
+ 'IE._WORKING, "IE marked as not _WORKING")')
87 write('@_skip("No output file specified")')
89 write('@_skip(' + repr(d
['skip']) + ')')
90 write('def test_' + name
+ '(self):')
91 write(' filename = ' + repr(d
['file']))
92 write(' fd = FileDownloader(self.parameters)')
93 write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + name
+ 'IE())')
94 for ien
in d
.get('addIEs', []):
95 write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + ien
+ 'IE())')
96 write(' fd.download([' + repr(d
['url']) + '])')
97 write(' self.assertTrue(os.path.exists(filename))')
99 write(' self.assertEqual(os.path.getsize(filename), ' + repr(d
['size']) + ')')
101 write(' md5_for_file = _file_md5(filename)')
102 write(' self.assertEqual(md5_for_file, ' + repr(d
['md5']) + ')')
105 write('def tearDown(self):')
108 write(' if os.path.exists(' + repr(d
['file']) + '):')
109 write(' os.remove(' + repr(d
['file']) + ')')
111 write(' # No file specified for ' + d
['name'])
115 if __name__
== '__main__':