mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Fix postprocess when value is a dict with only one key (#2242)
* Unwrap + test * Update tests + use resolve_singleton * Undo test change
This commit is contained in:
parent
5e7f5a0f6b
commit
422de63663
@ -673,7 +673,7 @@ class Blocks(BlockContext):
|
||||
)
|
||||
output_index = dependency["outputs"].index(component._id)
|
||||
reordered_predictions[output_index] = value
|
||||
predictions = reordered_predictions
|
||||
predictions = utils.resolve_singleton(reordered_predictions)
|
||||
elif any(keys_are_blocks):
|
||||
raise ValueError(
|
||||
"Returned dictionary included some keys as Components. Either all keys must be Components to assign Component values, or return a List of values to assign output values in order."
|
||||
|
@ -301,6 +301,25 @@ class TestComponentsInBlocks:
|
||||
assert output[0]["value"] == "NO_VALUE"
|
||||
|
||||
|
||||
def test_blocks_returns_correct_output_dict_single_key():
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
num = gr.Number()
|
||||
num2 = gr.Number()
|
||||
update = gr.Button(value="update")
|
||||
|
||||
def update_values():
|
||||
return {num2: gr.Number.update(value=42)}
|
||||
|
||||
update.click(update_values, inputs=[num], outputs=[num2])
|
||||
|
||||
output = demo.postprocess_data(0, {num2: gr.Number.update(value=42)}, state=None)
|
||||
assert output[0]["value"] == 42
|
||||
|
||||
output = demo.postprocess_data(0, {num2: 23}, state=None)
|
||||
assert output[0] == 23
|
||||
|
||||
|
||||
class TestCallFunction:
|
||||
@pytest.mark.asyncio
|
||||
async def test_call_regular_function(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user