Skip to content

Commit 1f14fff

Browse files
authored
Vision API: further fixes. (#2002)
* Vision API: further fixes. Redirects testing to the central cloud-samples-data asset bucket. Relaxes case considerations. Addresses web subtests, missed in previous PR.
1 parent 6afeca5 commit 1f14fff

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

vision/cloud-client/detect/detect_test.py

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import detect
2020

21+
ASSET_BUCKET = "cloud-samples-data"
22+
2123
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2224
OUTPUT_PREFIX = 'OCR_PDF_TEST_OUTPUT'
2325
GCS_SOURCE_URI = 'gs://{}/HodgeConj.pdf'.format(BUCKET)
@@ -34,15 +36,16 @@ def test_labels(capsys):
3436

3537

3638
def test_labels_uri(capsys):
37-
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
39+
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(ASSET_BUCKET)
3840
detect.detect_labels_uri(file_name)
3941
out, _ = capsys.readouterr()
4042
assert 'Labels' in out
4143

4244

4345
def test_labels_http(capsys):
44-
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
45-
detect.detect_labels_uri(uri.format(BUCKET))
46+
uri = 'https://storage-download.googleapis.com/{}' \
47+
'/vision/label/wakeupcat.jpg'
48+
detect.detect_labels_uri(uri.format(ASSET_BUCKET))
4649
out, _ = capsys.readouterr()
4750
assert 'Labels' in out
4851

@@ -53,21 +56,21 @@ def test_landmarks(capsys):
5356
'resources/landmark.jpg')
5457
detect.detect_landmarks(file_name)
5558
out, _ = capsys.readouterr()
56-
assert 'Palace' in out
59+
assert 'palace' in out.lower()
5760

5861

5962
def test_landmarks_uri(capsys):
60-
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
63+
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
6164
detect.detect_landmarks_uri(file_name)
6265
out, _ = capsys.readouterr()
63-
assert 'Palace' in out
66+
assert 'palace' in out.lower()
6467

6568

6669
def test_landmarks_http(capsys):
67-
uri = 'https://storage-download.googleapis.com/{}/vision/landmark.jpg'
68-
detect.detect_landmarks_uri(uri.format(BUCKET))
70+
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
71+
detect.detect_landmarks_uri(uri.format(ASSET_BUCKET))
6972
out, _ = capsys.readouterr()
70-
assert 'Palace' in out
73+
assert 'palace' in out.lower()
7174

7275

7376
def test_faces(capsys):
@@ -80,16 +83,16 @@ def test_faces(capsys):
8083

8184

8285
def test_faces_uri(capsys):
83-
file_name = 'gs://{}/vision/face_no_surprise.jpg'.format(BUCKET)
86+
file_name = 'gs://{}/vision/face/face_no_surprise.jpg'.format(ASSET_BUCKET)
8487
detect.detect_faces_uri(file_name)
8588
out, _ = capsys.readouterr()
8689
assert 'POSSIBLE' in out
8790

8891

8992
def test_faces_http(capsys):
9093
uri = ('https://storage-download.googleapis.com/{}/vision/' +
91-
'face_no_surprise.jpg')
92-
detect.detect_faces_uri(uri.format(BUCKET))
94+
'face/face_no_surprise.jpg')
95+
detect.detect_faces_uri(uri.format(ASSET_BUCKET))
9396
out, _ = capsys.readouterr()
9497
assert 'POSSIBLE' in out
9598

@@ -100,21 +103,22 @@ def test_logos(capsys):
100103
'resources/logos.png')
101104
detect.detect_logos(file_name)
102105
out, _ = capsys.readouterr()
103-
assert 'google' in out
106+
assert 'google' in out.lower()
104107

105108

106109
def test_logos_uri(capsys):
107-
file_name = 'gs://{}/vision/logos.png'.format(BUCKET)
110+
file_name = 'gs://{}/vision/logo/logo_google.png'.format(ASSET_BUCKET)
108111
detect.detect_logos_uri(file_name)
109112
out, _ = capsys.readouterr()
110-
assert 'google' in out
113+
assert 'google' in out.lower()
111114

112115

113116
def test_logos_http(capsys):
114-
uri = 'https://storage-download.googleapis.com/{}/vision/logos.png'
115-
detect.detect_logos_uri(uri.format(BUCKET))
117+
uri = 'https://storage-download.googleapis.com/{}' \
118+
'/vision/logo/logo_google.png'
119+
detect.detect_logos_uri(uri.format(ASSET_BUCKET))
116120
out, _ = capsys.readouterr()
117-
assert 'google' in out
121+
assert 'google' in out.lower()
118122

119123

120124
def test_safe_search(capsys):
@@ -128,16 +132,17 @@ def test_safe_search(capsys):
128132

129133

130134
def test_safe_search_uri(capsys):
131-
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
135+
file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(ASSET_BUCKET)
132136
detect.detect_safe_search_uri(file_name)
133137
out, _ = capsys.readouterr()
134138
assert 'VERY_LIKELY' in out
135139
assert 'racy: ' in out
136140

137141

138142
def test_safe_search_http(capsys):
139-
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
140-
detect.detect_safe_search_uri(uri.format(BUCKET))
143+
uri = 'https://storage-download.googleapis.com/{}' \
144+
'/vision/label/wakeupcat.jpg'
145+
detect.detect_safe_search_uri(uri.format(ASSET_BUCKET))
141146
out, _ = capsys.readouterr()
142147
assert 'VERY_LIKELY' in out
143148
assert 'racy: ' in out
@@ -153,15 +158,15 @@ def test_detect_text(capsys):
153158

154159

155160
def test_detect_text_uri(capsys):
156-
file_name = 'gs://{}/vision/text.jpg'.format(BUCKET)
161+
file_name = 'gs://{}/vision/text/screen.jpg'.format(ASSET_BUCKET)
157162
detect.detect_text_uri(file_name)
158163
out, _ = capsys.readouterr()
159164
assert '37%' in out
160165

161166

162167
def test_detect_text_http(capsys):
163-
uri = 'https://storage-download.googleapis.com/{}/vision/text.jpg'
164-
detect.detect_text_uri(uri.format(BUCKET))
168+
uri = 'https://storage-download.googleapis.com/{}/vision/text/screen.jpg'
169+
detect.detect_text_uri(uri.format(ASSET_BUCKET))
165170
out, _ = capsys.readouterr()
166171
assert '37%' in out
167172

@@ -176,15 +181,15 @@ def test_detect_properties(capsys):
176181

177182

178183
def test_detect_properties_uri(capsys):
179-
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
184+
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
180185
detect.detect_properties_uri(file_name)
181186
out, _ = capsys.readouterr()
182187
assert 'frac' in out
183188

184189

185190
def test_detect_properties_http(capsys):
186-
uri = 'https://storage-download.googleapis.com/{}/vision/landmark.jpg'
187-
detect.detect_properties_uri(uri.format(BUCKET))
191+
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
192+
detect.detect_properties_uri(uri.format(ASSET_BUCKET))
188193
out, _ = capsys.readouterr()
189194
assert 'frac' in out
190195

@@ -196,21 +201,21 @@ def test_detect_web(capsys):
196201
'resources/landmark.jpg')
197202
detect.detect_web(file_name)
198203
out, _ = capsys.readouterr()
199-
assert 'Best guess label: palace of fine arts' in out
204+
assert 'best guess label: palace of fine arts' in out.lower()
200205

201206

202207
def test_detect_web_uri(capsys):
203-
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
208+
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
204209
detect.detect_web_uri(file_name)
205210
out, _ = capsys.readouterr()
206-
assert 'Best guess label: palace of fine arts' in out
211+
assert 'best guess label: palace of fine arts' in out.lower()
207212

208213

209214
def test_detect_web_http(capsys):
210-
uri = 'https://storage-download.googleapis.com/{}/vision/landmark.jpg'
211-
detect.detect_web_uri(uri.format(BUCKET))
215+
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
216+
detect.detect_web_uri(uri.format(ASSET_BUCKET))
212217
out, _ = capsys.readouterr()
213-
assert 'Best guess label: palace of fine arts' in out
218+
assert 'best guess label: palace of fine arts' in out.lower()
214219

215220

216221
def test_detect_web_with_geo(capsys):
@@ -219,14 +224,16 @@ def test_detect_web_with_geo(capsys):
219224
'resources/city.jpg')
220225
detect.web_entities_include_geo_results(file_name)
221226
out, _ = capsys.readouterr()
222-
assert 'Zepra' in out or 'Electra Tower' in out
227+
out = out.lower()
228+
assert 'zepra' in out or 'electra tower' in out
223229

224230

225231
def test_detect_web_with_geo_uri(capsys):
226-
file_name = 'gs://{}/vision/city.jpg'.format(BUCKET)
232+
file_name = 'gs://{}/vision/web/city.jpg'.format(ASSET_BUCKET)
227233
detect.web_entities_include_geo_results_uri(file_name)
228234
out, _ = capsys.readouterr()
229-
assert 'Zepra' in out or 'Electra Tower' in out
235+
out = out.lower()
236+
assert 'zepra' in out or 'electra tower' in out
230237

231238

232239
def test_detect_document(capsys):
@@ -239,15 +246,15 @@ def test_detect_document(capsys):
239246

240247

241248
def test_detect_document_uri(capsys):
242-
file_name = 'gs://{}/vision/text.jpg'.format(BUCKET)
249+
file_name = 'gs://{}/vision/text/screen.jpg'.format(ASSET_BUCKET)
243250
detect.detect_document_uri(file_name)
244251
out, _ = capsys.readouterr()
245252
assert 'class' in out
246253

247254

248255
def test_detect_document_http(capsys):
249-
uri = 'https://storage-download.googleapis.com/{}/vision/text.jpg'
250-
detect.detect_document_uri(uri.format(BUCKET))
256+
uri = 'https://storage-download.googleapis.com/{}/vision/text/screen.jpg'
257+
detect.detect_document_uri(uri.format(ASSET_BUCKET))
251258
out, _ = capsys.readouterr()
252259
assert 'class' in out
253260

@@ -262,15 +269,16 @@ def test_detect_crop_hints(capsys):
262269

263270

264271
def test_detect_crop_hints_uri(capsys):
265-
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
272+
file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(ASSET_BUCKET)
266273
detect.detect_crop_hints_uri(file_name)
267274
out, _ = capsys.readouterr()
268275
assert 'bounds: (0,0)' in out
269276

270277

271278
def test_detect_crop_hints_http(capsys):
272-
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
273-
detect.detect_crop_hints_uri(uri.format(BUCKET))
279+
uri = 'https://storage-download.googleapis.com/{}' \
280+
'/vision/label/wakeupcat.jpg'
281+
detect.detect_crop_hints_uri(uri.format(ASSET_BUCKET))
274282
out, _ = capsys.readouterr()
275283
assert 'bounds: (0,0)' in out
276284

@@ -284,13 +292,14 @@ def test_async_detect_document(capsys):
284292

285293
assert len(list(bucket.list_blobs(prefix=OUTPUT_PREFIX))) == 0
286294

295+
uri = 'gs://{}/vision/document/custom_0773375000.pdf'.format(ASSET_BUCKET)
287296
detect.async_detect_document(
288-
gcs_source_uri=GCS_SOURCE_URI,
297+
gcs_source_uri=uri,
289298
gcs_destination_uri=GCS_DESTINATION_URI)
290299
out, _ = capsys.readouterr()
291300

292-
assert 'Hodge conjecture' in out
293-
assert len(list(bucket.list_blobs(prefix=OUTPUT_PREFIX))) == 3
301+
assert 'OIL, GAS AND MINERAL LEASE' in out
302+
assert len(list(bucket.list_blobs(prefix=OUTPUT_PREFIX))) > 0
294303

295304
for blob in bucket.list_blobs(prefix=OUTPUT_PREFIX):
296305
blob.delete()
@@ -302,7 +311,7 @@ def test_localize_objects(capsys):
302311
detect.localize_objects('resources/puppies.jpg')
303312

304313
out, _ = capsys.readouterr()
305-
assert 'Dog' in out
314+
assert 'dog' in out.lower()
306315

307316

308317
def test_localize_objects_uri(capsys):
@@ -311,4 +320,4 @@ def test_localize_objects_uri(capsys):
311320
detect.localize_objects_uri(uri)
312321

313322
out, _ = capsys.readouterr()
314-
assert 'Dog' in out
323+
assert 'dog' in out.lower()

vision/cloud-client/web/web_detect_test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
16-
1715
import web_detect
1816

19-
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
17+
ASSET_BUCKET = "cloud-samples-data"
2018

2119

2220
def test_detect_file(capsys):
2321
file_name = ('../detect/resources/landmark.jpg')
2422
web_detect.report(web_detect.annotate(file_name))
2523
out, _ = capsys.readouterr()
26-
assert 'Description: Palace of Fine Arts Theatre' in out
24+
print(out)
25+
assert 'description: palace of fine arts' in out.lower()
2726

2827

2928
def test_detect_web_gsuri(capsys):
30-
file_name = ('gs://{}/vision/landmark.jpg'.format(
31-
BUCKET))
29+
file_name = ('gs://{}/vision/landmark/pofa.jpg'.format(
30+
ASSET_BUCKET))
3231
web_detect.report(web_detect.annotate(file_name))
3332
out, _ = capsys.readouterr()
34-
assert 'Description: Palace of Fine Arts Theatre' in out
33+
assert 'description: palace of fine arts' in out.lower()
3534

3635

3736
def test_detect_web_http(capsys):

0 commit comments

Comments
 (0)