mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-12 12:40:29 +08:00
blocks-components-tests
- move gradio/test_data to test/test_data/media_data
This commit is contained in:
parent
f623438596
commit
070b8a96b5
@ -17,8 +17,9 @@ import pandas as pd
|
||||
import PIL
|
||||
from ffmpy import FFmpeg
|
||||
from markdown_it import MarkdownIt
|
||||
from test.test_data import media_data
|
||||
|
||||
from gradio import processing_utils, test_data
|
||||
from gradio import processing_utils
|
||||
from gradio.blocks import Block
|
||||
|
||||
|
||||
@ -1068,7 +1069,7 @@ class Image(Component):
|
||||
requires_permissions = source == "webcam"
|
||||
self.tool = tool
|
||||
self.invert_colors = invert_colors
|
||||
self.test_input = test_data.BASE64_IMAGE
|
||||
self.test_input = media_data.BASE64_IMAGE
|
||||
self.interpret_by_tokens = True
|
||||
super().__init__(
|
||||
label=label, requires_permissions=requires_permissions, **kwargs
|
||||
@ -1273,7 +1274,7 @@ class Image(Component):
|
||||
return self.save_flagged_file(dir, label, data, encryption_key)
|
||||
|
||||
def generate_sample(self):
|
||||
return test_data.BASE64_IMAGE
|
||||
return media_data.BASE64_IMAGE
|
||||
|
||||
# Output functions
|
||||
|
||||
@ -1445,7 +1446,7 @@ class Video(Component):
|
||||
)
|
||||
|
||||
def generate_sample(self):
|
||||
return test_data.BASE64_VIDEO
|
||||
return media_data.BASE64_VIDEO
|
||||
|
||||
def postprocess(self, y):
|
||||
"""
|
||||
@ -1555,7 +1556,7 @@ class Audio(Component):
|
||||
requires_permissions = source == "microphone"
|
||||
self.type = type
|
||||
self.output_type = "auto"
|
||||
self.test_input = test_data.BASE64_AUDIO
|
||||
self.test_input = media_data.BASE64_AUDIO
|
||||
self.interpret_by_tokens = True
|
||||
super().__init__(
|
||||
label=label, requires_permissions=requires_permissions, **kwargs
|
||||
@ -1741,7 +1742,7 @@ class Audio(Component):
|
||||
)
|
||||
|
||||
def generate_sample(self):
|
||||
return test_data.BASE64_AUDIO
|
||||
return media_data.BASE64_AUDIO
|
||||
|
||||
def postprocess(self, y):
|
||||
"""
|
||||
@ -1935,7 +1936,7 @@ class File(Component):
|
||||
)
|
||||
|
||||
def generate_sample(self):
|
||||
return test_data.BASE64_FILE
|
||||
return media_data.BASE64_FILE
|
||||
|
||||
# Output Functionalities
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
# To run the tests, simply navigate to the outer directory and run `python -m unittest discover`
|
@ -1,11 +1,7 @@
|
||||
import random
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .test_data.blocks_configs import XRAY_CONFIG # for pytest
|
||||
except ImportError:
|
||||
from test_data.blocks_configs import XRAY_CONFIG # for regular python
|
||||
|
||||
from test.test_data.blocks_configs import XRAY_CONFIG
|
||||
import gradio as gr
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import PIL
|
||||
|
||||
from test.test_data import media_data
|
||||
import gradio as gr
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
@ -412,7 +412,7 @@ class TestDropdown(unittest.TestCase):
|
||||
|
||||
class TestImage(unittest.TestCase):
|
||||
def test_as_component_as_input(self):
|
||||
img = gr.test_data.BASE64_IMAGE
|
||||
img = media_data.BASE64_IMAGE
|
||||
image_input = gr.Image()
|
||||
self.assertEqual(image_input.preprocess(img).shape, (68, 61, 3))
|
||||
image_input = gr.Image(shape=(25, 25), image_mode="L")
|
||||
@ -452,7 +452,7 @@ class TestImage(unittest.TestCase):
|
||||
image_input.preprocess(img)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
file_image = gr.Image(type="file")
|
||||
file_image.preprocess(gr.test_data.BASE64_IMAGE)
|
||||
file_image.preprocess(media_data.BASE64_IMAGE)
|
||||
file_image = gr.Image(type="filepath")
|
||||
self.assertIsInstance(file_image.preprocess(img), str)
|
||||
with self.assertRaises(ValueError):
|
||||
@ -473,7 +473,7 @@ class TestImage(unittest.TestCase):
|
||||
self.assertIsNotNone(image_input._segment_by_slic(img))
|
||||
|
||||
def test_in_interface_as_input(self):
|
||||
img = gr.test_data.BASE64_IMAGE
|
||||
img = media_data.BASE64_IMAGE
|
||||
image_input = gr.Image()
|
||||
iface = gr.Interface(
|
||||
lambda x: PIL.Image.open(x).rotate(90, expand=True),
|
||||
@ -488,10 +488,10 @@ class TestImage(unittest.TestCase):
|
||||
lambda x: np.sum(x), image_input, "number", interpretation="default"
|
||||
)
|
||||
scores, alternative_outputs = iface.interpret([img])
|
||||
self.assertEqual(scores, gr.test_data.SUM_PIXELS_INTERPRETATION["scores"])
|
||||
self.assertEqual(scores, media_data.SUM_PIXELS_INTERPRETATION["scores"])
|
||||
self.assertEqual(
|
||||
alternative_outputs,
|
||||
gr.test_data.SUM_PIXELS_INTERPRETATION["alternative_outputs"],
|
||||
media_data.SUM_PIXELS_INTERPRETATION["alternative_outputs"],
|
||||
)
|
||||
iface = gr.Interface(
|
||||
lambda x: np.sum(x), image_input, "label", interpretation="shap"
|
||||
@ -499,11 +499,11 @@ class TestImage(unittest.TestCase):
|
||||
scores, alternative_outputs = iface.interpret([img])
|
||||
self.assertEqual(
|
||||
len(scores[0]),
|
||||
len(gr.test_data.SUM_PIXELS_SHAP_INTERPRETATION["scores"][0]),
|
||||
len(media_data.SUM_PIXELS_SHAP_INTERPRETATION["scores"][0]),
|
||||
)
|
||||
self.assertEqual(
|
||||
len(alternative_outputs[0]),
|
||||
len(gr.test_data.SUM_PIXELS_SHAP_INTERPRETATION["alternative_outputs"][0]),
|
||||
len(media_data.SUM_PIXELS_SHAP_INTERPRETATION["alternative_outputs"][0]),
|
||||
)
|
||||
image_input = gr.Image(shape=(30, 10))
|
||||
iface = gr.Interface(
|
||||
@ -512,7 +512,7 @@ class TestImage(unittest.TestCase):
|
||||
self.assertIsNotNone(iface.interpret([img]))
|
||||
|
||||
def test_as_component_as_output(self):
|
||||
y_img = gr.processing_utils.decode_base64_to_image(gr.test_data.BASE64_IMAGE)
|
||||
y_img = gr.processing_utils.decode_base64_to_image(media_data.BASE64_IMAGE)
|
||||
image_output = gr.Image()
|
||||
self.assertTrue(
|
||||
image_output.postprocess(y_img).startswith(
|
||||
@ -542,11 +542,11 @@ class TestImage(unittest.TestCase):
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = image_output.save_flagged(
|
||||
tmpdirname, "image_output", gr.test_data.BASE64_IMAGE, None
|
||||
tmpdirname, "image_output", media_data.BASE64_IMAGE, None
|
||||
)
|
||||
self.assertEqual("image_output/0.png", to_save)
|
||||
to_save = image_output.save_flagged(
|
||||
tmpdirname, "image_output", gr.test_data.BASE64_IMAGE, None
|
||||
tmpdirname, "image_output", media_data.BASE64_IMAGE, None
|
||||
)
|
||||
self.assertEqual("image_output/1.png", to_save)
|
||||
|
||||
@ -562,7 +562,7 @@ class TestImage(unittest.TestCase):
|
||||
|
||||
class TestAudio(unittest.TestCase):
|
||||
def test_as_component_as_input(self):
|
||||
x_wav = gr.test_data.BASE64_AUDIO
|
||||
x_wav = media_data.BASE64_AUDIO
|
||||
audio_input = gr.Audio()
|
||||
output = audio_input.preprocess(x_wav)
|
||||
self.assertEqual(output[0], 8000)
|
||||
@ -612,7 +612,7 @@ class TestAudio(unittest.TestCase):
|
||||
self.assertIsInstance(audio_input.serialize(x_wav, False), dict)
|
||||
|
||||
def test_tokenize(self):
|
||||
x_wav = gr.test_data.BASE64_AUDIO
|
||||
x_wav = media_data.BASE64_AUDIO
|
||||
audio_input = gr.Audio()
|
||||
tokens, _, _ = audio_input.tokenize(x_wav)
|
||||
self.assertEquals(len(tokens), audio_input.interpretation_segments)
|
||||
@ -622,7 +622,7 @@ class TestAudio(unittest.TestCase):
|
||||
|
||||
def test_as_component_as_output(self):
|
||||
y_audio = gr.processing_utils.decode_base64_to_file(
|
||||
gr.test_data.BASE64_AUDIO["data"]
|
||||
media_data.BASE64_AUDIO["data"]
|
||||
)
|
||||
audio_output = gr.Audio(type="file")
|
||||
self.assertTrue(
|
||||
@ -641,15 +641,15 @@ class TestAudio(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
self.assertTrue(
|
||||
audio_output.deserialize(gr.test_data.BASE64_AUDIO["data"]).endswith(".wav")
|
||||
audio_output.deserialize(media_data.BASE64_AUDIO["data"]).endswith(".wav")
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = audio_output.save_flagged(
|
||||
tmpdirname, "audio_output", gr.test_data.BASE64_AUDIO, None
|
||||
tmpdirname, "audio_output", media_data.BASE64_AUDIO, None
|
||||
)
|
||||
self.assertEqual("audio_output/0.wav", to_save)
|
||||
to_save = audio_output.save_flagged(
|
||||
tmpdirname, "audio_output", gr.test_data.BASE64_AUDIO, None
|
||||
tmpdirname, "audio_output", media_data.BASE64_AUDIO, None
|
||||
)
|
||||
self.assertEqual("audio_output/1.wav", to_save)
|
||||
|
||||
@ -663,7 +663,7 @@ class TestAudio(unittest.TestCase):
|
||||
|
||||
class TestFile(unittest.TestCase):
|
||||
def test_as_component_as_input(self):
|
||||
x_file = gr.test_data.BASE64_FILE
|
||||
x_file = media_data.BASE64_FILE
|
||||
file_input = gr.File()
|
||||
output = file_input.preprocess(x_file)
|
||||
self.assertIsInstance(output, tempfile._TemporaryFileWrapper)
|
||||
@ -697,7 +697,7 @@ class TestFile(unittest.TestCase):
|
||||
self.assertIsNotNone(file_input.preprocess(x_file))
|
||||
|
||||
def test_in_interface_as_input(self):
|
||||
x_file = gr.test_data.BASE64_FILE
|
||||
x_file = media_data.BASE64_FILE
|
||||
|
||||
def get_size_of_file(file_obj):
|
||||
return os.path.getsize(file_obj.name)
|
||||
@ -723,11 +723,11 @@ class TestFile(unittest.TestCase):
|
||||
file_output = gr.File()
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = file_output.save_flagged(
|
||||
tmpdirname, "file_output", [gr.test_data.BASE64_FILE], None
|
||||
tmpdirname, "file_output", [media_data.BASE64_FILE], None
|
||||
)
|
||||
self.assertEqual("file_output/0", to_save)
|
||||
to_save = file_output.save_flagged(
|
||||
tmpdirname, "file_output", [gr.test_data.BASE64_FILE], None
|
||||
tmpdirname, "file_output", [media_data.BASE64_FILE], None
|
||||
)
|
||||
self.assertEqual("file_output/1", to_save)
|
||||
|
||||
@ -865,7 +865,7 @@ class TestDataframe(unittest.TestCase):
|
||||
|
||||
class TestVideo(unittest.TestCase):
|
||||
def test_as_component_as_input(self):
|
||||
x_video = gr.test_data.BASE64_VIDEO
|
||||
x_video = media_data.BASE64_VIDEO
|
||||
video_input = gr.Video()
|
||||
output = video_input.preprocess(x_video)
|
||||
self.assertIsInstance(output, str)
|
||||
@ -899,7 +899,7 @@ class TestVideo(unittest.TestCase):
|
||||
video_input.serialize(x_video, True)
|
||||
|
||||
def test_in_interface_as_input(self):
|
||||
x_video = gr.test_data.BASE64_VIDEO
|
||||
x_video = media_data.BASE64_VIDEO
|
||||
iface = gr.Interface(lambda x: x, "video", "playable_video")
|
||||
self.assertEqual(iface.process([x_video])[0][0]["data"], x_video["data"])
|
||||
|
||||
@ -910,15 +910,15 @@ class TestVideo(unittest.TestCase):
|
||||
video_output.postprocess(y_vid)["data"].startswith("data:video/mp4;base64,")
|
||||
)
|
||||
self.assertTrue(
|
||||
video_output.deserialize(gr.test_data.BASE64_VIDEO["data"]).endswith(".mp4")
|
||||
video_output.deserialize(media_data.BASE64_VIDEO["data"]).endswith(".mp4")
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = video_output.save_flagged(
|
||||
tmpdirname, "video_output", gr.test_data.BASE64_VIDEO, None
|
||||
tmpdirname, "video_output", media_data.BASE64_VIDEO, None
|
||||
)
|
||||
self.assertEqual("video_output/0.mp4", to_save)
|
||||
to_save = video_output.save_flagged(
|
||||
tmpdirname, "video_output", gr.test_data.BASE64_VIDEO, None
|
||||
tmpdirname, "video_output", media_data.BASE64_VIDEO, None
|
||||
)
|
||||
self.assertEqual("video_output/1.mp4", to_save)
|
||||
|
||||
@ -1092,7 +1092,7 @@ class TestLabel(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_in_interface(self):
|
||||
x_img = gr.test_data.BASE64_IMAGE
|
||||
x_img = media_data.BASE64_IMAGE
|
||||
|
||||
def rgb_distribution(img):
|
||||
rgb_dist = np.mean(img, axis=(0, 1))
|
||||
@ -1227,8 +1227,8 @@ class TestCarousel(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
output,
|
||||
[
|
||||
["Hello World", gr.test_data.BASE64_IMAGE],
|
||||
["Bye World", gr.test_data.BASE64_IMAGE],
|
||||
["Hello World", media_data.BASE64_IMAGE],
|
||||
["Bye World", media_data.BASE64_IMAGE],
|
||||
],
|
||||
)
|
||||
|
||||
@ -1277,7 +1277,7 @@ class TestCarousel(unittest.TestCase):
|
||||
return results
|
||||
|
||||
iface = gr.Interface(report, gr.inputs.Image(type="numpy"), carousel_output)
|
||||
result = iface.process([gr.test_data.BASE64_IMAGE])
|
||||
result = iface.process([media_data.BASE64_IMAGE])
|
||||
self.assertTrue(result[0][0][0][0] == "Red")
|
||||
self.assertTrue(
|
||||
result[0][0][0][1].startswith("data:image/png;base64,iVBORw0KGgoAAA")
|
||||
|
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@ import os
|
||||
import unittest
|
||||
|
||||
from gradio import encryptor, processing_utils
|
||||
from gradio.test_data import BASE64_IMAGE
|
||||
from test.test_data.media_data import BASE64_IMAGE
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
|
@ -9,6 +9,7 @@ import pandas
|
||||
import PIL
|
||||
|
||||
import gradio as gr
|
||||
from test.test_data import media_data
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
@ -405,7 +406,7 @@ class TestDropdown(unittest.TestCase):
|
||||
|
||||
class TestImage(unittest.TestCase):
|
||||
def test_as_component(self):
|
||||
img = gr.test_data.BASE64_IMAGE
|
||||
img = media_data.BASE64_IMAGE
|
||||
image_input = gr.inputs.Image()
|
||||
self.assertEqual(image_input.preprocess(img).shape, (68, 61, 3))
|
||||
image_input = gr.inputs.Image(shape=(25, 25), image_mode="L")
|
||||
@ -445,7 +446,7 @@ class TestImage(unittest.TestCase):
|
||||
image_input.preprocess(img)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
file_image = gr.inputs.Image(type="file")
|
||||
file_image.preprocess(gr.test_data.BASE64_IMAGE)
|
||||
file_image.preprocess(media_data.BASE64_IMAGE)
|
||||
file_image = gr.inputs.Image(type="filepath")
|
||||
self.assertIsInstance(file_image.preprocess(img), str)
|
||||
with self.assertRaises(ValueError):
|
||||
@ -466,7 +467,7 @@ class TestImage(unittest.TestCase):
|
||||
self.assertIsNotNone(image_input._segment_by_slic(img))
|
||||
|
||||
def test_in_interface(self):
|
||||
img = gr.test_data.BASE64_IMAGE
|
||||
img = media_data.BASE64_IMAGE
|
||||
image_input = gr.inputs.Image()
|
||||
iface = gr.Interface(
|
||||
lambda x: PIL.Image.open(x).rotate(90, expand=True),
|
||||
@ -481,10 +482,10 @@ class TestImage(unittest.TestCase):
|
||||
lambda x: np.sum(x), image_input, "number", interpretation="default"
|
||||
)
|
||||
scores, alternative_outputs = iface.interpret([img])
|
||||
self.assertEqual(scores, gr.test_data.SUM_PIXELS_INTERPRETATION["scores"])
|
||||
self.assertEqual(scores, media_data.SUM_PIXELS_INTERPRETATION["scores"])
|
||||
self.assertEqual(
|
||||
alternative_outputs,
|
||||
gr.test_data.SUM_PIXELS_INTERPRETATION["alternative_outputs"],
|
||||
media_data.SUM_PIXELS_INTERPRETATION["alternative_outputs"],
|
||||
)
|
||||
iface = gr.Interface(
|
||||
lambda x: np.sum(x), image_input, "label", interpretation="shap"
|
||||
@ -492,11 +493,11 @@ class TestImage(unittest.TestCase):
|
||||
scores, alternative_outputs = iface.interpret([img])
|
||||
self.assertEqual(
|
||||
len(scores[0]),
|
||||
len(gr.test_data.SUM_PIXELS_SHAP_INTERPRETATION["scores"][0]),
|
||||
len(media_data.SUM_PIXELS_SHAP_INTERPRETATION["scores"][0]),
|
||||
)
|
||||
self.assertEqual(
|
||||
len(alternative_outputs[0]),
|
||||
len(gr.test_data.SUM_PIXELS_SHAP_INTERPRETATION["alternative_outputs"][0]),
|
||||
len(media_data.SUM_PIXELS_SHAP_INTERPRETATION["alternative_outputs"][0]),
|
||||
)
|
||||
image_input = gr.inputs.Image(shape=(30, 10))
|
||||
iface = gr.Interface(
|
||||
@ -507,7 +508,7 @@ class TestImage(unittest.TestCase):
|
||||
|
||||
class TestAudio(unittest.TestCase):
|
||||
def test_as_component(self):
|
||||
x_wav = gr.test_data.BASE64_AUDIO
|
||||
x_wav = media_data.BASE64_AUDIO_DUPLICATE
|
||||
audio_input = gr.inputs.Audio()
|
||||
output = audio_input.preprocess(x_wav)
|
||||
self.assertEqual(output[0], 8000)
|
||||
@ -557,7 +558,7 @@ class TestAudio(unittest.TestCase):
|
||||
self.assertIsInstance(audio_input.serialize(x_wav, False), dict)
|
||||
|
||||
def test_tokenize(self):
|
||||
x_wav = gr.test_data.BASE64_AUDIO
|
||||
x_wav = media_data.BASE64_AUDIO
|
||||
audio_input = gr.inputs.Audio()
|
||||
tokens, _, _ = audio_input.tokenize(x_wav)
|
||||
self.assertEquals(len(tokens), audio_input.interpretation_segments)
|
||||
@ -568,7 +569,7 @@ class TestAudio(unittest.TestCase):
|
||||
|
||||
class TestFile(unittest.TestCase):
|
||||
def test_as_component(self):
|
||||
x_file = gr.test_data.BASE64_FILE
|
||||
x_file = media_data.BASE64_FILE
|
||||
file_input = gr.inputs.File()
|
||||
output = file_input.preprocess(x_file)
|
||||
self.assertIsInstance(output, tempfile._TemporaryFileWrapper)
|
||||
@ -602,7 +603,7 @@ class TestFile(unittest.TestCase):
|
||||
self.assertIsNotNone(file_input.preprocess(x_file))
|
||||
|
||||
def test_in_interface(self):
|
||||
x_file = gr.test_data.BASE64_FILE
|
||||
x_file = media_data.BASE64_FILE
|
||||
|
||||
def get_size_of_file(file_obj):
|
||||
return os.path.getsize(file_obj.name)
|
||||
@ -676,7 +677,7 @@ class TestDataframe(unittest.TestCase):
|
||||
|
||||
class TestVideo(unittest.TestCase):
|
||||
def test_as_component(self):
|
||||
x_video = gr.test_data.BASE64_VIDEO
|
||||
x_video = media_data.BASE64_VIDEO
|
||||
video_input = gr.inputs.Video()
|
||||
output = video_input.preprocess(x_video)
|
||||
self.assertIsInstance(output, str)
|
||||
@ -710,7 +711,7 @@ class TestVideo(unittest.TestCase):
|
||||
video_input.serialize(x_video, True)
|
||||
|
||||
def test_in_interface(self):
|
||||
x_video = gr.test_data.BASE64_VIDEO
|
||||
x_video = media_data.BASE64_VIDEO
|
||||
iface = gr.Interface(lambda x: x, "video", "playable_video")
|
||||
self.assertEqual(iface.process([x_video])[0][0]["data"], x_video["data"])
|
||||
|
||||
|
@ -4,9 +4,9 @@ import unittest
|
||||
import numpy as np
|
||||
|
||||
import gradio.interpretation
|
||||
import gradio.test_data
|
||||
from gradio import Interface
|
||||
from gradio.processing_utils import decode_base64_to_image
|
||||
from test.test_data import media_data
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
@ -59,9 +59,9 @@ class TestCustom(unittest.TestCase):
|
||||
img_interface = Interface(
|
||||
max_pixel_value, "image", "label", interpretation=custom
|
||||
)
|
||||
result = img_interface.interpret([gradio.test_data.BASE64_IMAGE])[0][0]
|
||||
result = img_interface.interpret([media_data.BASE64_IMAGE])[0][0]
|
||||
expected_result = np.asarray(
|
||||
decode_base64_to_image(gradio.test_data.BASE64_IMAGE).convert("RGB")
|
||||
decode_base64_to_image(media_data.BASE64_IMAGE).convert("RGB")
|
||||
).tolist()
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
|
@ -6,7 +6,7 @@ import unittest
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from test.test_data import media_data
|
||||
import gradio as gr
|
||||
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
@ -78,7 +78,7 @@ class TestLabel(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_in_interface(self):
|
||||
x_img = gr.test_data.BASE64_IMAGE
|
||||
x_img = media_data.BASE64_IMAGE
|
||||
|
||||
def rgb_distribution(img):
|
||||
rgb_dist = np.mean(img, axis=(0, 1))
|
||||
@ -107,7 +107,7 @@ class TestLabel(unittest.TestCase):
|
||||
|
||||
class TestImage(unittest.TestCase):
|
||||
def test_as_component(self):
|
||||
y_img = gr.processing_utils.decode_base64_to_image(gr.test_data.BASE64_IMAGE)
|
||||
y_img = gr.processing_utils.decode_base64_to_image(media_data.BASE64_IMAGE)
|
||||
image_output = gr.outputs.Image()
|
||||
self.assertTrue(
|
||||
image_output.postprocess(y_img).startswith(
|
||||
@ -137,11 +137,11 @@ class TestImage(unittest.TestCase):
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = image_output.save_flagged(
|
||||
tmpdirname, "image_output", gr.test_data.BASE64_IMAGE, None
|
||||
tmpdirname, "image_output", media_data.BASE64_IMAGE, None
|
||||
)
|
||||
self.assertEqual("image_output/0.png", to_save)
|
||||
to_save = image_output.save_flagged(
|
||||
tmpdirname, "image_output", gr.test_data.BASE64_IMAGE, None
|
||||
tmpdirname, "image_output", media_data.BASE64_IMAGE, None
|
||||
)
|
||||
self.assertEqual("image_output/1.png", to_save)
|
||||
|
||||
@ -163,15 +163,15 @@ class TestVideo(unittest.TestCase):
|
||||
video_output.postprocess(y_vid)["data"].startswith("data:video/mp4;base64,")
|
||||
)
|
||||
self.assertTrue(
|
||||
video_output.deserialize(gr.test_data.BASE64_VIDEO["data"]).endswith(".mp4")
|
||||
video_output.deserialize(media_data.BASE64_VIDEO["data"]).endswith(".mp4")
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = video_output.save_flagged(
|
||||
tmpdirname, "video_output", gr.test_data.BASE64_VIDEO, None
|
||||
tmpdirname, "video_output", media_data.BASE64_VIDEO, None
|
||||
)
|
||||
self.assertEqual("video_output/0.mp4", to_save)
|
||||
to_save = video_output.save_flagged(
|
||||
tmpdirname, "video_output", gr.test_data.BASE64_VIDEO, None
|
||||
tmpdirname, "video_output", media_data.BASE64_VIDEO, None
|
||||
)
|
||||
self.assertEqual("video_output/1.mp4", to_save)
|
||||
|
||||
@ -225,7 +225,7 @@ class TestHighlightedText(unittest.TestCase):
|
||||
class TestAudio(unittest.TestCase):
|
||||
def test_as_component(self):
|
||||
y_audio = gr.processing_utils.decode_base64_to_file(
|
||||
gr.test_data.BASE64_AUDIO["data"]
|
||||
media_data.BASE64_AUDIO["data"]
|
||||
)
|
||||
audio_output = gr.outputs.Audio(type="file")
|
||||
self.assertTrue(
|
||||
@ -244,15 +244,15 @@ class TestAudio(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
self.assertTrue(
|
||||
audio_output.deserialize(gr.test_data.BASE64_AUDIO["data"]).endswith(".wav")
|
||||
audio_output.deserialize(media_data.BASE64_AUDIO["data"]).endswith(".wav")
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = audio_output.save_flagged(
|
||||
tmpdirname, "audio_output", gr.test_data.BASE64_AUDIO, None
|
||||
tmpdirname, "audio_output", media_data.BASE64_AUDIO, None
|
||||
)
|
||||
self.assertEqual("audio_output/0.wav", to_save)
|
||||
to_save = audio_output.save_flagged(
|
||||
tmpdirname, "audio_output", gr.test_data.BASE64_AUDIO, None
|
||||
tmpdirname, "audio_output", media_data.BASE64_AUDIO, None
|
||||
)
|
||||
self.assertEqual("audio_output/1.wav", to_save)
|
||||
|
||||
@ -330,11 +330,11 @@ class TestFile(unittest.TestCase):
|
||||
file_output = gr.outputs.File()
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
to_save = file_output.save_flagged(
|
||||
tmpdirname, "file_output", [gr.test_data.BASE64_FILE], None
|
||||
tmpdirname, "file_output", [media_data.BASE64_FILE], None
|
||||
)
|
||||
self.assertEqual("file_output/0", to_save)
|
||||
to_save = file_output.save_flagged(
|
||||
tmpdirname, "file_output", [gr.test_data.BASE64_FILE], None
|
||||
tmpdirname, "file_output", [media_data.BASE64_FILE], None
|
||||
)
|
||||
self.assertEqual("file_output/1", to_save)
|
||||
|
||||
@ -422,8 +422,8 @@ class TestCarousel(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
output,
|
||||
[
|
||||
["Hello World", gr.test_data.BASE64_IMAGE],
|
||||
["Bye World", gr.test_data.BASE64_IMAGE],
|
||||
["Hello World", media_data.BASE64_IMAGE],
|
||||
["Bye World", media_data.BASE64_IMAGE],
|
||||
],
|
||||
)
|
||||
|
||||
@ -471,7 +471,7 @@ class TestCarousel(unittest.TestCase):
|
||||
|
||||
iface = gr.Interface(report, gr.inputs.Image(type="numpy"), carousel_output)
|
||||
self.assertEqual(
|
||||
iface.process([gr.test_data.BASE64_IMAGE])[0],
|
||||
iface.process([media_data.BASE64_IMAGE])[0],
|
||||
[
|
||||
[
|
||||
[
|
||||
|
@ -6,14 +6,14 @@ import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
import gradio as gr
|
||||
|
||||
from test.test_data import media_data
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
|
||||
class ImagePreprocessing(unittest.TestCase):
|
||||
def test_decode_base64_to_image(self):
|
||||
output_image = gr.processing_utils.decode_base64_to_image(
|
||||
gr.test_data.BASE64_IMAGE
|
||||
media_data.BASE64_IMAGE
|
||||
)
|
||||
self.assertIsInstance(output_image, Image.Image)
|
||||
|
||||
@ -21,33 +21,33 @@ class ImagePreprocessing(unittest.TestCase):
|
||||
output_base64 = gr.processing_utils.encode_url_or_file_to_base64(
|
||||
"test/test_data/test_image.png"
|
||||
)
|
||||
self.assertEquals(output_base64, gr.test_data.BASE64_IMAGE)
|
||||
self.assertEquals(output_base64, media_data.BASE64_IMAGE)
|
||||
|
||||
def test_encode_file_to_base64(self):
|
||||
output_base64 = gr.processing_utils.encode_file_to_base64(
|
||||
"test/test_data/test_image.png"
|
||||
)
|
||||
self.assertEquals(output_base64, gr.test_data.BASE64_IMAGE)
|
||||
self.assertEquals(output_base64, media_data.BASE64_IMAGE)
|
||||
|
||||
def test_encode_url_to_base64(self):
|
||||
output_base64 = gr.processing_utils.encode_url_to_base64(
|
||||
"https://raw.githubusercontent.com/gradio-app/gradio/master/test"
|
||||
"/test_data/test_image.png"
|
||||
)
|
||||
self.assertEqual(output_base64, gr.test_data.BASE64_IMAGE)
|
||||
self.assertEqual(output_base64, media_data.BASE64_IMAGE)
|
||||
|
||||
# Commented out because this is throwing errors on Windows. Possibly due to different matplotlib behavior on Windows?
|
||||
# def test_encode_plot_to_base64(self):
|
||||
# plt.plot([1, 2, 3, 4])
|
||||
# output_base64 = gr.processing_utils.encode_plot_to_base64(plt)
|
||||
# self.assertEqual(output_base64, gr.test_data.BASE64_PLT_IMG)
|
||||
# self.assertEqual(output_base64, media_data.BASE64_PLT_IMG)
|
||||
|
||||
def test_encode_array_to_base64(self):
|
||||
img = Image.open("test/test_data/test_image.png")
|
||||
img = img.convert("RGB")
|
||||
numpy_data = np.asarray(img, dtype=np.uint8)
|
||||
output_base64 = gr.processing_utils.encode_array_to_base64(numpy_data)
|
||||
self.assertEqual(output_base64, gr.test_data.ARRAY_TO_BASE64_IMAGE)
|
||||
self.assertEqual(output_base64, media_data.ARRAY_TO_BASE64_IMAGE)
|
||||
|
||||
def test_resize_and_crop(self):
|
||||
img = Image.open("test/test_data/test_image.png")
|
||||
@ -75,11 +75,11 @@ class AudioPreprocessing(unittest.TestCase):
|
||||
|
||||
class OutputPreprocessing(unittest.TestCase):
|
||||
def test_decode_base64_to_binary(self):
|
||||
binary = gr.processing_utils.decode_base64_to_binary(gr.test_data.BASE64_IMAGE)
|
||||
self.assertEqual(gr.test_data.BINARY_IMAGE, binary)
|
||||
binary = gr.processing_utils.decode_base64_to_binary(media_data.BASE64_IMAGE)
|
||||
self.assertEqual(media_data.BINARY_IMAGE, binary)
|
||||
|
||||
def test_decode_base64_to_file(self):
|
||||
temp_file = gr.processing_utils.decode_base64_to_file(gr.test_data.BASE64_IMAGE)
|
||||
temp_file = gr.processing_utils.decode_base64_to_file(media_data.BASE64_IMAGE)
|
||||
self.assertIsInstance(temp_file, tempfile._TemporaryFileWrapper)
|
||||
|
||||
def test_create_tmp_copy_of_file(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user