|
5 | 5 | import io |
6 | 6 | import uuid |
7 | 7 |
|
| 8 | +import pytest |
8 | 9 | from mock_vws import MockVWS |
9 | 10 | from mock_vws.database import VuforiaDatabase |
10 | 11 |
|
11 | 12 | from vws import VWS, CloudRecoService |
| 13 | +from vws.exceptions import MaxNumResultsOutOfRange |
12 | 14 |
|
13 | 15 |
|
14 | 16 | class TestQuery: |
@@ -111,3 +113,57 @@ def test_default( |
111 | 113 | vws_client.wait_for_target_processed(target_id=target_id_2) |
112 | 114 | matches = cloud_reco_client.query(image=high_quality_image) |
113 | 115 | assert len(matches) == 1 |
| 116 | + |
| 117 | + def test_custom( |
| 118 | + self, |
| 119 | + vws_client: VWS, |
| 120 | + cloud_reco_client: CloudRecoService, |
| 121 | + high_quality_image: io.BytesIO, |
| 122 | + ) -> None: |
| 123 | + """ |
| 124 | + It is possible to set a custom ``max_num_results``. |
| 125 | + """ |
| 126 | + target_id = vws_client.add_target( |
| 127 | + name=uuid.uuid4().hex, |
| 128 | + width=1, |
| 129 | + image=high_quality_image, |
| 130 | + ) |
| 131 | + target_id_2 = vws_client.add_target( |
| 132 | + name=uuid.uuid4().hex, |
| 133 | + width=1, |
| 134 | + image=high_quality_image, |
| 135 | + ) |
| 136 | + target_id_3 = vws_client.add_target( |
| 137 | + name=uuid.uuid4().hex, |
| 138 | + width=1, |
| 139 | + image=high_quality_image, |
| 140 | + ) |
| 141 | + vws_client.wait_for_target_processed(target_id=target_id) |
| 142 | + vws_client.wait_for_target_processed(target_id=target_id_2) |
| 143 | + vws_client.wait_for_target_processed(target_id=target_id_3) |
| 144 | + matches = cloud_reco_client.query( |
| 145 | + image=high_quality_image, |
| 146 | + max_num_results=2, |
| 147 | + ) |
| 148 | + assert len(matches) == 2 |
| 149 | + |
| 150 | + def test_too_many( |
| 151 | + self, |
| 152 | + cloud_reco_client: CloudRecoService, |
| 153 | + high_quality_image: io.BytesIO, |
| 154 | + ) -> None: |
| 155 | + """ |
| 156 | + A ``MaxNumResultsOutOfRange`` error is raised if the given |
| 157 | + ``max_num_results`` is out of range. |
| 158 | + """ |
| 159 | + with pytest.raises(MaxNumResultsOutOfRange) as exc: |
| 160 | + cloud_reco_client.query( |
| 161 | + image=high_quality_image, |
| 162 | + max_num_results=51, |
| 163 | + ) |
| 164 | + |
| 165 | + expected_value = ( |
| 166 | + "Integer out of range (51) in form data part 'max_result'. " |
| 167 | + 'Accepted range is from 1 to 50 (inclusive).' |
| 168 | + ) |
| 169 | + assert str(exc.value) == exc.value.response.text == expected_value |
0 commit comments