mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +08:00
Initial test coverage for new configuration system
This commit is contained in:
committed by
Madison May
parent
6b9251f4f5
commit
dc47fe5b0a
@@ -1,5 +1,6 @@
|
||||
import unittest
|
||||
import os
|
||||
from requests import ConnectionError
|
||||
|
||||
import numpy as np
|
||||
import skimage.io
|
||||
@@ -49,7 +50,7 @@ class BatchAPIRun(unittest.TestCase):
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(isinstance(response[0], list))
|
||||
self.assertEqual(len(response[0]), 48)
|
||||
|
||||
|
||||
def test_batch_image_features_greyscale(self):
|
||||
test_data = [np.random.rand(64, 64).tolist()]
|
||||
response = batch_image_features(test_data, auth=self.auth)
|
||||
@@ -63,13 +64,21 @@ class BatchAPIRun(unittest.TestCase):
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(isinstance(response[0], list))
|
||||
self.assertEqual(len(response[0]), 2048)
|
||||
|
||||
|
||||
def test_batch_language(self):
|
||||
test_data = ['clearly an english sentence']
|
||||
response = batch_language(test_data, auth=self.auth)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(response[0]['English'] > 0.25)
|
||||
|
||||
def test_batch_set_url_root(self):
|
||||
test_data = ['clearly an english sentence']
|
||||
self.assertRaises(ConnectionError,
|
||||
batch_language,
|
||||
test_data,
|
||||
auth=self.auth,
|
||||
url_root='http://not.a.real.url/')
|
||||
|
||||
|
||||
class FullAPIRun(unittest.TestCase):
|
||||
|
||||
@@ -156,7 +165,7 @@ class FullAPIRun(unittest.TestCase):
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertEqual(len(response), 48)
|
||||
self.check_range(response)
|
||||
|
||||
|
||||
def test_good_image_features_greyscale(self):
|
||||
test_image = np.random.rand(64, 64).tolist()
|
||||
response = image_features(test_image)
|
||||
@@ -214,6 +223,13 @@ class FullAPIRun(unittest.TestCase):
|
||||
self.assertEqual(language_set, set(language_dict.keys()))
|
||||
assert language_dict['English'] > 0.25
|
||||
|
||||
def test_set_url_root(self):
|
||||
test_data = 'clearly an english sentence'
|
||||
self.assertRaises(ConnectionError,
|
||||
language,
|
||||
test_data,
|
||||
url_root='http://not.a.real.url/')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
from indicoio import config
|
||||
|
||||
def test_batch_set_url_root_as_env_var():
|
||||
test_data = ['clearly an english sentence']
|
||||
old_private_cloud_url = os.environ.get("INDICO_PRIVATE_CLOUD_URL")
|
||||
os.environ["INDICO_PRIVATE_CLOUD_URL"] = "http://not.a.real.url/"
|
||||
|
||||
assert config.get_api_root() == "http://not.a.real.url/"
|
||||
|
||||
if old_private_cloud_url:
|
||||
os.environ["INDICO_PRIVATE_CLOUD_URL"] = old_private_cloud_url
|
||||
else:
|
||||
del(os.environ["INDICO_PRIVATE_CLOUD_URL"])
|
||||
Reference in New Issue
Block a user