Skip to content

Commit 2933e78

Browse files
committed
Progress towards test
1 parent c16d82a commit 2933e78

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Tests for giving an image which is too large.
3+
"""
4+
5+
import io
6+
import random
7+
from pathlib import Path
8+
9+
import pytest
10+
from PIL import Image
11+
12+
13+
def make_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+
reds = random.choices(population=range(0, 255), k=width * height)
36+
greens = random.choices(population=range(0, 255), k=width * height)
37+
blues = random.choices(population=range(0, 255), k=width * height)
38+
pixels = list(zip(reds, greens, blues))
39+
image = Image.new(color_space, (width, height))
40+
image.putdata(pixels)
41+
image.save(image_buffer, file_format)
42+
image_buffer.seek(0)
43+
return image_buffer
44+
45+
46+
def test_foo():
47+
width = height = 890
48+
49+
png_too_large = make_image_file(
50+
file_format='PNG',
51+
color_space='RGB',
52+
width=width,
53+
height=height,
54+
)
55+
#
56+
# with pytest.raises(ImageTooLarge):
57+
# client.add_target(name='x', width=1, image=png_too_large)

0 commit comments

Comments
 (0)