mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 20:37:29 +00:00
Handle expected_warnings
better
* make fake `report_warning()` method signatures correct (per 640d39f
)
* support single warning to expect as well as sequence
* don't colour text to be matched
* use `expected_warnings()` function throughout
This commit is contained in:
parent
15b06163a8
commit
2239666542
1 changed files with 9 additions and 13 deletions
|
@ -20,6 +20,7 @@ from youtube_dl.compat import (
|
||||||
from youtube_dl.utils import (
|
from youtube_dl.utils import (
|
||||||
IDENTITY,
|
IDENTITY,
|
||||||
preferredencoding,
|
preferredencoding,
|
||||||
|
variadic,
|
||||||
write_string,
|
write_string,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ def report_warning(message):
|
||||||
class FakeYDL(YoutubeDL):
|
class FakeYDL(YoutubeDL):
|
||||||
def __init__(self, override=None):
|
def __init__(self, override=None):
|
||||||
# Different instances of the downloader can't share the same dictionary
|
# Different instances of the downloader can't share the same dictionary
|
||||||
# some test set the "sublang" parameter, which would break the md5 checks.
|
# some tests set the "sublang" parameter, which would break the md5 checks.
|
||||||
params = get_params(override=override)
|
params = get_params(override=override)
|
||||||
super(FakeYDL, self).__init__(params, auto_init=False)
|
super(FakeYDL, self).__init__(params, auto_init=False)
|
||||||
self.result = []
|
self.result = []
|
||||||
|
@ -83,14 +84,7 @@ class FakeYDL(YoutubeDL):
|
||||||
|
|
||||||
def expect_warning(self, regex):
|
def expect_warning(self, regex):
|
||||||
# Silence an expected warning matching a regex
|
# Silence an expected warning matching a regex
|
||||||
old_report_warning = self.report_warning
|
expect_warnings(self, regex)
|
||||||
|
|
||||||
def report_warning(self, message):
|
|
||||||
if re.match(regex, message):
|
|
||||||
return
|
|
||||||
old_report_warning(message)
|
|
||||||
self.report_warning = types.MethodType(report_warning, self)
|
|
||||||
|
|
||||||
|
|
||||||
class FakeLogger(object):
|
class FakeLogger(object):
|
||||||
def debug(self, msg):
|
def debug(self, msg):
|
||||||
|
@ -285,12 +279,14 @@ def assertEqual(self, got, expected, msg=None):
|
||||||
|
|
||||||
def expect_warnings(ydl, warnings_re):
|
def expect_warnings(ydl, warnings_re):
|
||||||
real_warning = ydl.report_warning
|
real_warning = ydl.report_warning
|
||||||
|
# to facilitate matching, don't prettify messages
|
||||||
|
ydl.params['no_color'] = True
|
||||||
|
|
||||||
def _report_warning(w):
|
def _report_warning(self, w, *args, **kwargs):
|
||||||
if not any(re.search(w_re, w) for w_re in warnings_re):
|
if not any(re.search(w_re, w) for w_re in variadic(warnings_re)):
|
||||||
real_warning(w)
|
real_warning(w, *args, **kwargs)
|
||||||
|
|
||||||
ydl.report_warning = _report_warning
|
ydl.report_warning = types.MethodType(_report_warning, ydl)
|
||||||
|
|
||||||
|
|
||||||
def http_server_port(httpd):
|
def http_server_port(httpd):
|
||||||
|
|
Loading…
Reference in a new issue