MCPcopy Index your code
hub / github.com/plotly/dash / check_output_for_grouping

Function check_output_for_grouping

tests/unit/library/test_grouped_callbacks.py:34–68  ·  view source on GitHub ↗

Check the behavior of a callback that returns the specified grouping

(grouping)

Source from the content-addressed store, hash-verified

32
33
34def check_output_for_grouping(grouping):
35 """
36 Check the behavior of a callback that returns the specified grouping
37 """
38 outputs = make_dependency_grouping(grouping, Output)
39 multi = not isinstance(outputs, Output)
40 app = dash.Dash()
41 mock_fn = mock.Mock()
42 mock_fn.return_value = grouping
43 if multi:
44 callback_id = create_callback_id(flatten_grouping(outputs), [])
45 else:
46 callback_id = create_callback_id(outputs, [])
47
48 app.callback(
49 outputs,
50 Input("input-a", "prop"),
51 )(mock_fn)
52
53 wrapped_fn = app.callback_map[callback_id]["callback"]
54
55 expected_outputs = [
56 (dep.component_id, dep.component_property, val)
57 for dep, val in zip(flatten_grouping(outputs), flatten_grouping(grouping))
58 ]
59
60 outputs_list = [{"id": out[0], "property": out[1]} for out in expected_outputs]
61 if not multi:
62 outputs_list = outputs_list[0]
63
64 result = json.loads(wrapped_fn("Hello", outputs_list=outputs_list))
65
66 response = result["response"]
67 for id, prop, val in expected_outputs:
68 assert response[id][prop] == val
69
70
71def test_callback_output_scalar(scalar_grouping_size):

Callers 4

Calls 5

callbackMethod · 0.95
create_callback_idFunction · 0.90
flatten_groupingFunction · 0.90
InputClass · 0.90
make_dependency_groupingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…