|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | 8 | import uuid |
9 | | -from enum import Enum, auto |
10 | 9 | from typing import TYPE_CHECKING |
11 | 10 |
|
12 | 11 | import pytest |
@@ -120,73 +119,60 @@ def test_success_status( |
120 | 119 | assert new_tracking_rating == tracking_rating |
121 | 120 |
|
122 | 121 |
|
| 122 | +def _get_target_tracking_rating( |
| 123 | + vws_client: VWS, |
| 124 | + image_file: io.BytesIO, |
| 125 | +) -> int: |
| 126 | + """ |
| 127 | + Get the tracking rating of a target. |
| 128 | + """ |
| 129 | + target_id = vws_client.add_target( |
| 130 | + name=f"example_{uuid.uuid4().hex}", |
| 131 | + width=1, |
| 132 | + image=image_file, |
| 133 | + active_flag=True, |
| 134 | + application_metadata=None, |
| 135 | + ) |
| 136 | + |
| 137 | + vws_client.wait_for_target_processed(target_id=target_id) |
| 138 | + target_details = vws_client.get_target_record(target_id=target_id) |
| 139 | + return target_details.target_record.tracking_rating |
| 140 | + |
| 141 | + |
123 | 142 | @pytest.mark.usefixtures("verify_mock_vuforia") |
124 | 143 | class TestTargetTrackingRating: |
125 | 144 | """ |
126 | | - Tests which exercise the target tracking_rating, and check the image fixtures we |
127 | | - use. |
| 145 | + Tests which exercise the target tracking_rating, and check the image |
| 146 | + fixtures we use. |
128 | 147 | """ |
129 | 148 |
|
130 | 149 | @staticmethod |
131 | | - # We use almost all of the image fixtures here. |
132 | | - # We do not use images which we expect to fail to upload (`png_too_large`, `bad_image_file`). |
133 | 150 | def test_target_quality( |
134 | 151 | vws_client: VWS, |
135 | 152 | high_quality_image: io.BytesIO, |
136 | | - image_file_failed_state: io.BytesIO, |
137 | 153 | image_file_success_state_low_rating: io.BytesIO, |
138 | 154 | corrupted_image_file: io.BytesIO, |
139 | | - different_high_quality_image: io.BytesIO, |
140 | 155 | ) -> None: |
141 | 156 | """ |
142 | 157 | The target tracking rating is as expected. |
143 | 158 | """ |
144 | | - |
145 | | - class TrackingRating(Enum): |
146 | | - ZERO = auto() |
147 | | - NEGATIVE = auto() |
148 | | - POSITIVE = auto() |
149 | | - |
150 | | - target_id_expected_rating_pairs = [] |
151 | | - for image_file in ( |
152 | | - high_quality_image, |
153 | | - image_file_failed_state, |
154 | | - # image_file_success_state_low_rating, |
155 | | - corrupted_image_file, |
156 | | - # different_high_quality_image, |
157 | | - ): |
158 | | - target_id = vws_client.add_target( |
159 | | - name=f"example_{uuid.uuid4().hex}", |
160 | | - width=1, |
161 | | - image=image_file, |
162 | | - active_flag=True, |
163 | | - application_metadata=None, |
164 | | - ) |
165 | | - |
166 | | - expected_tracking_rating = { |
167 | | - high_quality_image: TrackingRating.POSITIVE, |
168 | | - image_file_failed_state: TrackingRating.ZERO, |
169 | | - image_file_success_state_low_rating: TrackingRating.ZERO, |
170 | | - corrupted_image_file: TrackingRating.NEGATIVE, |
171 | | - different_high_quality_image: TrackingRating.ZERO, |
172 | | - }[image_file] |
173 | | - target_id_expected_rating_pairs.append( |
174 | | - (target_id, expected_tracking_rating), |
175 | | - ) |
176 | | - |
177 | | - for ( |
178 | | - target_id, |
179 | | - expected_tracking_rating, |
180 | | - ) in target_id_expected_rating_pairs: |
181 | | - vws_client.wait_for_target_processed(target_id=target_id) |
182 | | - |
183 | | - target_details = vws_client.get_target_record(target_id=target_id) |
184 | | - if expected_tracking_rating == TrackingRating.ZERO: |
185 | | - assert target_details.target_record.tracking_rating == 0 |
186 | | - elif expected_tracking_rating == TrackingRating.NEGATIVE: |
187 | | - assert target_details.target_record.tracking_rating < 0 |
188 | | - else: |
189 | | - assert target_details.target_record.tracking_rating > 0 |
| 159 | + high_quality_image_tracking_rating = _get_target_tracking_rating( |
| 160 | + vws_client=vws_client, |
| 161 | + image_file=high_quality_image, |
| 162 | + ) |
| 163 | + low_quality_image_tracking_rating = _get_target_tracking_rating( |
| 164 | + vws_client=vws_client, |
| 165 | + image_file=image_file_success_state_low_rating, |
| 166 | + ) |
| 167 | + corrupted_image_file_tracking_rating = _get_target_tracking_rating( |
| 168 | + vws_client=vws_client, |
| 169 | + image_file=corrupted_image_file, |
| 170 | + ) |
| 171 | + assert ( |
| 172 | + high_quality_image_tracking_rating |
| 173 | + > low_quality_image_tracking_rating |
| 174 | + >= corrupted_image_file_tracking_rating |
| 175 | + ) |
190 | 176 |
|
191 | 177 |
|
192 | 178 | @pytest.mark.usefixtures("verify_mock_vuforia") |
|
0 commit comments