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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gPCNw7m6URC+6lKGwx0IIHwdYEW6FOGLlO14sSJ88XLeKmKErxUmLqqUAMJXaeKGdhvhG5ow/U9JAOGbkn7BYyN8BScH15IIeN/zV5N6kPj9SARYqjmJLTUz+JVK4CmJ52b8RNLNU53AvkwCCF+ZecGrdAKp55r4lDWftkabIQGEb4ZJJaSrCZwmaccEFh+TtFOCPaYFE0D4Ck4OriURuETSRgk9+JS2zyfYY1owAYSv4OTgWm8C20r6Ym/rawxvLOnKxD4wL5QAwldoYnAriYDPxPWxm33bFyQ9sK8xduUTQPjKzxEedifwT5Ke293sWosjmzNQErrAtGQCCF/J2cG3vgTOkrRNX2NJT5P0zgR7TAsngPAVniDc60xgA0leg3f9zpa/NfCxlOcl2GNaOAGEr/AE4V5nAttL8sHrfdtlkm7V1xi7OgggfHXkCS/bEzhA0mvaX36dK0+W9OgEe0wrIIDwVZAkXOxE4BhJe3ayWPfiV0p6eYI9phUQQPgqSBIudiJwvqS7drJY9+LdJR2XYI9pBQQQvgqShIutCdxa0sWtr17+QovmNxP7wLxwAghf4QnCvU4E/G7uo50s1r34W5LukmCPaSUEEL5KEoWbrQicIGnXVlcuf9GxkvZIsMe0EgIIXyWJws1WBH4oaeNWVy5/0UGSDkuwx7QSAghfJYnCzTUJ
|
2019-02-28 08:43:20 +08:00
|
|
|
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()
|
2020-07-02 08:34:51 +08:00
|
|
|
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.__class__.__name__.lower())
|
2019-06-20 03:03:54 +08:00
|
|
|
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-07-22 09:46:00 +08:00
|
|
|
array = inp.preprocess(BASE64_SKETCH)
|
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()
|
2020-07-02 08:34:51 +08:00
|
|
|
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.__class__.__name__.lower())
|
2020-06-12 03:31:44 +08:00
|
|
|
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.Webcam()
|
2019-02-28 13:39:18 +08:00
|
|
|
array = inp.preprocess(BASE64_IMG)
|
2020-06-12 03:31:44 +08:00
|
|
|
self.assertEqual(array.shape, (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()
|
2020-07-02 08:34:51 +08:00
|
|
|
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(
|
|
|
|
inp.__class__.__name__.lower())
|
2019-06-20 03:03:54 +08:00
|
|
|
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):
|
2020-07-01 07:11:35 +08:00
|
|
|
inp = inputs.Image()
|
2020-07-02 08:34:51 +08:00
|
|
|
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.__class__.__name__.lower())
|
2019-06-20 03:03:54 +08:00
|
|
|
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
def test_preprocessing(self):
|
2020-07-01 07:11:35 +08:00
|
|
|
inp = inputs.Image()
|
2019-02-28 13:39:18 +08:00
|
|
|
array = inp.preprocess(BASE64_IMG)
|
2020-06-12 03:31:44 +08:00
|
|
|
self.assertEqual(array.shape, (224, 224, 3))
|
2019-03-06 14:51:36 +08:00
|
|
|
|
2019-06-19 04:13:50 +08:00
|
|
|
def test_preprocessing(self):
|
2020-07-01 07:11:35 +08:00
|
|
|
inp = inputs.Image()
|
2019-06-19 04:13:50 +08:00
|
|
|
inp.image_height = 48
|
|
|
|
inp.image_width = 48
|
|
|
|
array = inp.preprocess(BASE64_IMG)
|
2020-06-12 03:31:44 +08:00
|
|
|
self.assertEqual(array.shape, (48, 48, 3))
|
2019-02-28 08:43:20 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-06-19 04:13:50 +08:00
|
|
|
unittest.main()
|