mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-10-08 19:54:52 +00:00
[compat, networking] Deprecate old functions (#2861)
Authored by: coletdjnz, pukkandan
This commit is contained in:
@@ -160,7 +160,7 @@ def generator(test_case, tname):
|
||||
force_generic_extractor=params.get('force_generic_extractor', False))
|
||||
except (DownloadError, ExtractorError) as err:
|
||||
# Check if the exception is not a network related one
|
||||
if not isinstance(err.exc_info[1], (TransportError, UnavailableVideoError)) or (isinstance(err.exc_info[1], HTTPError) and err.exc_info[1].code == 503):
|
||||
if not isinstance(err.exc_info[1], (TransportError, UnavailableVideoError)) or (isinstance(err.exc_info[1], HTTPError) and err.exc_info[1].status == 503):
|
||||
err.msg = f'{getattr(err, "msg", err)} ({tname})'
|
||||
raise
|
||||
|
||||
|
@@ -1057,14 +1057,15 @@ class TestYoutubeDLNetworking:
|
||||
urllib_req = urllib.request.Request('http://foo.bar', data=b'test', method='PUT', headers={'X-Test': '1'})
|
||||
urllib_req.add_unredirected_header('Cookie', 'bob=bob')
|
||||
urllib_req.timeout = 2
|
||||
|
||||
req = ydl.urlopen(urllib_req).request
|
||||
assert req.url == urllib_req.get_full_url()
|
||||
assert req.data == urllib_req.data
|
||||
assert req.method == urllib_req.get_method()
|
||||
assert 'X-Test' in req.headers
|
||||
assert 'Cookie' in req.headers
|
||||
assert req.extensions.get('timeout') == 2
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', category=DeprecationWarning)
|
||||
req = ydl.urlopen(urllib_req).request
|
||||
assert req.url == urllib_req.get_full_url()
|
||||
assert req.data == urllib_req.data
|
||||
assert req.method == urllib_req.get_method()
|
||||
assert 'X-Test' in req.headers
|
||||
assert 'Cookie' in req.headers
|
||||
assert req.extensions.get('timeout') == 2
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
ydl.urlopen(None)
|
||||
@@ -1362,7 +1363,9 @@ class TestResponse:
|
||||
|
||||
def test_compat(self):
|
||||
res = Response(io.BytesIO(b''), url='test://', status=404, headers={'test': 'test'})
|
||||
assert res.code == res.getcode() == res.status
|
||||
assert res.geturl() == res.url
|
||||
assert res.info() is res.headers
|
||||
assert res.getheader('test') == res.get_header('test')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', category=DeprecationWarning)
|
||||
assert res.code == res.getcode() == res.status
|
||||
assert res.geturl() == res.url
|
||||
assert res.info() is res.headers
|
||||
assert res.getheader('test') == res.get_header('test')
|
||||
|
@@ -8,11 +8,13 @@ import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import platform
|
||||
import random
|
||||
import ssl
|
||||
import urllib.error
|
||||
import warnings
|
||||
|
||||
from yt_dlp.cookies import YoutubeDLCookieJar
|
||||
from yt_dlp.dependencies import certifi
|
||||
@@ -202,20 +204,58 @@ class TestNetworkingExceptions:
|
||||
assert isinstance(error, HTTPError)
|
||||
assert isinstance(error, urllib.error.HTTPError)
|
||||
|
||||
assert error.code == 403
|
||||
assert error.getcode() == 403
|
||||
assert error.hdrs is error.response.headers
|
||||
assert error.info() is error.response.headers
|
||||
assert error.headers is error.response.headers
|
||||
assert error.filename == error.response.url
|
||||
assert error.url == error.response.url
|
||||
assert error.geturl() == error.response.url
|
||||
@contextlib.contextmanager
|
||||
def raises_deprecation_warning():
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
yield
|
||||
|
||||
if len(w) == 0:
|
||||
pytest.fail('Did not raise DeprecationWarning')
|
||||
if len(w) > 1:
|
||||
pytest.fail(f'Raised multiple warnings: {w}')
|
||||
|
||||
if not issubclass(w[-1].category, DeprecationWarning):
|
||||
pytest.fail(f'Expected DeprecationWarning, got {w[-1].category}')
|
||||
w.clear()
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.code == 403
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.getcode() == 403
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.hdrs is error.response.headers
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.info() is error.response.headers
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.headers is error.response.headers
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.filename == error.response.url
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.url == error.response.url
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert error.geturl() == error.response.url
|
||||
|
||||
# Passthrough file operations
|
||||
assert error.read() == b'test'
|
||||
assert not error.closed
|
||||
# Technically Response operations are also passed through, which should not be used.
|
||||
assert error.get_header('test') == 'test'
|
||||
with raises_deprecation_warning():
|
||||
assert error.read() == b'test'
|
||||
|
||||
with raises_deprecation_warning():
|
||||
assert not error.closed
|
||||
|
||||
with raises_deprecation_warning():
|
||||
# Technically Response operations are also passed through, which should not be used.
|
||||
assert error.get_header('test') == 'test'
|
||||
|
||||
# Should not raise a warning
|
||||
error.close()
|
||||
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy', reason='garbage collector works differently in pypy')
|
||||
|
Reference in New Issue
Block a user