General tests working

This commit is contained in:
Slater-Victoroff
2014-05-05 00:22:48 -04:00
parent 934424ead5
commit af23af6702
5 changed files with 32 additions and 38 deletions
-36
View File
@@ -1,36 +0,0 @@
import os, pkgutil, imp
import inspect
from config import active_modules
API_KEY = os.environ["INDICO_API_KEY"] or None
API_KEY = open("$HOME/.indico").read() or None
class PostApiKey(object):
def __init__(self, api_key):
self.func = func
self.api_key = api_key
def __call__(self, f):
def use_api_key(cls):
for name, func in inspect.getmembers(cls):
if inspect.ismethod(func) and not inspect.isclass(func.im_self):
setattr(cls, name, PostApiKey(func, cls.API_KEY))
return cls
@use_api_key
class Indico(object):
def __init__(api_key = API_KEY):
self.API_KEY = API_KEY
for module in active_modules:
actual_module = imp.new_module(module)
for _, name, _ in pkgutil.iter_modules([module]):
setattr(self, name, getattr(actual_module, name))
-1
View File
@@ -1 +0,0 @@
active_modules = ["text", "images"]
+1 -1
View File
@@ -14,7 +14,7 @@ def spam(test_text):
response = requests.post(base_url("spam"), data=data_dict, headers=headers)
return json.loads(response.content)
def sentiment(test_text):
def posneg(test_text):
data_dict = json.dumps({'text': test_text})
response = requests.post(base_url("sentiment"), data=data_dict, headers=headers)
return json.loads(response.content)
View File
+31
View File
@@ -0,0 +1,31 @@
import unittest
from IndicoIo.text.sentiment import political, spam, posneg
class FullAPIRun(unittest.TestCase):
def test_political(self):
political_set = set(['Libertarian', 'Liberal', 'Conservative', 'Green'])
test_string = "Guns don't kill people, people kill people."
response = political(test_string)
self.assertTrue(isinstance(response, dict))
self.assertEqual(political_set, set(response.keys()))
def test_spam(self):
spam_set = set(['Spam', 'Ham'])
test_string = "Buy a new car!!"
response = spam(test_string)
self.assertTrue(isinstance(response, dict))
self.assertEqual(spam_set, set(response.keys()))
def test_posneg(self):
posneg_set = set(['Positive', 'Negative'])
test_string = "Worst song ever."
response = posneg(test_string)
self.assertTrue(isinstance(response, dict))
self.assertEqual(posneg_set, set(response.keys()))
if __name__ == "__main__":
unittest.main()