Hi everybody, I’m setting up some testing and I am running into an issue when trying to test functions with pattern-matching callbacks.
I have a function like this:
@dash.callback(
Output('country-focus', 'n_clicks'),
Output('country-zoom', 'value'),
Output('country-lat', 'value'),
Output('country-lon', 'value'),
Input({'tag': 'model-map', 'index': ALL, "n_clicks": ALL}, 'viewport'),
Input({'tag': 'model-map', 'index': ALL, "n_clicks": ALL}, 'id'),
prevent_initial_call=True
)
def zooms(viewport, models):
"""Syncronize all maps to have same center and zoom in mosaic"""
ctx = dash.callback_context
if ctx.triggered:
changed = dict(ctx.triggered_id)
index = models.index(changed)
if viewport[index] is not None:
return 1, \
viewport[index]['zoom'], \
viewport[index]['center'][0], \
viewport[index]['center'][1]
raise PreventUpdate
Which I’m trying to test with a function that looks like this:
def test_zooms():
def run_callback():
context_value.set(AttributeDict(**{"triggered_inputs": [{"prop_id": "{'tag': 'model-map', 'index': 'med
ian', 'n_clicks': 0}"},{"prop_id": "{'tag': 'model-map', 'index': 'median', 'n_clicks': 0}"}]}))
return code.zooms([None, None],[{'tag': 'model-map', 'index': 'median', 'n_clicks': 0}, {'tag': 'model-
map', 'index': 'monarch', 'n_clicks': 1}])
ctx = copy_context()
output = ctx.run(run_callback)
assert output == (True, False)
The assert output statement is not what I’m expecting as the output, just a dummy to see what happens.
I’m fairly sure the problem is in the context_value.set line, as I’m not sure how to refer to the pattern-matching variables. Anybody have any experience with this or have any tips that might point me in the right direction?
Thanks,
Elliott