Scrapy, a fast high-level web crawling & scraping framework for Python.
Improve test coverage for responsetypes.py (#7646)
Adrian7499d17e281c
diff --git a/scrapy/responsetypes.py b/scrapy/responsetypes.pyindex cd62f02af..29e9b6bb7 100644--- a/scrapy/responsetypes.py+++ b/scrapy/responsetypes.py@@ -40,18 +40,13 @@ class ResponseTypes:self.classes: dict[str, type[Response]] = {}self.mimetypes: MimeTypes = MimeTypes()mimedata = get_data("scrapy", "mime.types")- if not mimedata:- raise ValueError(- "The mime.types file is not found in the Scrapy installation"- )+ assert mimedata is not Noneself.mimetypes.readfp(StringIO(mimedata.decode("utf8")))for mimetype, cls in self.CLASSES.items():self.classes[mimetype] = load_object(cls)def from_mimetype(self, mimetype: str) -> type[Response]:"""Return the most appropriate Response class for the given mimetype"""- if mimetype is None:- return Responseif mimetype in self.classes:return self.classes[mimetype]basetype = f"{mimetype.split('/', maxsplit=1)[0]}/*"diff --git a/tests/test_responsetypes.py b/tests/test_responsetypes.pyindex 5b04c7436..42ab29267 100644--- a/tests/test_responsetypes.py+++ b/tests/test_responsetypes.py@@ -40,6 +40,9 @@ class TestResponseTypes:retcls = responsetypes.from_content_disposition(source)assert retcls is cls, f"{source} ==> {retcls} != {cls}"+ def test_from_content_disposition_no_filename(self):+ assert responsetypes.from_content_disposition(b"attachment") is Response+def test_from_content_type(self):mappings = [("text/html; charset=UTF-8", HtmlResponse),