gradio/test/test_process_examples.py

31 lines
888 B
Python
Raw Normal View History

2022-01-26 14:05:50 +08:00
import os
import unittest
from gradio import Interface, process_examples
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
2022-03-26 02:14:28 +08:00
class TestProcessExamples(unittest.TestCase):
def test_process_example(self):
io = Interface(lambda x: "Hello " + x, "text", "text", examples=[["World"]])
prediction = process_examples.process_example(io, 0)
2022-03-26 02:14:28 +08:00
self.assertEquals(prediction[0], "Hello World")
2022-01-26 14:05:50 +08:00
2022-03-26 02:14:28 +08:00
def test_caching(self):
io = Interface(
lambda x: "Hello " + x,
"text",
"text",
examples=[["World"], ["Dunya"], ["Monde"]],
)
io.launch(prevent_thread_lock=True)
process_examples.cache_interface_examples(io)
prediction = process_examples.load_from_cache(io, 1)
io.close()
self.assertEquals(prediction[0], "Hello Dunya")
2022-01-26 14:05:50 +08:00
if __name__ == "__main__":
unittest.main()