Cleaner api handler interface + extended tests

This commit is contained in:
Madison May
2015-02-27 16:33:22 -05:00
parent 57f91a138b
commit 110abaf7a6
16 changed files with 258 additions and 93 deletions
+9 -10
View File
@@ -6,6 +6,7 @@ import numpy as np
import skimage.io
from nose.plugins.skip import Skip, SkipTest
from indicoio import config
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
@@ -15,11 +16,9 @@ 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)
self.auth = config.auth
if not self.username or not self.password:
if not all(self.auth):
raise SkipTest
def test_batch_texttags(self):
@@ -71,13 +70,13 @@ class BatchAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list))
self.assertTrue(response[0]['English'] > 0.25)
def test_batch_set_url_root(self):
def test_batch_set_cloud(self):
test_data = ['clearly an english sentence']
self.assertRaises(ConnectionError,
batch_language,
test_data,
auth=self.auth,
url_root='http://not.a.real.url/')
cloud='invalid/cloud')
class FullAPIRun(unittest.TestCase):
@@ -139,13 +138,13 @@ class FullAPIRun(unittest.TestCase):
self.assertEqual(fer_set, set(response.keys()))
def test_happy_fer(self):
test_face = self.load_image("../data/happy.png", as_grey=True)
test_face = self.load_image("data/happy.png", as_grey=True)
response = fer(test_face)
self.assertTrue(isinstance(response, dict))
self.assertTrue(response['Happy'] > 0.5)
def test_fear_fer(self):
test_face = self.load_image("../data/fear.png", as_grey=True)
test_face = self.load_image("data/fear.png", as_grey=True)
response = fer(test_face)
self.assertTrue(isinstance(response, dict))
self.assertTrue(response['Fear'] > 0.25)
@@ -223,12 +222,12 @@ class FullAPIRun(unittest.TestCase):
self.assertEqual(language_set, set(language_dict.keys()))
assert language_dict['English'] > 0.25
def test_set_url_root(self):
def test_set_cloud(self):
test_data = 'clearly an english sentence'
self.assertRaises(ConnectionError,
language,
test_data,
url_root='http://not.a.real.url/')
cloud='invalid/cloud')
if __name__ == "__main__":