MCPcopy
hub / github.com/scrapy/scrapy / test_convert_image

Method test_convert_image

tests/test_pipeline_images.py:199–230  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

197 assert new_im.getpixel((0, 0)) == (255, 0, 0)
198
199 def test_convert_image(self):
200 SIZE = (100, 100)
201 # straight forward case: RGB and JPEG
202 COLOUR = (0, 127, 255)
203 im, buf = _create_image("JPEG", "RGB", SIZE, COLOUR)
204 converted, converted_buf = self.pipeline.convert_image(im, response_body=buf)
205 assert converted.mode == "RGB"
206 assert converted.getcolors() == [(10000, COLOUR)]
207 # check that we don't convert JPEGs again
208 assert converted_buf == buf
209
210 # check that thumbnail keep image ratio
211 thumbnail, _ = self.pipeline.convert_image(
212 converted, size=(10, 25), response_body=converted_buf
213 )
214 assert thumbnail.mode == "RGB"
215 assert thumbnail.size == (10, 10)
216
217 # transparency case: RGBA and PNG
218 COLOUR = (0, 127, 255, 50)
219 im, buf = _create_image("PNG", "RGBA", SIZE, COLOUR)
220 converted, _ = self.pipeline.convert_image(im, response_body=buf)
221 assert converted.mode == "RGB"
222 assert converted.getcolors() == [(10000, (205, 230, 255))]
223
224 # transparency case with palette: P and PNG
225 COLOUR = (0, 127, 255, 50)
226 im, buf = _create_image("PNG", "RGBA", SIZE, COLOUR)
227 im = im.convert("P")
228 converted, _ = self.pipeline.convert_image(im, response_body=buf)
229 assert converted.mode == "RGB"
230 assert converted.getcolors() == [(10000, (205, 230, 255))]
231
232 @pytest.mark.parametrize(
233 "bad_type",

Callers

nothing calls this directly

Calls 2

_create_imageFunction · 0.85
convert_imageMethod · 0.80

Tested by

no test coverage detected