Skip to content

Commit 5057f85

Browse files
author
Jon Wayne Parrott
authored
* Add tests for quickstarts * Update secrets
1 parent 8d0551a commit 5057f85

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

samples/snippets/quickstart.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
def run_quickstart():
1919
# [START vision_quickstart]
2020
import io
21+
import os
2122

2223
# Imports the Google Cloud client library
2324
from google.cloud import vision
@@ -26,11 +27,15 @@ def run_quickstart():
2627
vision_client = vision.Client()
2728

2829
# The name of the image file to annotate
29-
fileName = './resources/wakeupcat.jpg'
30+
file_name = os.path.join(
31+
os.path.dirname(__file__),
32+
'resources/wakeupcat.jpg')
3033

3134
# Loads the image into memory
32-
with io.open(fileName, 'rb') as image_file:
33-
image = vision_client.image(content=image_file.read())
35+
with io.open(file_name, 'rb') as image_file:
36+
content = image_file.read()
37+
image = vision_client.image(
38+
content=content)
3439

3540
# Performs label detection on the image file
3641
labels = image.detect_labels()

samples/snippets/quickstart_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import quickstart
16+
17+
18+
def test_quickstart(capsys):
19+
quickstart.run_quickstart()
20+
out, _ = capsys.readouterr()
21+
assert 'Labels' in out

0 commit comments

Comments
 (0)