33"""
44
55import io
6- import random
76
87import pytest
98from _pytest .fixtures import SubRequest
10- from PIL import Image
119
12-
13- def _image_file (
14- file_format : str ,
15- color_space : str ,
16- width : int ,
17- height : int ,
18- ) -> io .BytesIO :
19- """
20- Return an image file in the given format and color space.
21-
22- The image file is filled with randomly colored pixels.
23-
24- Args:
25- file_format: See
26- http://pillow.readthedocs.io/en/3.1.x/handbook/image-file-formats.html
27- color_space: One of "L", "RGB", or "CMYK". "L" means greyscale.
28- width: The width, in pixels of the image.
29- height: The width, in pixels of the image.
30-
31- Returns:
32- An image file in the given format and color space.
33- """
34- image_buffer = io .BytesIO ()
35- image = Image .new (color_space , (width , height ))
36- pixels = image .load ()
37- for i in range (height ):
38- for j in range (width ):
39- red = random .randint (0 , 255 )
40- green = random .randint (0 , 255 )
41- blue = random .randint (0 , 255 )
42- if color_space != 'L' :
43- pixels [j , i ] = (red , green , blue )
44- image .save (image_buffer , file_format )
45- image_buffer .seek (0 )
46- return image_buffer
10+ from tests .mock_vws .utils import make_image_file
4711
4812
4913@pytest .fixture
@@ -52,23 +16,38 @@ def png_rgb_success() -> io.BytesIO:
5216 Return a PNG file in the RGB color space which is expected to have a
5317 'success' status when added to a target.
5418 """
55- return _image_file (file_format = 'PNG' , color_space = 'RGB' , width = 5 , height = 5 )
19+ return make_image_file (
20+ file_format = 'PNG' ,
21+ color_space = 'RGB' ,
22+ width = 5 ,
23+ height = 5 ,
24+ )
5625
5726
5827@pytest .fixture
5928def png_rgb () -> io .BytesIO :
6029 """
6130 Return a 1x1 PNG file in the RGB color space.
6231 """
63- return _image_file (file_format = 'PNG' , color_space = 'RGB' , width = 1 , height = 1 )
32+ return make_image_file (
33+ file_format = 'PNG' ,
34+ color_space = 'RGB' ,
35+ width = 1 ,
36+ height = 1 ,
37+ )
6438
6539
6640@pytest .fixture
6741def png_greyscale () -> io .BytesIO :
6842 """
6943 Return a 1x1 PNG file in the greyscale color space.
7044 """
71- return _image_file (file_format = 'PNG' , color_space = 'L' , width = 1 , height = 1 )
45+ return make_image_file (
46+ file_format = 'PNG' ,
47+ color_space = 'L' ,
48+ width = 1 ,
49+ height = 1 ,
50+ )
7251
7352
7453@pytest .fixture ()
@@ -98,7 +77,7 @@ def jpeg_cmyk() -> io.BytesIO:
9877 """
9978 Return a 1x1 JPEG file in the CMYK color space.
10079 """
101- return _image_file (
80+ return make_image_file (
10281 file_format = 'JPEG' ,
10382 color_space = 'CMYK' ,
10483 width = 1 ,
@@ -111,7 +90,7 @@ def jpeg_rgb() -> io.BytesIO:
11190 """
11291 Return a 1x1 JPEG file in the RGB color space.
11392 """
114- return _image_file (
93+ return make_image_file (
11594 file_format = 'JPEG' ,
11695 color_space = 'RGB' ,
11796 width = 1 ,
@@ -127,7 +106,7 @@ def tiff_rgb() -> io.BytesIO:
127106 This is given as an option which is not supported by Vuforia as Vuforia
128107 supports only JPEG and PNG files.
129108 """
130- return _image_file (
109+ return make_image_file (
131110 file_format = 'TIFF' ,
132111 color_space = 'RGB' ,
133112 width = 1 ,
0 commit comments