Skip to content

Commit

Permalink
[tests] Add tests for socks proxies (#7908)
Browse files Browse the repository at this point in the history
Authored by: coletdjnz
  • Loading branch information
coletdjnz committed Aug 25, 2023
1 parent 7cccab7 commit fcd6a76
Show file tree
Hide file tree
Showing 3 changed files with 460 additions and 98 deletions.
21 changes: 21 additions & 0 deletions test/conftest.py
@@ -0,0 +1,21 @@
import functools
import inspect

import pytest

from yt_dlp.networking import RequestHandler
from yt_dlp.networking.common import _REQUEST_HANDLERS
from yt_dlp.utils._utils import _YDLLogger as FakeLogger


@pytest.fixture
def handler(request):
RH_KEY = request.param
if inspect.isclass(RH_KEY) and issubclass(RH_KEY, RequestHandler):
handler = RH_KEY
elif RH_KEY in _REQUEST_HANDLERS:
handler = _REQUEST_HANDLERS[RH_KEY]
else:
pytest.skip(f'{RH_KEY} request handler is not available')

return functools.partial(handler, logger=FakeLogger)
16 changes: 0 additions & 16 deletions test/test_networking.py
Expand Up @@ -8,12 +8,10 @@

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import functools
import gzip
import http.client
import http.cookiejar
import http.server
import inspect
import io
import pathlib
import random
Expand All @@ -40,7 +38,6 @@
Response,
)
from yt_dlp.networking._urllib import UrllibRH
from yt_dlp.networking.common import _REQUEST_HANDLERS
from yt_dlp.networking.exceptions import (
CertificateVerifyError,
HTTPError,
Expand Down Expand Up @@ -307,19 +304,6 @@ def setup_class(cls):
cls.https_server_thread.start()


@pytest.fixture
def handler(request):
RH_KEY = request.param
if inspect.isclass(RH_KEY) and issubclass(RH_KEY, RequestHandler):
handler = RH_KEY
elif RH_KEY in _REQUEST_HANDLERS:
handler = _REQUEST_HANDLERS[RH_KEY]
else:
pytest.skip(f'{RH_KEY} request handler is not available')

return functools.partial(handler, logger=FakeLogger)


class TestHTTPRequestHandler(TestRequestHandlerBase):
@pytest.mark.parametrize('handler', ['Urllib'], indirect=True)
def test_verify_cert(self, handler):
Expand Down

0 comments on commit fcd6a76

Please sign in to comment.