18
18
19
19
import detect
20
20
21
+ ASSET_BUCKET = "cloud-samples-data"
22
+
21
23
BUCKET = os .environ ['CLOUD_STORAGE_BUCKET' ]
22
24
OUTPUT_PREFIX = 'OCR_PDF_TEST_OUTPUT'
23
25
GCS_SOURCE_URI = 'gs://{}/HodgeConj.pdf' .format (BUCKET )
@@ -34,15 +36,16 @@ def test_labels(capsys):
34
36
35
37
36
38
def test_labels_uri (capsys ):
37
- file_name = 'gs://{}/vision/wakeupcat.jpg' .format (BUCKET )
39
+ file_name = 'gs://{}/vision/wakeupcat.jpg' .format (ASSET_BUCKET )
38
40
detect .detect_labels_uri (file_name )
39
41
out , _ = capsys .readouterr ()
40
42
assert 'Labels' in out
41
43
42
44
43
45
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 ))
46
49
out , _ = capsys .readouterr ()
47
50
assert 'Labels' in out
48
51
@@ -53,21 +56,21 @@ def test_landmarks(capsys):
53
56
'resources/landmark.jpg' )
54
57
detect .detect_landmarks (file_name )
55
58
out , _ = capsys .readouterr ()
56
- assert 'Palace ' in out
59
+ assert 'palace ' in out . lower ()
57
60
58
61
59
62
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 )
61
64
detect .detect_landmarks_uri (file_name )
62
65
out , _ = capsys .readouterr ()
63
- assert 'Palace ' in out
66
+ assert 'palace ' in out . lower ()
64
67
65
68
66
69
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 ))
69
72
out , _ = capsys .readouterr ()
70
- assert 'Palace ' in out
73
+ assert 'palace ' in out . lower ()
71
74
72
75
73
76
def test_faces (capsys ):
@@ -80,16 +83,16 @@ def test_faces(capsys):
80
83
81
84
82
85
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 )
84
87
detect .detect_faces_uri (file_name )
85
88
out , _ = capsys .readouterr ()
86
89
assert 'POSSIBLE' in out
87
90
88
91
89
92
def test_faces_http (capsys ):
90
93
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 ))
93
96
out , _ = capsys .readouterr ()
94
97
assert 'POSSIBLE' in out
95
98
@@ -100,21 +103,22 @@ def test_logos(capsys):
100
103
'resources/logos.png' )
101
104
detect .detect_logos (file_name )
102
105
out , _ = capsys .readouterr ()
103
- assert 'google' in out
106
+ assert 'google' in out . lower ()
104
107
105
108
106
109
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 )
108
111
detect .detect_logos_uri (file_name )
109
112
out , _ = capsys .readouterr ()
110
- assert 'google' in out
113
+ assert 'google' in out . lower ()
111
114
112
115
113
116
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 ))
116
120
out , _ = capsys .readouterr ()
117
- assert 'google' in out
121
+ assert 'google' in out . lower ()
118
122
119
123
120
124
def test_safe_search (capsys ):
@@ -128,16 +132,17 @@ def test_safe_search(capsys):
128
132
129
133
130
134
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 )
132
136
detect .detect_safe_search_uri (file_name )
133
137
out , _ = capsys .readouterr ()
134
138
assert 'VERY_LIKELY' in out
135
139
assert 'racy: ' in out
136
140
137
141
138
142
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 ))
141
146
out , _ = capsys .readouterr ()
142
147
assert 'VERY_LIKELY' in out
143
148
assert 'racy: ' in out
@@ -153,15 +158,15 @@ def test_detect_text(capsys):
153
158
154
159
155
160
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 )
157
162
detect .detect_text_uri (file_name )
158
163
out , _ = capsys .readouterr ()
159
164
assert '37%' in out
160
165
161
166
162
167
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 ))
165
170
out , _ = capsys .readouterr ()
166
171
assert '37%' in out
167
172
@@ -176,15 +181,15 @@ def test_detect_properties(capsys):
176
181
177
182
178
183
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 )
180
185
detect .detect_properties_uri (file_name )
181
186
out , _ = capsys .readouterr ()
182
187
assert 'frac' in out
183
188
184
189
185
190
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 ))
188
193
out , _ = capsys .readouterr ()
189
194
assert 'frac' in out
190
195
@@ -196,21 +201,21 @@ def test_detect_web(capsys):
196
201
'resources/landmark.jpg' )
197
202
detect .detect_web (file_name )
198
203
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 ()
200
205
201
206
202
207
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 )
204
209
detect .detect_web_uri (file_name )
205
210
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 ()
207
212
208
213
209
214
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 ))
212
217
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 ()
214
219
215
220
216
221
def test_detect_web_with_geo (capsys ):
@@ -219,14 +224,16 @@ def test_detect_web_with_geo(capsys):
219
224
'resources/city.jpg' )
220
225
detect .web_entities_include_geo_results (file_name )
221
226
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
223
229
224
230
225
231
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 )
227
233
detect .web_entities_include_geo_results_uri (file_name )
228
234
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
230
237
231
238
232
239
def test_detect_document (capsys ):
@@ -239,15 +246,15 @@ def test_detect_document(capsys):
239
246
240
247
241
248
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 )
243
250
detect .detect_document_uri (file_name )
244
251
out , _ = capsys .readouterr ()
245
252
assert 'class' in out
246
253
247
254
248
255
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 ))
251
258
out , _ = capsys .readouterr ()
252
259
assert 'class' in out
253
260
@@ -262,15 +269,16 @@ def test_detect_crop_hints(capsys):
262
269
263
270
264
271
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 )
266
273
detect .detect_crop_hints_uri (file_name )
267
274
out , _ = capsys .readouterr ()
268
275
assert 'bounds: (0,0)' in out
269
276
270
277
271
278
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 ))
274
282
out , _ = capsys .readouterr ()
275
283
assert 'bounds: (0,0)' in out
276
284
@@ -284,13 +292,14 @@ def test_async_detect_document(capsys):
284
292
285
293
assert len (list (bucket .list_blobs (prefix = OUTPUT_PREFIX ))) == 0
286
294
295
+ uri = 'gs://{}/vision/document/custom_0773375000.pdf' .format (ASSET_BUCKET )
287
296
detect .async_detect_document (
288
- gcs_source_uri = GCS_SOURCE_URI ,
297
+ gcs_source_uri = uri ,
289
298
gcs_destination_uri = GCS_DESTINATION_URI )
290
299
out , _ = capsys .readouterr ()
291
300
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
294
303
295
304
for blob in bucket .list_blobs (prefix = OUTPUT_PREFIX ):
296
305
blob .delete ()
@@ -302,7 +311,7 @@ def test_localize_objects(capsys):
302
311
detect .localize_objects ('resources/puppies.jpg' )
303
312
304
313
out , _ = capsys .readouterr ()
305
- assert 'Dog ' in out
314
+ assert 'dog ' in out . lower ()
306
315
307
316
308
317
def test_localize_objects_uri (capsys ):
@@ -311,4 +320,4 @@ def test_localize_objects_uri(capsys):
311
320
detect .localize_objects_uri (uri )
312
321
313
322
out , _ = capsys .readouterr ()
314
- assert 'Dog ' in out
323
+ assert 'dog ' in out . lower ()
0 commit comments