From af23af67022c33f34542021650392c0c5c7cfeaa Mon Sep 17 00:00:00 2001 From: Slater-Victoroff Date: Mon, 5 May 2014 00:22:48 -0400 Subject: [PATCH] General tests working --- IndicoIo/__init__.py | 36 ------------------------------------ IndicoIo/conf.py | 1 - IndicoIo/text/sentiment.py | 2 +- tests/__init__.py | 0 tests/test_run.py | 31 +++++++++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 IndicoIo/conf.py create mode 100644 tests/__init__.py create mode 100644 tests/test_run.py diff --git a/IndicoIo/__init__.py b/IndicoIo/__init__.py index 1b39500..e69de29 100644 --- a/IndicoIo/__init__.py +++ b/IndicoIo/__init__.py @@ -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)) diff --git a/IndicoIo/conf.py b/IndicoIo/conf.py deleted file mode 100644 index da9f382..0000000 --- a/IndicoIo/conf.py +++ /dev/null @@ -1 +0,0 @@ -active_modules = ["text", "images"] diff --git a/IndicoIo/text/sentiment.py b/IndicoIo/text/sentiment.py index 899fd8e..d4af89d 100644 --- a/IndicoIo/text/sentiment.py +++ b/IndicoIo/text/sentiment.py @@ -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) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_run.py b/tests/test_run.py new file mode 100644 index 0000000..506faae --- /dev/null +++ b/tests/test_run.py @@ -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()