]>
Commit | Line | Data |
---|---|---|
112da0a0 PH |
1 | import io |
2 | import json | |
3 | import os.path | |
00fcc17a FV |
4 | import re |
5 | import types | |
112da0a0 | 6 | |
fc2c063e | 7 | import youtube_dl.extractor |
112da0a0 PH |
8 | from youtube_dl import YoutubeDL, YoutubeDLHandler |
9 | from youtube_dl.utils import ( | |
10 | compat_cookiejar, | |
11 | compat_urllib_request, | |
12 | ) | |
13 | ||
14 | # General configuration (from __init__, not very elegant...) | |
15 | jar = compat_cookiejar.CookieJar() | |
16 | cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar) | |
17 | proxy_handler = compat_urllib_request.ProxyHandler() | |
18 | opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) | |
19 | compat_urllib_request.install_opener(opener) | |
20 | ||
21 | PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json") | |
22 | with io.open(PARAMETERS_FILE, encoding='utf-8') as pf: | |
23 | parameters = json.load(pf) | |
24 | ||
25 | class FakeYDL(YoutubeDL): | |
26 | def __init__(self): | |
27 | self.result = [] | |
28 | # Different instances of the downloader can't share the same dictionary | |
29 | # some test set the "sublang" parameter, which would break the md5 checks. | |
30 | self.params = dict(parameters) | |
31 | def to_screen(self, s): | |
32 | print(s) | |
33 | def trouble(self, s, tb=None): | |
34 | raise Exception(s) | |
35 | def download(self, x): | |
fc2c063e | 36 | self.result.append(x) |
00fcc17a FV |
37 | def expect_warning(self, regex): |
38 | # Silence an expected warning matching a regex | |
39 | old_report_warning = self.report_warning | |
40 | def report_warning(self, message): | |
41 | if re.match(regex, message): return | |
42 | old_report_warning(message) | |
43 | self.report_warning = types.MethodType(report_warning, self) | |
fc2c063e PH |
44 | |
45 | def get_testcases(): | |
46 | for ie in youtube_dl.extractor.gen_extractors(): | |
47 | t = getattr(ie, '_TEST', None) | |
48 | if t: | |
49 | t['name'] = type(ie).__name__[:-len('IE')] | |
50 | yield t | |
51 | for t in getattr(ie, '_TESTS', []): | |
52 | t['name'] = type(ie).__name__[:-len('IE')] | |
53 | yield t |