-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added system tests and Entity Response tests.
Still need explicit SyntaxResponse and SentimentResponse tests.
- Loading branch information
Luke Sneeringer
committed
Feb 23, 2017
1 parent
c0448da
commit 1c6db0d
Showing
2 changed files
with
60 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2016 Google Inc. | ||
This comment has been minimized.
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 TestEntityResponse(unittest.TestCase): | ||
ENTITY_DICT = { | ||
'mentions': [{'text': {'content': 'Italian'}}], | ||
'metadata': {'wikipedia_url': 'http://en.wikipedia.org/wiki/Italy'}, | ||
'name': 'Italian', | ||
'salience': 0.15, | ||
'type': 'LOCATION', | ||
} | ||
|
||
def test_constructor(self): | ||
from google.cloud.language.api_responses import EntityResponse | ||
from google.cloud.language.entity import Entity | ||
|
||
entity_response = EntityResponse( | ||
entities=[Entity.from_api_repr(self.ENTITY_DICT)], | ||
language='en', | ||
) | ||
self._verify_entity_response(entity_response) | ||
|
||
def test_api_repr_factory(self): | ||
from google.cloud.language.api_responses import EntityResponse | ||
|
||
entity_response = EntityResponse.from_api_repr({ | ||
'entities': [self.ENTITY_DICT], | ||
'language': 'en', | ||
}) | ||
self._verify_entity_response(entity_response) | ||
|
||
def _verify_entity_response(self, entity_response): | ||
from google.cloud.language.entity import EntityType | ||
|
||
self.assertEqual(len(entity_response.entities), 1) | ||
entity = entity_response.entities[0] | ||
self.assertEqual(entity.name, 'Italian') | ||
self.assertEqual(len(entity.mentions), 1) | ||
self.assertEqual(entity.mentions[0], 'Italian') | ||
self.assertTrue(entity.metadata['wikipedia_url'].endswith('Italy')) | ||
self.assertAlmostEqual(entity.salience, 0.15) | ||
self.assertEqual(entity.entity_type, EntityType.LOCATION) | ||
self.assertEqual(entity_response.language, 'en') |
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
2017