]> jfr.im git - yt-dlp.git/blame - test/helper.py
[googleplus] Fix upload_date detection
[yt-dlp.git] / test / helper.py
CommitLineData
112da0a0
PH
1import io
2import json
3import os.path
4
fc2c063e 5import youtube_dl.extractor
112da0a0
PH
6from youtube_dl import YoutubeDL, YoutubeDLHandler
7from youtube_dl.utils import (
8 compat_cookiejar,
9 compat_urllib_request,
10)
11
12# General configuration (from __init__, not very elegant...)
13jar = compat_cookiejar.CookieJar()
14cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
15proxy_handler = compat_urllib_request.ProxyHandler()
16opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
17compat_urllib_request.install_opener(opener)
18
19PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
20with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
21 parameters = json.load(pf)
22
23class 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):
fc2c063e
PH
34 self.result.append(x)
35
36def 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