Check the behavior of a callback that returns the specified grouping
(grouping)
| 32 | |
| 33 | |
| 34 | def 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 | |
| 71 | def test_callback_output_scalar(scalar_grouping_size): |
no test coverage detected
searching dependent graphs…