-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
test_soft_reload.py
79 lines (70 loc) · 1.8 KB
/
test_soft_reload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from selenium.webdriver.support.select import Select
import time, os
RED_BG = """
#hot-reload-content {
background-color: red;
}
"""
app = """
library(dash)
app <- Dash$new()
app$layout(html$div(list(
html$h3("Hot reload"),
dccInput(id='input'),
html$div(id='output-serverside')
),
id="hot-reload-content"
)
)
app$callback(
output(id = "output-serverside", property = "children"),
params = list(
input(id = "input", property = "value")
),
function(value) {
sprintf("Test output should be %s", value)
}
)
app$run_server(dev_tools_hot_reload=TRUE, dev_tools_hot_reload_interval=0.1, dev_tools_silence_routes_logging=TRUE)
"""
def test_rsdv001_soft_reload(dashr):
dashr.start_server(app)
dashr.wait_for_style_to_equal(
"#hot-reload-content",
"background-color",
"rgba(0, 0, 255, 1)"
)
dashr.wait_for_text_to_equal(
"#output-serverside",
"Test output should be NULL"
)
input1 = dashr.find_element("#input")
dashr.clear_input(input1)
input1.send_keys("unchanged")
hot_reload_file = os.path.join(
dashr.server.tmp_app_path, "assets", "hot_reload.css"
)
print(hot_reload_file)
with open(hot_reload_file, "r+") as fp:
time.sleep(1) # ensure a new mod time
old_content = fp.read()
fp.truncate(0)
fp.seek(0)
fp.write(RED_BG)
dashr.wait_for_style_to_equal(
"#hot-reload-content",
"background-color",
"rgba(255, 0, 0, 1)"
)
dashr.wait_for_text_to_equal(
"#output-serverside",
"Test output should be unchanged"
)
with open(hot_reload_file, "w") as f:
f.write(old_content)
time.sleep(1)
dashr.wait_for_style_to_equal(
"#hot-reload-content",
"background-color",
"rgba(0, 0, 255, 1)"
)