Skip to content

Commit 976006b

Browse files
committed
Use a fixture for corrupted image
1 parent 9083cca commit 976006b

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

tests/mock_vws/fixtures/images.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ def png_rgb() -> io.BytesIO:
3737
)
3838

3939

40+
@pytest.fixture
41+
def corrupted_image_file() -> io.BytesIO:
42+
"""
43+
Return an image file which is corrupted.
44+
"""
45+
original_image = make_image_file(
46+
file_format='PNG',
47+
color_space='RGB',
48+
width=1,
49+
height=1,
50+
)
51+
original_data = original_image.getvalue()
52+
corrupted_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
53+
return io.BytesIO(corrupted_data)
54+
55+
4056
@pytest.fixture
4157
def image_file_failed_state() -> io.BytesIO:
4258
"""

tests/mock_vws/test_add_target.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,12 @@ def test_bad_image_format_or_color_space(
441441
def test_corrupted(
442442
self,
443443
vuforia_database_keys: VuforiaDatabaseKeys,
444-
png_rgb: io.BytesIO,
444+
corrupted_image_file: io.BytesIO,
445445
) -> None:
446446
"""
447447
No error is returned when the given image is corrupted.
448448
"""
449-
original_data = png_rgb.getvalue()
450-
corrupted_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
451-
corrupted_file = io.BytesIO(corrupted_data)
452-
453-
image_data = corrupted_file.read()
449+
image_data = corrupted_image_file.getvalue()
454450
image_data_encoded = base64.b64encode(image_data).decode('ascii')
455451

456452
data = {

tests/mock_vws/test_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,13 +1024,12 @@ class TestBadImage:
10241024
def test_corrupted(
10251025
self,
10261026
vuforia_database_keys: VuforiaDatabaseKeys,
1027-
png_rgb: io.BytesIO,
1027+
corrupted_image_file: io.BytesIO,
10281028
) -> None:
10291029
"""
10301030
A "BadImage" result is returned when a corrupted image is given.
10311031
"""
1032-
original_data = png_rgb.getvalue()
1033-
corrupted_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
1032+
corrupted_data = corrupted_image_file.getvalue()
10341033

10351034
body = {'image': ('image.jpeg', corrupted_data, 'image/jpeg')}
10361035

tests/mock_vws/test_update_target.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,16 +766,14 @@ def test_bad_image_format_or_color_space(
766766
def test_corrupted(
767767
self,
768768
vuforia_database_keys: VuforiaDatabaseKeys,
769-
png_rgb: io.BytesIO,
769+
corrupted_image_file: io.BytesIO,
770770
target_id: str,
771771
) -> None:
772772
"""
773773
No error is returned when the given image is corrupted.
774774
"""
775-
original_data = png_rgb.getvalue()
776-
corrupted_data = original_data.replace(b'IEND', b'\x00' + b'IEND')
777-
778-
image_data_encoded = base64.b64encode(corrupted_data).decode('ascii')
775+
image_data = corrupted_image_file.getvalue()
776+
image_data_encoded = base64.b64encode(image_data).decode('ascii')
779777

780778
wait_for_target_processed(
781779
vuforia_database_keys=vuforia_database_keys,

0 commit comments

Comments
 (0)