Skip to content

Commit

Permalink
Added system tests and Entity Response tests.
Browse files Browse the repository at this point in the history
Still need explicit SyntaxResponse and SentimentResponse tests.
  • Loading branch information
Luke Sneeringer committed Feb 23, 2017
1 parent c0448da commit 1c6db0d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
57 changes: 57 additions & 0 deletions language/unit_tests/test_api_responses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2016 Google Inc.

This comment has been minimized.

Copy link
@dhermes

dhermes Feb 23, 2017

Contributor

2017

#
# 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')
5 changes: 3 additions & 2 deletions system_tests/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def _check_analyze_entities_result(self, entities):

def test_analyze_entities(self):
document = Config.CLIENT.document_from_text(self.TEXT_CONTENT)
entities = document.analyze_entities().entities
self._check_analyze_entities_result(entities)
response = document.analyze_entities()
self.assertEqual(response.language, 'en')
self._check_analyze_entities_result(response.entities)

def test_analyze_entities_from_blob(self):
# Upload the text to a blob.
Expand Down

0 comments on commit 1c6db0d

Please sign in to comment.