conftest.py 663 B

123456789101112131415161718192021222324252627
  1. import functools
  2. import inspect
  3. import pytest
  4. from yt_dlp.networking import RequestHandler
  5. from yt_dlp.networking.common import _REQUEST_HANDLERS
  6. from yt_dlp.utils._utils import _YDLLogger as FakeLogger
  7. @pytest.fixture
  8. def handler(request):
  9. RH_KEY = request.param
  10. if inspect.isclass(RH_KEY) and issubclass(RH_KEY, RequestHandler):
  11. handler = RH_KEY
  12. elif RH_KEY in _REQUEST_HANDLERS:
  13. handler = _REQUEST_HANDLERS[RH_KEY]
  14. else:
  15. pytest.skip(f'{RH_KEY} request handler is not available')
  16. return functools.partial(handler, logger=FakeLogger)
  17. def validate_and_send(rh, req):
  18. rh.validate(req)
  19. return rh.send(req)