Fix for texttagging batch support, adding in a few more tests

This commit is contained in:
Madison May
2014-12-20 15:34:07 -05:00
parent 5b1ab380a7
commit aa63a831c6
3 changed files with 33 additions and 3 deletions
+1 -1
View File
@@ -22,4 +22,4 @@ def text_tags(api_root, text, batch=False, auth=None, **kwargs):
:rtype: Dictionary of class probability pairs
"""
return api_handler(text, api_root + "texttags", batch=batch, auth=None, **kwargs)
return api_handler(text, api_root + "texttags", batch=batch, auth=auth, **kwargs)
+3 -2
View File
@@ -26,8 +26,9 @@ def api_handler(arg, url, batch=False, auth=None, **kwargs):
json_data = json.dumps(data)
if batch:
url += "/batch"
if not auth:
auth = auth_query()
# if not auth:
# auth = auth_query()
print auth
response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth).json()
results = response.get('results', False)
if results is False:
+29
View File
@@ -3,11 +3,40 @@ import os
import numpy as np
import skimage.io
from nose.plugins.skip import Skip, SkipTest
from indicoio import political, sentiment, fer, facial_features, language, image_features, text_tags
from indicoio import batch_political, batch_sentiment, batch_fer, batch_facial_features
from indicoio import batch_language, batch_image_features, batch_text_tags
DIR = os.path.dirname(os.path.realpath(__file__))
class BatchAPIRun(unittest.TestCase):
def setUp(self):
self.username = os.getenv("INDICO_USERNAME")
self.password = os.getenv("INDICO_PASSWORD")
self.auth = (self.username, self.password)
if not self.username or not self.password:
raise SkipTest
def test_batch_texttags(self):
test_data = ["On Monday, president Barack Obama will be..."]
response = batch_text_tags(test_data, auth=self.auth)
self.assertTrue(isinstance(response, list))
def test_batch_posneg(self):
test_data = ['Worst song ever', 'Best song ever']
response = batch_sentiment(test_data, auth=self.auth)
self.assertTrue(isinstance(response, list))
self.assertTrue(response[0] < 0.5)
def test_batch_political(self):
test_data = ["Guns don't kill people, people kill people."]
response = batch_political(test_data, auth=self.auth)
self.assertTrue(isinstance(response, list))
class FullAPIRun(unittest.TestCase):