mirror of https://github.com/scrapy/scrapy.git
Merge pull request #5489 from PluT00/deprecate-NoimagesDrop
Deprecate scrapy.pipelines.images.NoimagesDrop
This commit is contained in:
commit
77cd511a5e
|
|
@ -5,12 +5,13 @@ See documentation in topics/media-pipeline.rst
|
|||
"""
|
||||
import functools
|
||||
import hashlib
|
||||
import warnings
|
||||
from contextlib import suppress
|
||||
from io import BytesIO
|
||||
|
||||
from itemadapter import ItemAdapter
|
||||
|
||||
from scrapy.exceptions import DropItem, NotConfigured
|
||||
from scrapy.exceptions import DropItem, NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.http import Request
|
||||
from scrapy.pipelines.files import FileException, FilesPipeline
|
||||
# TODO: from scrapy.pipelines.media import MediaPipeline
|
||||
|
|
@ -22,6 +23,10 @@ from scrapy.utils.python import to_bytes
|
|||
class NoimagesDrop(DropItem):
|
||||
"""Product with no images exception"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("The NoimagesDrop class is deprecated", category=ScrapyDeprecationWarning, stacklevel=2)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class ImageException(FileException):
|
||||
"""General image error exception"""
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
import dataclasses
|
||||
import hashlib
|
||||
import io
|
||||
import random
|
||||
from shutil import rmtree
|
||||
from tempfile import mkdtemp
|
||||
import dataclasses
|
||||
from warnings import catch_warnings
|
||||
|
||||
import attr
|
||||
from itemadapter import ItemAdapter
|
||||
from twisted.trial import unittest
|
||||
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.item import Field, Item
|
||||
from scrapy.pipelines.images import ImagesPipeline
|
||||
from scrapy.pipelines.images import ImagesPipeline, NoimagesDrop
|
||||
from scrapy.settings import Settings
|
||||
from scrapy.utils.python import to_bytes
|
||||
|
||||
|
|
@ -416,6 +418,22 @@ class ImagesPipelineTestCaseCustomSettings(unittest.TestCase):
|
|||
expected_value)
|
||||
|
||||
|
||||
class NoimagesDropTestCase(unittest.TestCase):
|
||||
|
||||
def test_deprecation_warning(self):
|
||||
arg = str()
|
||||
with catch_warnings(record=True) as warnings:
|
||||
NoimagesDrop(arg)
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertEqual(warnings[0].category, ScrapyDeprecationWarning)
|
||||
with catch_warnings(record=True) as warnings:
|
||||
class SubclassedNoimagesDrop(NoimagesDrop):
|
||||
pass
|
||||
SubclassedNoimagesDrop(arg)
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertEqual(warnings[0].category, ScrapyDeprecationWarning)
|
||||
|
||||
|
||||
def _create_image(format, *a, **kw):
|
||||
buf = io.BytesIO()
|
||||
Image.new(*a, **kw).save(buf, format)
|
||||
|
|
|
|||
Loading…
Reference in New Issue