Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

tests for new API

Anubhav Patel881bade2c1b2
diff --git a/tests/test_pipeline_images.py b/tests/test_pipeline_images.py
index 651691862..1dfca5c11 100644
--- a/tests/test_pipeline_images.py
+++ b/tests/test_pipeline_images.py
@@ -79,12 +79,11 @@ class ImagesPipelineTestCase(unittest.TestCase):
# tests for old API
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
-
SIZE = (100, 100)
# straigh forward case: RGB and JPEG
COLOUR = (0, 127, 255)
- im, buf = _create_image('JPEG', 'RGB', SIZE, COLOUR)
- converted, converted_buf = self.pipeline.convert_image(im)
+ im, _ = _create_image('JPEG', 'RGB', SIZE, COLOUR)
+ converted, _ = self.pipeline.convert_image(im)
self.assertEqual(converted.mode, 'RGB')
self.assertEqual(converted.getcolors(), [(10000, COLOUR)])
@@ -95,14 +94,14 @@ class ImagesPipelineTestCase(unittest.TestCase):
# transparency case: RGBA and PNG
COLOUR = (0, 127, 255, 50)
- im, buf = _create_image('PNG', 'RGBA', SIZE, COLOUR)
+ im, _ = _create_image('PNG', 'RGBA', SIZE, COLOUR)
converted, _ = self.pipeline.convert_image(im)
self.assertEqual(converted.mode, 'RGB')
self.assertEqual(converted.getcolors(), [(10000, (205, 230, 255))])
# transparency case with palette: P and PNG
COLOUR = (0, 127, 255, 50)
- im, buf = _create_image('PNG', 'RGBA', SIZE, COLOUR)
+ im, _ = _create_image('PNG', 'RGBA', SIZE, COLOUR)
im = im.convert('P')
converted, _ = self.pipeline.convert_image(im)
self.assertEqual(converted.mode, 'RGB')
@@ -112,12 +111,36 @@ class ImagesPipelineTestCase(unittest.TestCase):
self.assertTrue(len(w) >= 4)
# tests for new API
- # check that we don't convert JPEGs again
+ SIZE = (100, 100)
+ # straigh forward case: RGB and JPEG
COLOUR = (0, 127, 255)
im, buf = _create_image('JPEG', 'RGB', SIZE, COLOUR)
converted, converted_buf = self.pipeline.convert_image(im, response_body=buf)
+ self.assertEqual(converted.mode, 'RGB')
+ self.assertEqual(converted.getcolors(), [(10000, COLOUR)])
+ # check that we don't convert JPEGs again
self.assertEqual(converted_buf, buf)
+ # check that thumbnail keep image ratio
+ thumbnail, _ = self.pipeline.convert_image(converted, size=(10, 25), response_body=converted_buf)
+ self.assertEqual(thumbnail.mode, 'RGB')
+ self.assertEqual(thumbnail.size, (10, 10))
+
+ # transparency case: RGBA and PNG
+ COLOUR = (0, 127, 255, 50)
+ im, buf = _create_image('PNG', 'RGBA', SIZE, COLOUR)
+ converted, _ = self.pipeline.convert_image(im, response_body=buf)
+ self.assertEqual(converted.mode, 'RGB')
+ self.assertEqual(converted.getcolors(), [(10000, (205, 230, 255))])
+
+ # transparency case with palette: P and PNG
+ COLOUR = (0, 127, 255, 50)
+ im, buf = _create_image('PNG', 'RGBA', SIZE, COLOUR)
+ im = im.convert('P')
+ converted, _ = self.pipeline.convert_image(im, response_body=buf)
+ self.assertEqual(converted.mode, 'RGB')
+ self.assertEqual(converted.getcolors(), [(10000, (205, 230, 255))])
+
class DeprecatedImagesPipeline(ImagesPipeline):
def file_key(self, url):
return self.image_key(url)