MCPcopy
hub / github.com/plotly/dash / test_dvhr001_hot_reload

Function test_dvhr001_hot_reload

tests/integration/devtools/test_hot_reload.py:33–131  ·  view source on GitHub ↗
(dash_duo_mp)

Source from the content-addressed store, hash-verified

31
32
33def test_dvhr001_hot_reload(dash_duo_mp):
34 app = Dash(__name__, assets_folder="hr_assets")
35 app.layout = html.Div(
36 [html.H3("Hot reload", id="text"), html.Button("Click", id="btn")],
37 id="hot-reload-content",
38 )
39
40 @app.callback(Output("text", "children"), [Input("btn", "n_clicks")])
41 def new_text(n):
42 if not n:
43 raise PreventUpdate
44 return n
45
46 hot_reload_settings = dict(
47 dev_tools_hot_reload=True,
48 dev_tools_ui=True,
49 dev_tools_serve_dev_bundles=True,
50 dev_tools_hot_reload_interval=0.1,
51 dev_tools_hot_reload_max_retry=100,
52 )
53
54 dash_duo_mp.start_server(app, **hot_reload_settings)
55
56 # default overload color is blue
57 dash_duo_mp.wait_for_style_to_equal(
58 "#hot-reload-content", "background-color", "rgba(0, 0, 255, 1)"
59 )
60
61 # set a global var - if we soft reload it should still be there,
62 # hard reload will delete it
63 dash_duo_mp.driver.execute_script("window.someVar = 42;")
64 assert dash_duo_mp.driver.execute_script("return window.someVar") == 42
65
66 soft_reload_file, old_soft = replace_file("hot_reload.css", RED_BG)
67
68 try:
69 # red is live changed during the test execution
70 dash_duo_mp.wait_for_style_to_equal(
71 "#hot-reload-content", "background-color", "rgba(255, 0, 0, 1)"
72 )
73 finally:
74 sleep(1) # ensure a new mod time
75 with open(soft_reload_file, "w") as f:
76 f.write(old_soft)
77
78 dash_duo_mp.wait_for_style_to_equal(
79 "#hot-reload-content", "background-color", "rgba(0, 0, 255, 1)"
80 )
81
82 # only soft reload, someVar is still there
83 assert dash_duo_mp.driver.execute_script("return window.someVar") == 42
84
85 assert dash_duo_mp.driver.execute_script("return window.cheese") == "roquefort"
86
87 hard_reload_file, old_hard = replace_file("hot_reload.js", GOUDA)
88
89 try:
90 until(

Callers

nothing calls this directly

Calls 12

DashClass · 0.90
untilFunction · 0.90
replace_fileFunction · 0.85
find_elementMethod · 0.80
percy_snapshotMethod · 0.80
wait_for_elementMethod · 0.80
wait_for_no_elementsMethod · 0.80
start_serverMethod · 0.45
stopMethod · 0.45
clickMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…