aboutsummaryrefslogtreecommitdiff
path: root/test/gentests.py
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo.valsorda@gmail.com>2012-12-11 12:15:16 +0100
committerFilippo Valsorda <filippo.valsorda@gmail.com>2012-12-11 12:15:16 +0100
commit95eb771dcda47f948b050da85c7ff22539e3ee12 (patch)
tree3bea4b6975544ef76241ccf402de541da350b4ac /test/gentests.py
parent3c6ffbaedbbae8734f6b86fea1169413b656abf3 (diff)
parent4fb1acc212555e3e817f858dce964876eef75d85 (diff)
Merge branch 'master' into fork_master
Conflicts: .travis.yml
Diffstat (limited to 'test/gentests.py')
-rwxr-xr-xtest/gentests.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/test/gentests.py b/test/gentests.py
index 9352d6d94..0ea5d9f21 100755
--- a/test/gentests.py
+++ b/test/gentests.py
@@ -23,13 +23,28 @@ import os
import json
import unittest
import sys
+import socket
# Allow direct execution
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from youtube_dl.FileDownloader import FileDownloader
+import youtube_dl.FileDownloader
import youtube_dl.InfoExtractors
+from youtube_dl.utils import *
+
+# General configuration (from __init__, not very elegant...)
+jar = compat_cookiejar.CookieJar()
+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(300) # 5 minutes should be enough (famous last words)
+
+class FileDownloader(youtube_dl.FileDownloader):
+ def __init__(self, *args, **kwargs):
+ youtube_dl.FileDownloader.__init__(self, *args, **kwargs)
+ self.to_stderr = self.to_screen
def _file_md5(fn):
with open(fn, 'rb') as f:
@@ -76,12 +91,12 @@ def gentests():
with io.open(TEST_FILE, 'w', encoding='utf-8') as testf:
testf.write(HEADER)
spaces = ' ' * 4
- write = lambda l: testf.write(spaces + l + '\n')
+ write = lambda l: testf.write(spaces + l + u'\n')
for d in defs:
name = d['name']
ie = getattr(youtube_dl.InfoExtractors, name + 'IE')
- testf.write('\n')
+ testf.write(u'\n')
write('@_skip_unless(youtube_dl.InfoExtractors.' + name + 'IE._WORKING, "IE marked as not _WORKING")')
if not d['file']:
write('@_skip("No output file specified")')
@@ -89,19 +104,20 @@ def gentests():
write('@_skip(' + repr(d['skip']) + ')')
write('def test_' + name + '(self):')
write(' filename = ' + repr(d['file']))
- write(' fd = FileDownloader(self.parameters)')
+ write(' params = self.parameters')
+ for p in d.get('params', {}):
+ write(' params["' + p + '"] = ' + repr(d['params'][p]))
+ write(' fd = FileDownloader(params)')
write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + name + 'IE())')
for ien in d.get('addIEs', []):
write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + ien + 'IE())')
write(' fd.download([' + repr(d['url']) + '])')
write(' self.assertTrue(os.path.exists(filename))')
- if 'size' in d:
- write(' self.assertEqual(os.path.getsize(filename), ' + repr(d['size']) + ')')
if 'md5' in d:
write(' md5_for_file = _file_md5(filename)')
write(' self.assertEqual(md5_for_file, ' + repr(d['md5']) + ')')
- testf.write('\n\n')
+ testf.write(u'\n\n')
write('def tearDown(self):')
for d in defs:
if d['file']:
@@ -109,7 +125,7 @@ def gentests():
write(' os.remove(' + repr(d['file']) + ')')
else:
write(' # No file specified for ' + d['name'])
- testf.write('\n')
+ testf.write(u'\n')
testf.write(FOOTER)
if __name__ == '__main__':