Updated tests for image apis

This commit is contained in:
Madison May
2014-10-29 17:51:50 -04:00
parent bb9bef2cc3
commit fa3ea8959a
3 changed files with 29 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

+29
View File
@@ -1,12 +1,21 @@
import unittest
import os
import numpy as np
import skimage.io
from indicoio import political, sentiment, fer, facial_features, language, image_features
DIR = os.path.dirname(os.path.realpath(__file__))
class FullAPIRun(unittest.TestCase):
def load_image(self, relpath, as_grey=False):
image_path = os.path.normpath(os.path.join(DIR, relpath))
image = skimage.io.imread(image_path, as_grey=True).tolist()
return image
def test_political(self):
political_set = set(['Libertarian', 'Liberal', 'Conservative', 'Green'])
test_string = "Guns don't kill people, people kill people."
@@ -41,6 +50,18 @@ class FullAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, dict))
self.assertEqual(fer_set, set(response.keys()))
def test_happy_fer(self):
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)
response = fer(test_face)
self.assertTrue(isinstance(response, dict))
self.assertTrue(response['Fear'] > 0.25)
def test_bad_fer(self):
fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy'])
test_face = np.random.rand(56,56).tolist()
@@ -55,6 +76,9 @@ class FullAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list))
self.assertEqual(len(response), 48)
self.assertTrue(np.asarray(response).max() > 0.1)
self.assertTrue(np.asarray(response).min() < 0.9)
self.assertTrue(np.ptp(np.asarray(response)) > 0.5)
def test_good_image_features_greyscale(self):
test_image = np.random.rand(64, 64).tolist()
@@ -62,6 +86,8 @@ class FullAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list))
self.assertEqual(len(response), 2048)
self.assertTrue(np.asarray(response).max() > 0.1)
self.assertTrue(np.asarray(response).min() < 0.9)
def test_good_image_features_rgb(self):
test_image = np.random.rand(64, 64, 3).tolist()
@@ -69,6 +95,9 @@ class FullAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list))
self.assertEqual(len(response), 2048)
self.assertTrue(np.asarray(response).max() > 0.1)
self.assertTrue(np.asarray(response).min() < 0.9)
self.assertTrue(np.ptp(np.asarray(response)) > 0.5)
def test_language(self):
language_set = set([