Simplify the changes after the merge

This commit is contained in:
Andrey Rahmatullin 2022-11-07 16:36:54 +05:00 committed by GitHub
parent b03d84e9fb
commit 6c0890ff54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 19 deletions

View File

@ -7,7 +7,6 @@ from shutil import rmtree
from tempfile import mkdtemp
from unittest import skipIf
from unittest.mock import patch
from warnings import catch_warnings
import attr
from itemadapter import ItemAdapter
@ -91,6 +90,22 @@ class ImagesPipelineTestCase(unittest.TestCase):
info=object()),
'thumbs/50/850233df65a5b83361798f532f1fc549cd13cbe9.jpg')
def test_thumbnail_name_from_item(self):
"""
Custom thumbnail name based on item data, overriding default implementation
"""
class CustomImagesPipeline(ImagesPipeline):
def thumb_path(self, request, thumb_id, response=None, info=None, item=None):
return f"thumb/{thumb_id}/{item.get('path')}"
thumb_path = CustomImagesPipeline.from_settings(Settings(
{'IMAGES_STORE': self.tempdir}
)).thumb_path
item = dict(path='path-to-store-file')
request = Request("http://example.com")
self.assertEqual(thumb_path(request, 'small', item=item), 'thumb/small/path-to-store-file')
def test_get_images_exception(self):
self.pipeline.min_width = 100
self.pipeline.min_height = 100
@ -231,22 +246,6 @@ class ImagesPipelineTestCase(unittest.TestCase):
self.assertEqual(converted.mode, 'RGB')
self.assertEqual(converted.getcolors(), [(10000, (205, 230, 255))])
def test_thumbnail_name_from_item(self):
"""
Custom thumbnail name based on item data, overriding default implementation
"""
class CustomImagesPipeline(ImagesPipeline):
def thumb_path(self, request, thumb_id, response=None, info=None, item=None):
return f"thumb/{thumb_id}/{item.get('path')}"
thumb_path = CustomImagesPipeline.from_settings(Settings(
{'IMAGES_STORE': self.tempdir}
)).thumb_path
item = dict(path='path-to-store-file')
request = Request("http://example.com")
self.assertEqual(thumb_path(request, 'small', item=item), 'thumb/small/path-to-store-file')
class DeprecatedImagesPipeline(ImagesPipeline):
def file_key(self, url):
@ -536,11 +535,11 @@ class NoimagesDropTestCase(unittest.TestCase):
def test_deprecation_warning(self):
arg = str()
with catch_warnings(record=True) as warnings:
with warnings.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:
with warnings.catch_warnings(record=True) as warnings:
class SubclassedNoimagesDrop(NoimagesDrop):
pass
SubclassedNoimagesDrop(arg)