output tests passing

This commit is contained in:
Abubakar Abid 2022-03-25 16:44:13 -07:00
parent 444e91cdc9
commit 6ff3ad2d4a
3 changed files with 20 additions and 11 deletions

View File

@ -1988,7 +1988,7 @@ class Dataframe(Component):
): ):
""" """
Input Parameters: Input Parameters:
default_value (List[List[Any]]): Default value default_value (List[List[Any]]): Default value as a pandas DataFrame. TODO: Add support for default value as a filepath
headers (List[str]): Header names to dataframe. If None, no headers are shown. headers (List[str]): Header names to dataframe. If None, no headers are shown.
row_count (int): Limit number of rows for input. row_count (int): Limit number of rows for input.
col_count (int): Limit number of columns for input. If equal to 1, return data will be one-dimensional. Ignored if `headers` is provided. col_count (int): Limit number of columns for input. If equal to 1, return data will be one-dimensional. Ignored if `headers` is provided.
@ -2150,7 +2150,7 @@ class Timeseries(Component):
def __init__( def __init__(
self, self,
default_value: str = "", default_value: Optional[str] = None,
*, *,
x: Optional[str] = None, x: Optional[str] = None,
y: str | List[str] = None, y: str | List[str] = None,
@ -2160,13 +2160,16 @@ class Timeseries(Component):
): ):
""" """
Parameters: Parameters:
default_value: File path for the timeseries csv file. default_value: File path for the timeseries csv file. TODO: Add support for default value as a pd.DataFrame
x (str): Column name of x (time) series. None if csv has no headers, in which case first column is x series. x (str): Column name of x (time) series. None if csv has no headers, in which case first column is x series.
y (Union[str, List[str]]): Column name of y series, or list of column names if multiple series. None if csv has no headers, in which case every column after first is a y series. y (Union[str, List[str]]): Column name of y series, or list of column names if multiple series. None if csv has no headers, in which case every column after first is a y series.
label (str): component name in interface. label (str): component name in interface.
""" """
# TODO: Probably incorrect self.default_value = (
self.default_value = pd.DataFrame(default_value) pd.read_csv(default_value)
if default_value is not None
else None
)
self.x = x self.x = x
if isinstance(y, str): if isinstance(y, str):
y = [y] y = [y]

View File

@ -130,7 +130,7 @@ class TestNumber(unittest.TestCase):
) )
self.assertEqual( self.assertEqual(
numeric_input.get_template_context(), numeric_input.get_template_context(),
{"default": None, "name": "number", "label": None, "css": {}}, {"default_value": None, "name": "number", "label": None, "css": {}},
) )
def test_in_interface(self): def test_in_interface(self):
@ -191,7 +191,7 @@ class TestSlider(unittest.TestCase):
"minimum": 10, "minimum": 10,
"maximum": 20, "maximum": 20,
"step": 1, "step": 1,
"default": 15, "default_value": 15,
"name": "slider", "name": "slider",
"label": "Slide Your Input", "label": "Slide Your Input",
"css": {}, "css": {},

View File

@ -184,6 +184,7 @@ class TestHighlightedText(unittest.TestCase):
"label": None, "label": None,
"show_legend": False, "show_legend": False,
"css": {}, "css": {},
"default_value": ""
}, },
) )
ht = {"pos": "Hello ", "neg": "World"} ht = {"pos": "Hello ", "neg": "World"}
@ -231,7 +232,11 @@ class TestAudio(unittest.TestCase):
) )
self.assertEqual( self.assertEqual(
audio_output.get_template_context(), audio_output.get_template_context(),
{"name": "audio", "label": None, "source": "upload", "css": {}}, {"name": "audio",
"label": None,
"source": "upload",
"css": {},
"default_value": None},
) )
self.assertTrue( self.assertTrue(
audio_output.deserialize(gr.test_data.BASE64_AUDIO["data"]).endswith(".wav") audio_output.deserialize(gr.test_data.BASE64_AUDIO["data"]).endswith(".wav")
@ -357,7 +362,7 @@ class TestDataframe(unittest.TestCase):
"row_count": 3, "row_count": 3,
"col_count": 3, "col_count": 3,
"col_width": None, "col_width": None,
"default": [[None, None, None], [None, None, None], [None, None, None]], "default_value": [[None, None, None], [None, None, None], [None, None, None]],
"name": "dataframe", "name": "dataframe",
}, },
) )
@ -423,7 +428,7 @@ class TestCarousel(unittest.TestCase):
{ {
"name": "textbox", "name": "textbox",
"label": None, "label": None,
"default": "", "default_value": "",
"lines": 1, "lines": 1,
"css": {}, "css": {},
"placeholder": None, "placeholder": None,
@ -482,7 +487,8 @@ class TestTimeseries(unittest.TestCase):
timeseries_output = gr.outputs.Timeseries(label="Disease") timeseries_output = gr.outputs.Timeseries(label="Disease")
self.assertEqual( self.assertEqual(
timeseries_output.get_template_context(), timeseries_output.get_template_context(),
{"x": None, "y": None, "name": "timeseries", "label": "Disease", "css": {}}, {"x": None, "y": None, "name": "timeseries", "label": "Disease", "css": {},
"default_value": None},
) )
data = {"Name": ["Tom", "nick", "krish", "jack"], "Age": [20, 21, 19, 18]} data = {"Name": ["Tom", "nick", "krish", "jack"], "Age": [20, 21, 19, 18]}
df = pd.DataFrame(data) df = pd.DataFrame(data)