]>
jfr.im git - yt-dlp.git/blob - test/helper.py
8 import youtube_dl
.extractor
9 from youtube_dl
import YoutubeDL
, YoutubeDLHandler
10 from youtube_dl
.utils
import (
12 compat_urllib_request
,
15 # General configuration (from __init__, not very elegant...)
16 jar
= compat_cookiejar
.CookieJar()
17 cookie_processor
= compat_urllib_request
.HTTPCookieProcessor(jar
)
18 proxy_handler
= compat_urllib_request
.ProxyHandler()
19 opener
= compat_urllib_request
.build_opener(proxy_handler
, cookie_processor
, YoutubeDLHandler())
20 compat_urllib_request
.install_opener(opener
)
22 PARAMETERS_FILE
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "parameters.json")
23 with io
.open(PARAMETERS_FILE
, encoding
='utf-8') as pf
:
24 parameters
= json
.load(pf
)
28 """ Remove a file if it exists """
31 except OSError as ose
:
32 if ose
.errno
!= errno
.ENOENT
:
36 class FakeYDL(YoutubeDL
):
38 # Different instances of the downloader can't share the same dictionary
39 # some test set the "sublang" parameter, which would break the md5 checks.
40 params
= dict(parameters
)
41 super(FakeYDL
, self
).__init
__(params
)
44 def to_screen(self
, s
, skip_eol
=None):
47 def trouble(self
, s
, tb
=None):
50 def download(self
, x
):
53 def expect_warning(self
, regex
):
54 # Silence an expected warning matching a regex
55 old_report_warning
= self
.report_warning
56 def report_warning(self
, message
):
57 if re
.match(regex
, message
): return
58 old_report_warning(message
)
59 self
.report_warning
= types
.MethodType(report_warning
, self
)
62 for ie
in youtube_dl
.extractor
.gen_extractors():
63 t
= getattr(ie
, '_TEST', None)
65 t
['name'] = type(ie
).__name
__[:-len('IE')]
67 for t
in getattr(ie
, '_TESTS', []):
68 t
['name'] = type(ie
).__name
__[:-len('IE')]