Skip to content

Commit f29a065

Browse files
chore(fixit): sample clean up for vision quickstart (GoogleCloudPlatform#10050)
* chore(fixit): sample clean up for vision quickstart * added back printing labels --------- Co-authored-by: Balaji Subramaniam <balajismaniam@google.com>
1 parent c2d2a8a commit f29a065

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

vision/snippets/quickstart/quickstart.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,29 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# [START vision_quickstart]
18+
import os
1719

18-
def run_quickstart():
19-
# [START vision_quickstart]
20-
import os
20+
# Imports the Google Cloud client library
21+
# [START vision_python_migration_import]
22+
from google.cloud import vision
2123

22-
# Imports the Google Cloud client library
23-
# [START vision_python_migration_import]
24-
from google.cloud import vision
25-
# [END vision_python_migration_import]
24+
# [END vision_python_migration_import]
25+
26+
27+
def run_quickstart() -> vision.EntityAnnotation:
28+
"""Provides a quick start example for Cloud Vision."""
2629

2730
# Instantiates a client
2831
# [START vision_python_migration_client]
2932
client = vision.ImageAnnotatorClient()
3033
# [END vision_python_migration_client]
3134

3235
# The name of the image file to annotate
33-
file_name = os.path.abspath('resources/wakeupcat.jpg')
36+
file_name = os.path.abspath("resources/wakeupcat.jpg")
3437

3538
# Loads the image into memory
36-
with open(file_name, 'rb') as image_file:
39+
with open(file_name, "rb") as image_file:
3740
content = image_file.read()
3841

3942
image = vision.Image(content=content)
@@ -45,8 +48,11 @@ def run_quickstart():
4548
print('Labels:')
4649
for label in labels:
4750
print(label.description)
48-
# [END vision_quickstart]
4951

52+
return labels
5053

51-
if __name__ == '__main__':
54+
55+
if __name__ == "__main__":
5256
run_quickstart()
57+
58+
# [END vision_quickstart]

vision/snippets/quickstart/quickstart_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import quickstart
1616

1717

18-
def test_quickstart(capsys):
19-
quickstart.run_quickstart()
20-
out, _ = capsys.readouterr()
21-
assert 'Labels' in out
18+
def test_quickstart() -> None:
19+
labels = quickstart.run_quickstart()
20+
for label in labels:
21+
assert len(label.description) > 0

0 commit comments

Comments
 (0)