Simplify the H2DownloadHandler import.

This commit is contained in:
Andrey Rakhmatullin 2025-02-02 01:31:21 +05:00
parent 79480658cd
commit ed187046ac
1 changed files with 9 additions and 12 deletions

View File

@ -23,6 +23,9 @@ pytestmark = pytest.mark.skipif(
not H2_ENABLED, reason="HTTP/2 support in Twisted is not enabled"
)
# pylint: disable-next=ungrouped-imports
from scrapy.core.downloader.handlers.http2 import H2DownloadHandler # noqa: E402
class BaseTestClasses:
# A hack to prevent tests from the imported classes to run here too.
@ -50,19 +53,13 @@ class BaseTestClasses:
)
def _get_dh() -> type[DownloadHandlerProtocol]:
from scrapy.core.downloader.handlers.http2 import H2DownloadHandler
return H2DownloadHandler
class Https2TestCase(BaseTestClasses.Https11TestCase):
scheme = "https"
HTTP2_DATALOSS_SKIP_REASON = "Content-Length mismatch raises InvalidBodyLengthError"
@property
def download_handler_cls(self) -> type[DownloadHandlerProtocol]:
return _get_dh()
return H2DownloadHandler
def test_protocol(self):
request = Request(self.getURL("host"), method="GET")
@ -183,25 +180,25 @@ class Https2TestCase(BaseTestClasses.Https11TestCase):
class Https2WrongHostnameTestCase(BaseTestClasses.Https11WrongHostnameTestCase):
@property
def download_handler_cls(self) -> type[DownloadHandlerProtocol]:
return _get_dh()
return H2DownloadHandler
class Https2InvalidDNSId(BaseTestClasses.Https11InvalidDNSId):
@property
def download_handler_cls(self) -> type[DownloadHandlerProtocol]:
return _get_dh()
return H2DownloadHandler
class Https2InvalidDNSPattern(BaseTestClasses.Https11InvalidDNSPattern):
@property
def download_handler_cls(self) -> type[DownloadHandlerProtocol]:
return _get_dh()
return H2DownloadHandler
class Https2CustomCiphers(BaseTestClasses.Https11CustomCiphers):
@property
def download_handler_cls(self) -> type[DownloadHandlerProtocol]:
return _get_dh()
return H2DownloadHandler
class Http2MockServerTestCase(BaseTestClasses.Http11MockServerTestCase):
@ -227,7 +224,7 @@ class Https2ProxyTestCase(BaseTestClasses.Http11ProxyTestCase):
@property
def download_handler_cls(self) -> type[DownloadHandlerProtocol]:
return _get_dh()
return H2DownloadHandler
def setUp(self):
site = server.Site(UriResource(), timeout=None)