forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_test.py
More file actions
251 lines (188 loc) · 7.12 KB
/
detect_test.py
File metadata and controls
251 lines (188 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import detect
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
def test_labels(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/wakeupcat.jpg')
detect.detect_labels(file_name)
out, _ = capsys.readouterr()
assert 'Labels' in out
def test_labels_uri(capsys):
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
detect.detect_labels_uri(file_name)
out, _ = capsys.readouterr()
assert 'Labels' in out
def test_labels_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
detect.detect_labels_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'Labels' in out
def test_landmarks(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/landmark.jpg')
detect.detect_landmarks(file_name)
out, _ = capsys.readouterr()
assert 'Palace' in out
def test_landmarks_uri(capsys):
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
detect.detect_landmarks_uri(file_name)
out, _ = capsys.readouterr()
assert 'Palace' in out
def test_landmarks_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/landmark.jpg'
detect.detect_landmarks_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'Palace' in out
def test_faces(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/face_no_surprise.jpg')
detect.detect_faces(file_name)
out, _ = capsys.readouterr()
assert 'POSSIBLE' in out
def test_faces_uri(capsys):
file_name = 'gs://{}/vision/face_no_surprise.jpg'.format(BUCKET)
detect.detect_faces_uri(file_name)
out, _ = capsys.readouterr()
assert 'POSSIBLE' in out
def test_faces_http(capsys):
uri = ('https://storage-download.googleapis.com/{}/vision/' +
'face_no_surprise.jpg')
detect.detect_faces_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'POSSIBLE' in out
def test_logos(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/logos.png')
detect.detect_logos(file_name)
out, _ = capsys.readouterr()
assert 'Google' in out
def test_logos_uri(capsys):
file_name = 'gs://{}/vision/logos.png'.format(BUCKET)
detect.detect_logos_uri(file_name)
out, _ = capsys.readouterr()
assert 'Google' in out
def test_logos_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/logos.png'
detect.detect_logos_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'Google' in out
def test_safe_search(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/wakeupcat.jpg')
detect.detect_safe_search(file_name)
out, _ = capsys.readouterr()
assert 'VERY_LIKELY' in out
def test_safe_search_uri(capsys):
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
detect.detect_safe_search_uri(file_name)
out, _ = capsys.readouterr()
assert 'VERY_LIKELY' in out
def test_safe_search_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
detect.detect_safe_search_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'VERY_LIKELY' in out
def test_detect_text(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/text.jpg')
detect.detect_text(file_name)
out, _ = capsys.readouterr()
assert '37%' in out
def test_detect_text_uri(capsys):
file_name = 'gs://{}/vision/text.jpg'.format(BUCKET)
detect.detect_text_uri(file_name)
out, _ = capsys.readouterr()
assert '37%' in out
def test_detect_text_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/text.jpg'
detect.detect_text_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert '37%' in out
def test_detect_properties(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/landmark.jpg')
detect.detect_properties(file_name)
out, _ = capsys.readouterr()
assert 'frac' in out
def test_detect_properties_uri(capsys):
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
detect.detect_properties_uri(file_name)
out, _ = capsys.readouterr()
assert 'frac' in out
def test_detect_properties_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/landmark.jpg'
detect.detect_properties_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'frac' in out
# Vision 1.1 tests
def test_detect_web(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/landmark.jpg')
detect.detect_web(file_name)
out, _ = capsys.readouterr()
assert 'Description: Palace of Fine Arts Theatre' in out
def test_detect_web_uri(capsys):
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
detect.detect_web_uri(file_name)
out, _ = capsys.readouterr()
assert 'Description: Palace of Fine Arts Theatre' in out
def test_detect_web_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/landmark.jpg'
detect.detect_web_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'Description: Palace of Fine Arts Theatre' in out
def test_detect_document(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/text.jpg')
detect.detect_document(file_name)
out, _ = capsys.readouterr()
assert '37%' in out
def test_detect_document_uri(capsys):
file_name = 'gs://{}/vision/text.jpg'.format(BUCKET)
detect.detect_document_uri(file_name)
out, _ = capsys.readouterr()
assert '37%' in out
def test_detect_document_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/text.jpg'
detect.detect_document_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert '37%' in out
def test_detect_crop_hints(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/wakeupcat.jpg')
detect.detect_crop_hints(file_name)
out, _ = capsys.readouterr()
assert 'bounds: (0,0)' in out
def test_detect_crop_hints_uri(capsys):
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
detect.detect_crop_hints_uri(file_name)
out, _ = capsys.readouterr()
assert 'bounds: (0,0)' in out
def test_detect_crop_hints_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
detect.detect_crop_hints_uri(uri.format(BUCKET))
out, _ = capsys.readouterr()
assert 'bounds: (0,0)' in out