本文整理汇总了Python中scrapy.pipelines.images.ImagesPipeline.from_settings方法的典型用法代码示例。如果您正苦于以下问题:Python ImagesPipeline.from_settings方法的具体用法?Python ImagesPipeline.from_settings怎么用?Python ImagesPipeline.from_settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.pipelines.images.ImagesPipeline
的用法示例。
在下文中一共展示了ImagesPipeline.from_settings方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_item_fields_default
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_item_fields_default(self):
class TestItem(Item):
name = Field()
image_urls = Field()
images = Field()
for cls in TestItem, dict:
url = 'http://www.example.com/images/1.jpg'
item = cls({'name': 'item1', 'image_urls': [url]})
pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': 's3://example/images/'}))
requests = list(pipeline.get_media_requests(item, None))
self.assertEqual(requests[0].url, url)
results = [(True, {'url': url})]
pipeline.item_completed(results, item, None)
self.assertEqual(item['images'], [results[0][1]])
示例2: test_different_settings_for_different_instances
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_different_settings_for_different_instances(self):
"""
If there are two instances of ImagesPipeline class with different settings, they should
have different settings.
"""
custom_settings = self._generate_fake_settings()
default_settings = Settings()
default_sts_pipe = ImagesPipeline(self.tempdir, settings=default_settings)
user_sts_pipe = ImagesPipeline.from_settings(Settings(custom_settings))
for pipe_attr, settings_attr in self.img_cls_attribute_names:
expected_default_value = self.default_pipeline_settings.get(pipe_attr)
custom_value = custom_settings.get(settings_attr)
self.assertNotEqual(expected_default_value, custom_value)
self.assertEqual(getattr(default_sts_pipe, pipe_attr.lower()), expected_default_value)
self.assertEqual(getattr(user_sts_pipe, pipe_attr.lower()), custom_value)
示例3: test_thumbs
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_thumbs(self):
custom_thumbs = {'small': (50, 50), 'big': (270, 270)}
another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
'IMAGES_THUMBS': custom_thumbs}))
self.assertEqual(self.pipeline.thumbs, self.default_settings.get('IMAGES_THUMBS'))
self.assertEqual(another_pipeline.thumbs, custom_thumbs)
示例4: test_min_height
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_min_height(self):
another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
'IMAGES_MIN_HEIGHT': 42}))
self.assertEqual(self.pipeline.min_height, self.default_settings.getint('IMAGES_MIN_HEIGHT'))
self.assertEqual(another_pipeline.min_height, 42)
示例5: test_min_width
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_min_width(self):
another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
'IMAGES_MIN_WIDTH': 42}))
self.assertEqual(self.pipeline.min_width, self.default_settings.getint('IMAGES_MIN_WIDTH'))
self.assertEqual(another_pipeline.min_width, 42)
示例6: test_images_result_field
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_images_result_field(self):
another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
'IMAGES_RESULT_FIELD': 'funny_field'}))
self.assertEqual(self.pipeline.images_result_field, self.default_settings.get('IMAGES_RESULT_FIELD'))
self.assertEqual(another_pipeline.images_result_field, 'funny_field')
示例7: test_expires
# 需要导入模块: from scrapy.pipelines.images import ImagesPipeline [as 别名]
# 或者: from scrapy.pipelines.images.ImagesPipeline import from_settings [as 别名]
def test_expires(self):
another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
'IMAGES_EXPIRES': 42}))
self.assertEqual(self.pipeline.expires, self.default_settings.getint('IMAGES_EXPIRES'))
self.assertEqual(another_pipeline.expires, 42)