File tree 15 files changed +265
-12
lines changed
15 files changed +265
-12
lines changed Original file line number Diff line number Diff line change 16
16
- GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/testing/resources/service-account.json
17
17
- GOOGLE_CLIENT_SECRETS=${TRAVIS_BUILD_DIR}/testing/resources/client-secrets.json
18
18
- GAE_ROOT=${HOME}/.cache/
19
- - secure : TQ0e6XKeFwVkoqgOJH9f/afyRouUSC6s7LC32C4JS+O2X4sXyXTPXACmzu5wCW0BXPc6HvITMLvkf7g6XXyGlCPkjM8Uw5Vg5F9+cwN1HMlI+gK6bMGTUfrwN5ruFT+KmEnD4F93NY3xkDbZd0fw23d/mVloTc6V0gUsxEUkuhM =
19
+ - secure : f3aU0nf8ZBV2QfZ03oeqvR0f/JM69P/7IH3IGoBcRUWVIXXhQ6Esh9SmCUILPtis1ZKu11I9c+NDebZio7PFgTqfvLbKzAkrg0ucx+Bsyx6379/S1trbLeKunERSGA3GqK6+OCoR5q/9sKxNvlm/c/e9h7xZmPfP5W0qwVR/K0M =
20
20
addons :
21
21
apt :
22
22
sources :
Original file line number Diff line number Diff line change
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
+ from google .cloud import bigquery
16
+ import pytest
17
+
18
+ import quickstart
19
+
20
+
21
+ # Must match the dataset listed in quickstart.py (there's no easy way to
22
+ # extract this).
23
+ DATASET_ID = 'my_new_dataset'
24
+
25
+
26
+ @pytest .fixture
27
+ def temporary_dataset ():
28
+ """Fixture that ensures the test dataset does not exist before or
29
+ after a test."""
30
+ bigquery_client = bigquery .Client ()
31
+ dataset = bigquery_client .dataset (DATASET_ID )
32
+
33
+ if dataset .exists ():
34
+ dataset .delete ()
35
+
36
+ yield
37
+
38
+ if dataset .exists ():
39
+ dataset .delete ()
40
+
41
+
42
+ def test_quickstart (capsys , temporary_dataset ):
43
+ quickstart .run_quickstart ()
44
+ out , _ = capsys .readouterr ()
45
+ assert DATASET_ID in out
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ def cloud_config():
30
30
project = os .environ .get ('GCLOUD_PROJECT' ),
31
31
storage_bucket = os .environ .get ('CLOUD_STORAGE_BUCKET' ),
32
32
client_secrets = os .environ .get ('GOOGLE_CLIENT_SECRETS' ),
33
- bigtable_instance = os .environ .get ('BIGTABLE_CLUSTER' ))
33
+ bigtable_instance = os .environ .get ('BIGTABLE_CLUSTER' ),
34
+ api_key = os .environ .get ('API_KEY' ))
34
35
35
36
36
37
def get_resource_path (resource , local_path ):
Original file line number Diff line number Diff line change
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 'Saved' in out
Original file line number Diff line number Diff line change @@ -539,7 +539,8 @@ def inequality_invalid(client):
539
539
540
540
return list (query .fetch ())
541
541
542
- except google .cloud .exceptions .BadRequest :
542
+ except (google .cloud .exceptions .BadRequest ,
543
+ google .cloud .exceptions .GrpcRendezvous ):
543
544
pass
544
545
545
546
@@ -579,7 +580,8 @@ def inequality_sort_invalid_not_same(client):
579
580
580
581
return list (query .fetch ())
581
582
582
- except google .cloud .exceptions .BadRequest :
583
+ except (google .cloud .exceptions .BadRequest ,
584
+ google .cloud .exceptions .GrpcRendezvous ):
583
585
pass
584
586
585
587
@@ -593,7 +595,8 @@ def inequality_sort_invalid_not_first(client):
593
595
594
596
return list (query .fetch ())
595
597
596
- except google .cloud .exceptions .BadRequest :
598
+ except (google .cloud .exceptions .BadRequest ,
599
+ google .cloud .exceptions .GrpcRendezvous ):
597
600
pass
598
601
599
602
Original file line number Diff line number Diff line change
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
+
16
+ import quickstart
17
+
18
+
19
+ def test_quickstart (capsys ):
20
+ quickstart .run_quickstart ()
21
+ out , _ = capsys .readouterr ()
22
+ assert 'Sentiment' in out
Original file line number Diff line number Diff line change
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
+
16
+ import quickstart
17
+
18
+
19
+ def test_quickstart (capsys ):
20
+ quickstart .run_quickstart ()
21
+ out , _ = capsys .readouterr ()
22
+ assert 'Logged' in out
Original file line number Diff line number Diff line change
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
+ from google .cloud import pubsub
16
+ import pytest
17
+
18
+ import quickstart
19
+
20
+
21
+ # Must match the dataset listed in quickstart.py (there's no easy way to
22
+ # extract this).
23
+ TOPIC_NAME = 'my-new-topic'
24
+
25
+
26
+ @pytest .fixture
27
+ def temporary_topic ():
28
+ """Fixture that ensures the test dataset does not exist before or
29
+ after a test."""
30
+ pubsub_client = pubsub .Client ()
31
+ topic = pubsub_client .topic (TOPIC_NAME )
32
+
33
+ if topic .exists ():
34
+ topic .delete ()
35
+
36
+ yield
37
+
38
+ if topic .exists ():
39
+ topic .delete ()
40
+
41
+
42
+ def test_quickstart (capsys , temporary_topic ):
43
+ quickstart .run_quickstart ()
44
+ out , _ = capsys .readouterr ()
45
+ assert TOPIC_NAME in out
Original file line number Diff line number Diff line change
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 mock
16
+
17
+ import quickstart
18
+
19
+
20
+ @mock .patch ('google.cloud.storage.client.Client.create_bucket' )
21
+ def test_quickstart (create_bucket_mock , capsys ):
22
+ # Unlike other quickstart tests, this one mocks out the creation
23
+ # because buckets are expensive, globally-namespaced object.
24
+ create_bucket_mock .return_value = mock .sentinel .bucket
25
+
26
+ quickstart .run_quickstart ()
27
+
28
+ create_bucket_mock .assert_called_with ('my-new-bucket' )
Original file line number Diff line number Diff line change 1
1
# Environment variables for system tests.
2
2
export GCLOUD_PROJECT=your-project-id
3
3
export CLOUD_STORAGE_BUCKET=$GCLOUD_PROJECT
4
+ export API_KEY=
4
5
export BIGTABLE_CLUSTER=bigtable-test
5
6
export BIGTABLE_ZONE=us-central1-c
6
7
Original file line number Diff line number Diff line change @@ -27,16 +27,15 @@ def run_quickstart():
27
27
translate_client = translate .Client (api_key )
28
28
29
29
# The text to translate
30
- text = 'Hello, world!'
30
+ text = u 'Hello, world!'
31
31
# The target language
32
32
target = 'ru'
33
33
34
34
# Translates some text into Russian
35
35
translation = translate_client .translate (text , target_language = target )
36
36
37
- print ('Text: {}' .format (text ))
38
- print ('Translation: {}' .format (
39
- translation ['translatedText' ].encode ('utf-8' )))
37
+ print (u'Text: {}' .format (text ))
38
+ print (u'Translation: {}' .format (translation ['translatedText' ]))
40
39
# [END translate_quickstart]
41
40
42
41
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2016 Google Inc. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from google .cloud import translate
17
+ import mock
18
+ import pytest
19
+
20
+ import quickstart
21
+
22
+
23
+ @pytest .fixture
24
+ def mock_client (cloud_config ):
25
+ original_client_ctor = translate .Client
26
+
27
+ def new_client_ctor (api_key ):
28
+ # Strip api_key argument and replace with our api key.
29
+ return original_client_ctor (cloud_config .api_key )
30
+
31
+ with mock .patch (
32
+ 'google.cloud.translate.Client' ,
33
+ side_effect = new_client_ctor ):
34
+ yield
35
+
36
+
37
+ def test_quickstart (mock_client , capsys ):
38
+ quickstart .run_quickstart ()
39
+ out , _ = capsys .readouterr ()
40
+ assert u'Привет мир!' in out
Original file line number Diff line number Diff line change 18
18
def run_quickstart ():
19
19
# [START vision_quickstart]
20
20
import io
21
+ import os
21
22
22
23
# Imports the Google Cloud client library
23
24
from google .cloud import vision
@@ -26,11 +27,15 @@ def run_quickstart():
26
27
vision_client = vision .Client ()
27
28
28
29
# 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' )
30
33
31
34
# 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 )
34
39
35
40
# Performs label detection on the image file
36
41
labels = image .detect_labels ()
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments