2019-02-28 08:43:20 +08:00
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
from gradio import inputs
|
|
|
|
|
|
|
|
BASE64_IMG = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wgARCADIAMgDASIAAhEBAxEB/8QAHAAAAQUBAQEAAAAAAAAAAAAABQACAwQGBwEI/8QAGgEAAwEBAQEAAAAAAAAAAAAAAQIDBAAFBv/aAAwDAQACEAMQAAAB09a1OqDQ98RNiD50j1JoWICkgVvMXUcqCNvqPJeNIQ++Pr0KuXmGfJPfPrQvUA6AQpUg3Y6OqBCz2SJZ7N5Zm+SPp0Escx6s70WQRK41/dsKw2yVmDkAUiVmgur0womMbrYuzSqrUxSYuMvBGByxWsSerPHXBJz0n2aZ9bZMc8C3cKvk3alA87zHa8Y84KNW2JzFKJlKV/S8LvkZSYpc70xBb1K88NddNM7i2kEpht+eWSLVZsMlNmsWaSpmvjLxGiHz01bl10e/Tl6IaFl3kUC2IVtWyW9wCJOqyAukhJrPR7/GHrftey1JfYIqcsz0gOpyxw2wPzIwXeDOpcwoxEUd7Rn6cWpvpH2KKdNA/Nkxxz2kLStNpc5pM95JLUnAfa8usaflqiwJ5keBTT0Gnnx3NptDzyUd0jOvyQnZNS31sUhtxb/JF21YlTMiSNEKKU6cm9KF0OTVIvYxK3XdHZYxRd3NjrwXRi5qvk5zRwq1kk4uOD6V82vkgs5wfhmh9LNWkjizPmXtuHqCDKnbsyNI47vv86o7cvSPMdRou0pi6C9eEKston5CGdjQuMv3P2Lz03yZPG622LXVq3tx6+KWfZWdliNMYrCr2/H6QNE4+PXM1wAacdIGNi4iRXB9Pym6W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YqIGW5hXryuXfW8UEYx4hfAJzecsLknvcBn1A/nnv7n5HiPosfO1H+pOdYu7QfPThqmTrPqKz9hn/F9mOE/Zji+i739uv8Amau248ON+7/4fTcf9X/OoSdqo42OGRLwSVwiW5zPOv2kOyPAw/YeWdtn7dacPPRPr9j+0/8Ah9Nj/wAWdek0j5TXnbPx9SWO3BgOO2gg19icJxjnwv2//8QAIxEAAgICAwABBQEAAAAAAAAAAAECEQMQEiExQQQTIjJRIP/aAAgBAwEBPwGP7El2cKRxsrVnIstCHO+tL2yy+jkyT09LwXpQtqBwoUBoWpR+RCoi4y6Jx4vUPR5Bv8bObs9EmWVZ4y+7MPyyU+WsaOBVqj7VkFXRb+CjteFN9jkY58kxagvxs5jdIU3YuhRY3fTJdIVQgSMbpPbfwUes6TIytEYR/pKaRycnZKblqHW5DySZcjjL+mGXVCkynIyLhAUqLExanks530WXZgffZGiUlBGTLyLE0xRtC81ZY5nJsx+EFkroycr/ACJeaaojmkiGSMlQ2iUUlbOWoiXR9K24NGVuUif8/wAcRNoy+D1FEVbURYlCNIm+9e6SK1m+CfusZ9N3kRm/Vk9fAhC1/8QAJBEAAgIBBAIDAQEBAAAAAAAAAAECEQMSITFBECIEMlETFGH/2gAIAQIBAT8Bl9CMtiWQTdml9FvsXAsdiVFdj/6NJKyjJk9KIy/Ta6FGhcGixY6Konuy+jkklXjSmh0iL7ExD8KXQ4dn87dsaobdCs1dGhMUN6FBV4tFF0XaOif4ONCJCnsQka6Gylz45e5aWxGJKNE2JGRCikiKR0cjN1uR9mTfZDgyy0tDle4ib3NRxHYSZWljZV8FKKHNSdCPkK5IoR9p7kcUInokPJFbUZP0aR
|
|
|
|
RAND_STRING = "2wBDAAYEBQYFBAYGBQYHBwYIC"
|
|
|
|
PACKAGE_NAME = 'gradio'
|
|
|
|
|
|
|
|
|
|
|
|
class TestSketchpad(unittest.TestCase):
|
2019-06-19 04:13:50 +08:00
|
|
|
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)))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
def test_preprocessing(self):
|
|
|
|
inp = inputs.Sketchpad()
|
2019-02-28 13:39:18 +08:00
|
|
|
array = inp.preprocess(BASE64_IMG)
|
2019-03-10 10:05:30 +08:00
|
|
|
self.assertEqual(array.shape, (1, 28, 28))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TestWebcam(unittest.TestCase):
|
|
|
|
def test_path_exists(self):
|
|
|
|
inp = inputs.Webcam()
|
2019-06-19 04:13:50 +08:00
|
|
|
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
|
2019-03-18 20:24:25 +08:00
|
|
|
self.assertFalse(os.path.exists(os.path.join(PACKAGE_NAME, path))) # Note implemented yet.
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
def test_preprocessing(self):
|
|
|
|
inp = inputs.Webcam()
|
2019-02-28 13:39:18 +08:00
|
|
|
array = inp.preprocess(BASE64_IMG)
|
2019-03-06 14:51:36 +08:00
|
|
|
self.assertEqual(array.shape, (1, 224, 224, 3))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TestTextbox(unittest.TestCase):
|
2019-06-19 04:13:50 +08:00
|
|
|
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)))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
def test_preprocessing(self):
|
|
|
|
inp = inputs.Textbox()
|
2019-02-28 13:39:18 +08:00
|
|
|
string = inp.preprocess(RAND_STRING)
|
2019-02-28 08:43:20 +08:00
|
|
|
self.assertEqual(string, RAND_STRING)
|
|
|
|
|
|
|
|
|
|
|
|
class TestImageUpload(unittest.TestCase):
|
2019-06-19 04:13:50 +08:00
|
|
|
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)))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
def test_preprocessing(self):
|
|
|
|
inp = inputs.ImageUpload()
|
2019-02-28 13:39:18 +08:00
|
|
|
array = inp.preprocess(BASE64_IMG)
|
2019-03-06 14:51:36 +08:00
|
|
|
self.assertEqual(array.shape, (1, 224, 224, 3))
|
|
|
|
|
2019-06-19 04:13:50 +08:00
|
|
|
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))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-06-19 04:13:50 +08:00
|
|
|
unittest.main()
|