Merge pull request #3 from gradio-app/dawoodkhan82/unit-tests-fix

Fix unit tests
This commit is contained in:
Abubakar Abid 2019-06-21 01:16:16 -07:00 committed by GitHub
commit 9e617c3df4
7 changed files with 70 additions and 71 deletions

View File

@ -26,4 +26,4 @@ jobs:
path: test-reports/
destination: tr1
- store_test_results:
path: test-reports/
path: test-reports/

View File

@ -13,7 +13,7 @@ import warnings
import json
# Where to find the static resources associated with each template.
BASE_INPUT_INTERFACE_TEMPLATE_PATH = 'templates/input/{}.html'
# BASE_INPUT_INTERFACE_TEMPLATE_PATH = 'static/js/interfaces/input/{}.js'
BASE_INPUT_INTERFACE_JS_PATH = 'static/js/interfaces/input/{}.js'

View File

@ -11,7 +11,6 @@ from gradio import imagenet_class_labels, preprocessing_utils
import datetime
# Where to find the static resources associated with each template.
BASE_OUTPUT_INTERFACE_TEMPLATE_PATH = 'templates/output/{}.html'
BASE_OUTPUT_INTERFACE_JS_PATH = 'static/js/interfaces/output/{}.js'

View File

@ -8,10 +8,10 @@ PACKAGE_NAME = 'gradio'
class TestSketchpad(unittest.TestCase):
# def test_path_exists(self):
# inp = inputs.Sketchpad()
# path = inputs.BASE_INPUT_INTERFACE_TEMPLATE_PATH.format(inp.get_name())
# self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_path_exists(self):
inp = inputs.Sketchpad()
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_preprocessing(self):
inp = inputs.Sketchpad()
@ -22,7 +22,7 @@ class TestSketchpad(unittest.TestCase):
class TestWebcam(unittest.TestCase):
def test_path_exists(self):
inp = inputs.Webcam()
path = inputs.BASE_INPUT_INTERFACE_TEMPLATE_PATH.format(inp.get_name())
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
self.assertFalse(os.path.exists(os.path.join(PACKAGE_NAME, path))) # Note implemented yet.
def test_preprocessing(self):
@ -32,10 +32,10 @@ class TestWebcam(unittest.TestCase):
class TestTextbox(unittest.TestCase):
# def test_path_exists(self):
# inp = inputs.Textbox()
# path = inputs.BASE_INPUT_INTERFACE_TEMPLATE_PATH.format(inp.get_name())
# self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_path_exists(self):
inp = inputs.Textbox()
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_preprocessing(self):
inp = inputs.Textbox()
@ -44,21 +44,22 @@ class TestTextbox(unittest.TestCase):
class TestImageUpload(unittest.TestCase):
# def test_path_exists(self):
# inp = inputs.ImageUpload()
# path = inputs.BASE_INPUT_INTERFACE_TEMPLATE_PATH.format(inp.get_name())
# self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_path_exists(self):
inp = inputs.ImageUpload()
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_preprocessing(self):
inp = inputs.ImageUpload()
array = inp.preprocess(BASE64_IMG)
self.assertEqual(array.shape, (1, 224, 224, 3))
# def test_preprocessing(self):
# inp = inputs.ImageUpload(image_height=48, image_width=48)
# array = inp.preprocess(BASE64_IMG)
# self.assertEqual(array.shape, (1, 48, 48, 3))
def test_preprocessing(self):
inp = inputs.ImageUpload()
inp.image_height = 48
inp.image_width = 48
array = inp.preprocess(BASE64_IMG)
self.assertEqual(array.shape, (1, 48, 48, 3))
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@ -21,25 +21,25 @@ class TestInterface(unittest.TestCase):
io = Interface(inputs='SketCHPad', outputs=out, model=lambda x: x, model_type='function')
self.assertEqual(io.output_interface, out)
# def test_keras_model(self):
# try:
# import tensorflow as tf
# except:
# raise unittest.SkipTest("Need tensorflow installed to do keras-based tests")
# inputs = tf.keras.Input(shape=(3,))
# x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
# outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
# model = tf.keras.Model(inputs=inputs, outputs=outputs)
# io = Interface(inputs='SketCHPad', outputs='textBOX', model=model, model_type='keras')
# pred = io.predict(np.ones(shape=(1, 3), ))
# self.assertEqual(pred.shape, (1, 5))
def test_keras_model(self):
try:
import tensorflow as tf
except:
raise unittest.SkipTest("Need tensorflow installed to do keras-based tests")
inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
io = Interface(inputs='SketCHPad', outputs='textBOX', model=model, model_type='keras')
pred = io.predict(np.ones(shape=(1, 3), ))
self.assertEqual(pred.shape, (1, 5))
# def test_func_model(self):
# def model(x):
# return 2*x
# io = Interface(inputs='SketCHPad', outputs='textBOX', model=model, model_type='function')
# pred = io.predict(np.ones(shape=(1, 3)))
# self.assertEqual(pred.shape, (1, 3))
def test_func_model(self):
def model(x):
return 2*x
io = Interface(inputs='SketCHPad', outputs='textBOX', model=model, model_type='pyfunc')
pred = io.predict(np.ones(shape=(1, 3)))
self.assertEqual(pred.shape, (1, 3))
def test_pytorch_model(self):
try:
@ -65,4 +65,4 @@ class TestInterface(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@ -27,18 +27,17 @@ class TestGetAvailablePort(unittest.TestCase):
s.close()
self.assertFalse(port==new_port)
# class TestCopyFiles(unittest.TestCase):
# def test_copy_files(self):
# filename = "a.txt"
# with tempfile.TemporaryDirectory() as temp_src:
# with open(os.path.join(temp_src, "a.txt"), "w+") as f:
# f.write('Hi')
# with tempfile.TemporaryDirectory() as temp_dest:
# self.assertFalse(os.path.exists(os.path.join(temp_dest, filename)))
# networking.copy_files(temp_src, temp_dest)
# self.assertTrue(os.path.exists(os.path.join(temp_dest, filename)))
# def test_copy_files(self):
# filename = "a.txt"
# with tempfile.TemporaryDirectory() as temp_src:
# with open(os.path.join(temp_src, "a.txt"), "w+") as f:
# f.write('Hi')
# with tempfile.TemporaryDirectory() as temp_dest:
# self.assertFalse(os.path.exists(os.path.join(temp_dest, filename)))
# networking.copy_files(temp_src, temp_dest)
# self.assertTrue(os.path.exists(os.path.join(temp_dest, filename)))
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@ -9,10 +9,10 @@ BASE64_IMG = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAY
class TestLabel(unittest.TestCase):
# def test_path_exists(self):
# out = outputs.Label()
# path = outputs.BASE_OUTPUT_INTERFACE_TEMPLATE_PATH.format(out.get_name())
# self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_path_exists(self):
out = outputs.Label()
path = outputs.BASE_OUTPUT_INTERFACE_JS_PATH.format(out.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_postprocessing_string(self):
string = 'happy'
@ -39,19 +39,19 @@ class TestLabel(unittest.TestCase):
label = json.loads(out.postprocess(array))
self.assertDictEqual(label, true_label)
# def test_postprocessing_int(self):
# true_label_array = np.array([[[3]]])
# true_label = {outputs.Label.LABEL_KEY: 3}
# out = outputs.Label()
# label = json.loads(out.postprocess(true_label_array))
# self.assertDictEqual(label, true_label)
def test_postprocessing_int(self):
true_label_array = np.array([[[3]]])
true_label = {outputs.Label.LABEL_KEY: 3}
out = outputs.Label()
label = json.loads(out.postprocess(true_label_array))
self.assertDictEqual(label, true_label)
# class TestTextbox(unittest.TestCase):
# def test_path_exists(self):
# out = outputs.Textbox()
# path = outputs.BASE_OUTPUT_INTERFACE_TEMPLATE_PATH.format(out.get_name())
# self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
class TestTextbox(unittest.TestCase):
def test_path_exists(self):
out = outputs.Textbox()
path = outputs.BASE_OUTPUT_INTERFACE_JS_PATH.format(out.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_postprocessing(self):
string = 'happy'
@ -61,10 +61,10 @@ class TestLabel(unittest.TestCase):
class TestImage(unittest.TestCase):
# def test_path_exists(self):
# out = outputs.Image()
# path = outputs.BASE_OUTPUT_INTERFACE_TEMPLATE_PATH.format(out.get_name())
# self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_path_exists(self):
out = outputs.Image()
path = outputs.BASE_OUTPUT_INTERFACE_JS_PATH.format(out.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_postprocessing(self):
string = BASE64_IMG