8 import youtube_dl.extractor
9 from youtube_dl import YoutubeDL, YoutubeDLHandler
10 from youtube_dl.utils import (
12 compat_urllib_request,
15 youtube_dl._setup_opener(timeout=10)
17 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
18 with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
19 parameters = json.load(pf)
23 """ Remove a file if it exists """
26 except OSError as ose:
27 if ose.errno != errno.ENOENT:
31 class FakeYDL(YoutubeDL):
33 # Different instances of the downloader can't share the same dictionary
34 # some test set the "sublang" parameter, which would break the md5 checks.
35 params = dict(parameters)
36 super(FakeYDL, self).__init__(params)
39 def to_screen(self, s, skip_eol=None):
42 def trouble(self, s, tb=None):
45 def download(self, x):
48 def expect_warning(self, regex):
49 # Silence an expected warning matching a regex
50 old_report_warning = self.report_warning
51 def report_warning(self, message):
52 if re.match(regex, message): return
53 old_report_warning(message)
54 self.report_warning = types.MethodType(report_warning, self)
57 for ie in youtube_dl.extractor.gen_extractors():
58 t = getattr(ie, '_TEST', None)
60 t['name'] = type(ie).__name__[:-len('IE')]
62 for t in getattr(ie, '_TESTS', []):
63 t['name'] = type(ie).__name__[:-len('IE')]