-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vision: Add gRPC support for safe search. #2938
Merged
daspecster
merged 1 commit into
googleapis:master
from
daspecster:vision-add-safe-search-from-pb
Jan 23, 2017
+155
−54
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright 2016 Google Inc. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
# | ||
# 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 unittest | ||
|
||
|
||
class TestSafeSearchAnnotation(unittest.TestCase): | ||
@staticmethod | ||
def _get_target_class(): | ||
from google.cloud.vision.safe_search import SafeSearchAnnotation | ||
return SafeSearchAnnotation | ||
|
||
def test_safe_search_annotation(self): | ||
from google.cloud.vision.likelihood import Likelihood | ||
from unit_tests._fixtures import SAFE_SEARCH_DETECTION_RESPONSE | ||
|
||
response = SAFE_SEARCH_DETECTION_RESPONSE['responses'][0] | ||
safe_search_response = response['safeSearchAnnotation'] | ||
|
||
safe_search = self._get_target_class().from_api_repr( | ||
safe_search_response) | ||
|
||
self.assertIs(safe_search.adult, Likelihood.VERY_UNLIKELY) | ||
self.assertIs(safe_search.spoof, Likelihood.UNLIKELY) | ||
self.assertIs(safe_search.medical, Likelihood.POSSIBLE) | ||
self.assertIs(safe_search.violence, Likelihood.VERY_UNLIKELY) | ||
|
||
def test_pb_safe_search_annotation(self): | ||
from google.cloud.vision.likelihood import Likelihood | ||
from google.cloud.grpc.vision.v1.image_annotator_pb2 import ( | ||
Likelihood as LikelihoodPB) | ||
from google.cloud.grpc.vision.v1 import image_annotator_pb2 | ||
|
||
possible = LikelihoodPB.Value('POSSIBLE') | ||
possible_name = Likelihood.POSSIBLE | ||
safe_search_annotation = image_annotator_pb2.SafeSearchAnnotation( | ||
adult=possible, spoof=possible, medical=possible, violence=possible | ||
) | ||
|
||
safe_search = self._get_target_class().from_pb(safe_search_annotation) | ||
|
||
self.assertIs(safe_search.adult, possible_name) | ||
self.assertIs(safe_search.spoof, possible_name) | ||
self.assertIs(safe_search.medical, possible_name) | ||
self.assertIs(safe_search.violence, possible_name) | ||
|
||
def test_empty_pb_safe_search_annotation(self): | ||
from google.cloud.vision.likelihood import Likelihood | ||
from google.cloud.grpc.vision.v1 import image_annotator_pb2 | ||
|
||
unknown = Likelihood.UNKNOWN | ||
safe_search_annotation = image_annotator_pb2.SafeSearchAnnotation() | ||
|
||
safe_search = self._get_target_class().from_pb(safe_search_annotation) | ||
|
||
self.assertIs(safe_search.adult, unknown) | ||
self.assertIs(safe_search.spoof, unknown) | ||
self.assertIs(safe_search.medical, unknown) | ||
self.assertIs(safe_search.violence, unknown) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.