|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import io |
6 | | -import random |
7 | 6 |
|
8 | 7 | import pytest |
9 | 8 | from mock_vws import MockVWS, States |
10 | | -from PIL import Image |
11 | 9 | from requests import codes |
12 | 10 |
|
13 | 11 | from vws import VWS |
14 | 12 | from vws.exceptions import ( |
15 | 13 | BadImage, |
16 | 14 | Fail, |
17 | | - ImageTooLarge, |
18 | 15 | MetadataTooLarge, |
19 | 16 | ProjectInactive, |
20 | 17 | TargetNameExist, |
21 | 18 | ) |
22 | 19 |
|
23 | 20 |
|
24 | | -def make_image_file( |
25 | | - file_format: str, |
26 | | - color_space: str, |
27 | | - width: int, |
28 | | - height: int, |
29 | | -) -> io.BytesIO: |
30 | | - """ |
31 | | - Return an image file in the given format and color space. |
32 | | -
|
33 | | - The image file is filled with randomly colored pixels. |
34 | | -
|
35 | | - Args: |
36 | | - file_format: See |
37 | | - http://pillow.readthedocs.io/en/3.1.x/handbook/image-file-formats.html |
38 | | - color_space: One of "L", "RGB", or "CMYK". "L" means greyscale. |
39 | | - width: The width, in pixels of the image. |
40 | | - height: The width, in pixels of the image. |
41 | | -
|
42 | | - Returns: |
43 | | - An image file in the given format and color space. |
44 | | - """ |
45 | | - image_buffer = io.BytesIO() |
46 | | - image = Image.new(color_space, (width, height)) |
47 | | - pixels = image.load() |
48 | | - for i in range(height): |
49 | | - for j in range(width): |
50 | | - red = random.randint(0, 255) |
51 | | - green = random.randint(0, 255) |
52 | | - blue = random.randint(0, 255) |
53 | | - if color_space != 'L': |
54 | | - pixels[j, i] = (red, green, blue) |
55 | | - image.save(image_buffer, file_format) |
56 | | - image_buffer.seek(0) |
57 | | - return image_buffer |
58 | | - |
59 | | - |
60 | 21 | class TestSuccess: |
61 | 22 | """ |
62 | 23 | Tests for successfully adding a target. |
@@ -117,7 +78,6 @@ def test_add_two_targets_same_name( |
117 | 78 | assert exc.value.response.status_code == codes.FORBIDDEN |
118 | 79 |
|
119 | 80 |
|
120 | | - |
121 | 81 | class TestAuthentication: |
122 | 82 | """ |
123 | 83 | Tests for authentication issues. |
@@ -160,23 +120,6 @@ def test_not_an_image(self, client: VWS) -> None: |
160 | 120 | with pytest.raises(BadImage): |
161 | 121 | client.add_target(name='x', width=1, image=not_an_image) |
162 | 122 |
|
163 | | - def test_image_too_large(self, client: VWS) -> None: |
164 | | - """ |
165 | | - An ``ImageTooLarge`` exception is raised when the given image is too |
166 | | - large. |
167 | | - """ |
168 | | - width = height = 890 |
169 | | - |
170 | | - png_too_large = make_image_file( |
171 | | - file_format='PNG', |
172 | | - color_space='RGB', |
173 | | - width=width, |
174 | | - height=height, |
175 | | - ) |
176 | | - |
177 | | - with pytest.raises(ImageTooLarge): |
178 | | - client.add_target(name='x', width=1, image=png_too_large) |
179 | | - |
180 | 123 |
|
181 | 124 | class TestCustomBaseURL: |
182 | 125 | """ |
|
0 commit comments