]> Raphaƫl G. Git Repositories - youtubedl/blob - test/helper.py
Prepare for upload.
[youtubedl] / test / helper.py
1 import io
2 import json
3 import os.path
4
5 import youtube_dl.extractor
6 from youtube_dl import YoutubeDL, YoutubeDLHandler
7 from youtube_dl.utils import (
8 compat_cookiejar,
9 compat_urllib_request,
10 )
11
12 # General configuration (from __init__, not very elegant...)
13 jar = compat_cookiejar.CookieJar()
14 cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
15 proxy_handler = compat_urllib_request.ProxyHandler()
16 opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
17 compat_urllib_request.install_opener(opener)
18
19 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
20 with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
21 parameters = json.load(pf)
22
23 class FakeYDL(YoutubeDL):
24 def __init__(self):
25 self.result = []
26 # Different instances of the downloader can't share the same dictionary
27 # some test set the "sublang" parameter, which would break the md5 checks.
28 self.params = dict(parameters)
29 def to_screen(self, s):
30 print(s)
31 def trouble(self, s, tb=None):
32 raise Exception(s)
33 def download(self, x):
34 self.result.append(x)
35
36 def get_testcases():
37 for ie in youtube_dl.extractor.gen_extractors():
38 t = getattr(ie, '_TEST', None)
39 if t:
40 t['name'] = type(ie).__name__[:-len('IE')]
41 yield t
42 for t in getattr(ie, '_TESTS', []):
43 t['name'] = type(ie).__name__[:-len('IE')]
44 yield t