|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import io |
6 | | -import random |
7 | 6 |
|
8 | 7 | import pytest |
9 | 8 | from freezegun import freeze_time |
10 | 9 | from mock_vws import MockVWS |
11 | 10 | from mock_vws.database import VuforiaDatabase |
12 | 11 | from mock_vws.states import States |
13 | | -from PIL import Image |
14 | 12 | from requests import codes |
15 | 13 |
|
16 | 14 | from vws import VWS, CloudRecoService |
|
30 | 28 | ) |
31 | 29 |
|
32 | 30 |
|
33 | | -def _make_image_file( |
34 | | - file_format: str, |
35 | | - color_space: str, |
36 | | - width: int, |
37 | | - height: int, |
38 | | -) -> io.BytesIO: |
39 | | - """ |
40 | | - Return an image file in the given format and color space. |
41 | | -
|
42 | | - The image file is filled with randomly colored pixels. |
43 | | -
|
44 | | - Args: |
45 | | - file_format: See |
46 | | - http://pillow.readthedocs.io/en/3.1.x/handbook/image-file-formats.html |
47 | | - color_space: One of "L", "RGB", or "CMYK". |
48 | | - width: The width, in pixels of the image. |
49 | | - height: The width, in pixels of the image. |
50 | | -
|
51 | | - Returns: |
52 | | - An image file in the given format and color space. |
53 | | - """ |
54 | | - image_buffer = io.BytesIO() |
55 | | - reds = random.choices(population=range(0, 255), k=width * height) |
56 | | - greens = random.choices(population=range(0, 255), k=width * height) |
57 | | - blues = random.choices(population=range(0, 255), k=width * height) |
58 | | - pixels = list(zip(reds, greens, blues)) |
59 | | - image = Image.new(color_space, (width, height)) |
60 | | - image.putdata(pixels) |
61 | | - image.save(image_buffer, file_format) |
62 | | - image_buffer.seek(0) |
63 | | - return image_buffer |
64 | | - |
65 | | - |
66 | | -def test_image_too_large(vws_client: VWS) -> None: |
| 31 | +def test_image_too_large( |
| 32 | + vws_client: VWS, |
| 33 | + png_too_large: io.BytesIO, |
| 34 | +) -> None: |
67 | 35 | """ |
68 | 36 | When giving an image which is too large, an ``ImageTooLarge`` exception is |
69 | 37 | raised. |
70 | 38 | """ |
71 | | - width = height = 890 |
72 | | - |
73 | | - png_too_large = _make_image_file( |
74 | | - file_format='PNG', |
75 | | - color_space='RGB', |
76 | | - width=width, |
77 | | - height=height, |
78 | | - ) |
79 | | - |
80 | 39 | with pytest.raises(ImageTooLarge) as exc: |
81 | 40 | vws_client.add_target(name='x', width=1, image=png_too_large) |
82 | 41 |
|
|
0 commit comments