|
1 | 1 | # -*- coding: UTF-8 -*-
|
2 |
| -from multiprocessing import Value |
| 2 | +from multiprocessing import Value, Lock |
| 3 | +import pytest |
3 | 4 |
|
4 | 5 | from dash import Dash, Input, Output, State, ClientsideFunction, ALL, html, dcc
|
5 | 6 | from selenium.webdriver.common.keys import Keys
|
@@ -223,6 +224,7 @@ def test_clsd004_clientside_multiple_outputs(dash_duo):
|
223 | 224 | dash_duo.wait_for_text_to_equal(selector, expected)
|
224 | 225 |
|
225 | 226 |
|
| 227 | +@pytest.mark.xfail(reason="Promises are now handled within Dash-Renderer") |
226 | 228 | def test_clsd005_clientside_fails_when_returning_a_promise(dash_duo):
|
227 | 229 | app = Dash(__name__, assets_folder="assets")
|
228 | 230 |
|
@@ -716,3 +718,90 @@ def test_clsd014_input_output_callback(dash_duo):
|
716 | 718 | assert call_count == 2, "initial + changed once"
|
717 | 719 |
|
718 | 720 | assert dash_duo.get_logs() == []
|
| 721 | + |
| 722 | + |
| 723 | +def test_clsd015_clientside_chained_callbacks_returning_promise(dash_duo): |
| 724 | + app = Dash(__name__, assets_folder="assets") |
| 725 | + |
| 726 | + app.layout = html.Div( |
| 727 | + [ |
| 728 | + html.Div(id="input", children=["initial"]), |
| 729 | + html.Div(id="div-1"), |
| 730 | + html.Div(id="div-2"), |
| 731 | + ] |
| 732 | + ) |
| 733 | + |
| 734 | + app.clientside_callback( |
| 735 | + ClientsideFunction(namespace="clientside", function_name="chained_promise"), |
| 736 | + Output("div-1", "children"), |
| 737 | + Input("input", "children"), |
| 738 | + ) |
| 739 | + |
| 740 | + @app.callback(Output("div-2", "children"), Input("div-1", "children")) |
| 741 | + def callback(value): |
| 742 | + return value + "-twice" |
| 743 | + |
| 744 | + dash_duo.start_server(app) |
| 745 | + |
| 746 | + dash_duo.wait_for_text_to_equal("#div-1", "initial-chained") |
| 747 | + dash_duo.wait_for_text_to_equal("#div-2", "initial-chained-twice") |
| 748 | + |
| 749 | + |
| 750 | +def test_clsd016_serverside_clientside_shared_input_with_promise(dash_duo): |
| 751 | + app = Dash(__name__, assets_folder="assets") |
| 752 | + |
| 753 | + app.layout = html.Div( |
| 754 | + [ |
| 755 | + html.Div(id="input", children=["initial"]), |
| 756 | + html.Div(id="clientside-div"), |
| 757 | + html.Div(id="serverside-div"), |
| 758 | + ] |
| 759 | + ) |
| 760 | + |
| 761 | + app.clientside_callback( |
| 762 | + ClientsideFunction(namespace="clientside", function_name="delayed_promise"), |
| 763 | + Output("clientside-div", "children"), |
| 764 | + Input("input", "children"), |
| 765 | + ) |
| 766 | + |
| 767 | + @app.callback(Output("serverside-div", "children"), Input("input", "children")) |
| 768 | + def callback(value): |
| 769 | + return "serverside-" + value[0] |
| 770 | + |
| 771 | + dash_duo.start_server(app) |
| 772 | + |
| 773 | + dash_duo.wait_for_text_to_equal("#serverside-div", "serverside-initial") |
| 774 | + dash_duo.driver.execute_script("window.callbackDone('deferred')") |
| 775 | + dash_duo.wait_for_text_to_equal("#clientside-div", "clientside-initial-deferred") |
| 776 | + |
| 777 | + |
| 778 | +def test_clsd017_clientside_serverside_shared_input_with_promise(dash_duo): |
| 779 | + lock = Lock() |
| 780 | + lock.acquire() |
| 781 | + |
| 782 | + app = Dash(__name__, assets_folder="assets") |
| 783 | + |
| 784 | + app.layout = html.Div( |
| 785 | + [ |
| 786 | + html.Div(id="input", children=["initial"]), |
| 787 | + html.Div(id="clientside-div"), |
| 788 | + html.Div(id="serverside-div"), |
| 789 | + ] |
| 790 | + ) |
| 791 | + |
| 792 | + app.clientside_callback( |
| 793 | + ClientsideFunction(namespace="clientside", function_name="non_delayed_promise"), |
| 794 | + Output("clientside-div", "children"), |
| 795 | + Input("input", "children"), |
| 796 | + ) |
| 797 | + |
| 798 | + @app.callback(Output("serverside-div", "children"), Input("input", "children")) |
| 799 | + def callback(value): |
| 800 | + with lock: |
| 801 | + return "serverside-" + value[0] + "-deferred" |
| 802 | + |
| 803 | + dash_duo.start_server(app) |
| 804 | + |
| 805 | + dash_duo.wait_for_text_to_equal("#clientside-div", "clientside-initial") |
| 806 | + lock.release() |
| 807 | + dash_duo.wait_for_text_to_equal("#serverside-div", "serverside-initial-deferred") |
0 commit comments