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
148 lines (115 loc) · 4.33 KB
/
detect_test.py
File metadata and controls
148 lines (115 loc) · 4.33 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
# 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 pytest
import detect
def test_quickstart(capsys):
detect.run_all_local()
out, _ = capsys.readouterr()
assert 'Labels' in out
assert 'Landmarks' in out
assert 'Faces' in out
assert 'Logos' in out
assert 'Safe search' in out
# TODO: uncomment when https://goo.gl/c47YwV is fixed.
# assert 'Text' in out
assert 'Properties' in out
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 'whiskers' in out
def test_labels_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/wakeupcat.jpg'
detect.detect_labels_cloud_storage(file_name)
out, _ = capsys.readouterr()
assert 'whiskers' 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_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/landmark.jpg'
detect.detect_landmarks_cloud_storage(file_name)
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 'Likelihood.POSSIBLE' in out
def test_faces_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/face_no_surprise.jpg'
detect.detect_faces_cloud_storage(file_name)
out, _ = capsys.readouterr()
assert 'Likelihood.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_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/logos.png'
detect.detect_logos_cloud_storage(file_name)
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 'Likelihood.VERY_LIKELY' in out
def test_safe_search_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/wakeupcat.jpg'
detect.detect_safe_search_cloud_storage(file_name)
out, _ = capsys.readouterr()
assert 'Likelihood.VERY_LIKELY' in out
@pytest.mark.xfail(reason='Client library needs to be more resilient'
+ 'https://goo.gl/c47YwV')
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
@pytest.mark.xfail(reason='Client library needs to be more resilient'
+ 'https://goo.gl/c47YwV')
def test_detect_text_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/text.jpg'
detect.detect_text_cloud_storage(file_name)
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 'fraction' in out
def test_detect_properties_cloud_storage(capsys):
file_name = 'gs://python-docs-samples-tests/vision/landmark.jpg'
detect.detect_properties_cloud_storage(file_name)
out, _ = capsys.readouterr()
assert 'fraction' in out