From 50a8ef6bf67d09f403e6d77b87484c58e68c48b6 Mon Sep 17 00:00:00 2001 From: Madison May Date: Fri, 7 Nov 2014 17:18:59 -0500 Subject: [PATCH] Updates to test suite for text tags --- tests/local/test_local.py | 22 +++++++++++++++++----- tests/remote/test_remote.py | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/tests/local/test_local.py b/tests/local/test_local.py index 4f5748c..48cc0f5 100644 --- a/tests/local/test_local.py +++ b/tests/local/test_local.py @@ -2,7 +2,7 @@ import unittest import numpy as np -from indicoio.local import political, sentiment, fer, facial_features, language, image_features +from indicoio.local import political, sentiment, fer, facial_features, language, image_features, text_tags DIR = os.path.dirname(os.path.realpath(__file__)) @@ -20,11 +20,23 @@ class FullAPIRun(unittest.TestCase): self.assertTrue(vector.min() < minimum) self.assertTrue(np.ptp(vector) > span) - def test_document_classification(self): - categories = set(['arts']) + def test_text_tags(self): + expected_keys = set(['fashion', 'art', 'energy', 'economics', 'entreprener', + 'books', 'politics', 'gardening', 'nba', 'conservative', + 'technology', 'startps', 'relationships', 'edcation', + 'hmor', 'psychology', 'bicycling', 'investing', 'travel', + 'cooking', 'christianity', 'environment', 'religion', 'health', + 'hockey', 'pets', 'msic', 'soccer', 'gns', 'gaming', 'jobs', + 'bsiness', 'natre', 'food', 'cars', 'photography', 'philosophy', + 'geek', 'sports', 'baseball', 'news', 'television', 'entertainment', + 'parenting', 'comics', 'science', 'nfl','programming', + 'personalfinance', 'atheism', 'movies', 'anime', 'fitness', + 'military', 'realestate', 'history']) text = "On Monday, president Barack Obama will be..." - results = classification(text) - self.assertTrue(categories < set(results.keys())) + results = text_tags(text) + max_keys = sorted(results.keys(), key=lambda x:results.get(x), reverse=True) + assert 'politics' in max_keys[:3] + self.assertTrue(expected_keys == set(results.keys())) def test_political(self): political_set = set(['Libertarian', 'Liberal', 'Conservative', 'Green']) diff --git a/tests/remote/test_remote.py b/tests/remote/test_remote.py index 8b6e9d3..1477822 100644 --- a/tests/remote/test_remote.py +++ b/tests/remote/test_remote.py @@ -4,7 +4,7 @@ import os import numpy as np import skimage.io -from indicoio import political, sentiment, fer, facial_features, language, image_features, classification +from indicoio import political, sentiment, fer, facial_features, language, image_features, text_tags DIR = os.path.dirname(os.path.realpath(__file__)) @@ -22,11 +22,23 @@ class FullAPIRun(unittest.TestCase): self.assertTrue(vector.min() < minimum) self.assertTrue(np.ptp(vector) > span) - def test_document_classification(self): - categories = set(['arts']) + def test_text_tags(self): + expected_keys = set(['fashion', 'art', 'energy', 'economics', 'entrepreneur', + 'books', 'politics', 'gardening', 'nba', 'conservative', + 'technology', 'startups', 'relationships', 'education', + 'humor', 'psychology', 'bicycling', 'investing', 'travel', + 'cooking', 'christianity', 'environment', 'religion', 'health', + 'hockey', 'pets', 'music', 'soccer', 'guns', 'gaming', 'jobs', + 'business', 'nature', 'food', 'cars', 'photography', 'philosophy', + 'geek', 'sports', 'baseball', 'news', 'television', 'entertainment', + 'parenting', 'comics', 'science', 'nfl','programming', + 'personalfinance', 'atheism', 'movies', 'anime', 'fitness', + 'military', 'realestate', 'history']) text = "On Monday, president Barack Obama will be..." - results = classification(text) - self.assertTrue(categories < set(results.keys())) + results = text_tags(text) + max_keys = sorted(results.keys(), key=lambda x:results.get(x), reverse=True) + assert 'politics' in max_keys[:3] + self.assertFalse(set(results.keys()) - expected_keys) def test_political(self): political_set = set(['Libertarian', 'Liberal', 'Conservative', 'Green'])