Skip to content

Commit b3e73de

Browse files
authored
Merge pull request #112 from plotly/test-hot-reload
Add test for hot reload
2 parents 657ab92 + 8c882bf commit b3e73de

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

tests/IntegrationTests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ def tearDown(s):
4949
s.server_process.terminate()
5050
time.sleep(2)
5151

52-
def startServer(s, dash):
52+
def startServer(s, dash, **kwargs):
5353
def run():
5454
dash.scripts.config.serve_locally = True
55-
dash.run_server(
55+
kws = dict(
5656
port=8050,
5757
debug=False,
5858
processes=4,
5959
threaded=False
6060
)
61+
kws.update(kwargs)
62+
dash.run_server(**kws)
6163

6264
# Run on a separate process so that it doesn't block
6365
s.server_process = multiprocessing.Process(target=run)

tests/test_assets/hot_reload.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#hot-reload-content {
2+
background-color: blue;
3+
}

tests/test_render.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
import textwrap
3+
14
from dash import Dash
25
from dash.dependencies import Input, Output, State, Event
36
import dash
@@ -45,6 +48,24 @@ def wait_for_text_to_equal(self, selector, assertion_text):
4548

4649
raise exception
4750

51+
def wait_for_style_to_equal(self, selector, style, assertion_style,
52+
timeout=20):
53+
start = time.time()
54+
exception = Exception('Time ran out, {} on {} not found'.format(
55+
assertion_style, selector))
56+
while time.time() < start + timeout:
57+
element = self.wait_for_element_by_css_selector(selector)
58+
try:
59+
self.assertEqual(assertion_style,
60+
element.value_of_css_property(style))
61+
except Exception as e:
62+
exception = e
63+
else:
64+
return
65+
time.sleep(0.25)
66+
67+
raise exception
68+
4869
def request_queue_assertions(
4970
self, check_rejected=True, expected_length=None):
5071
request_queue = self.driver.execute_script(
@@ -1961,3 +1982,42 @@ def render_content(tab):
19611982
)[0].click()
19621983

19631984
self.wait_for_text_to_equal('#graph2_info', json.dumps(graph_2_expected_clickdata))
1985+
1986+
def test_hot_reload(self):
1987+
app = dash.Dash(__name__, assets_folder='tests/test_assets')
1988+
1989+
app.layout = html.Div([
1990+
html.H3('Hot reload')
1991+
], id='hot-reload-content')
1992+
1993+
self.startServer(
1994+
app,
1995+
dev_tools_hot_reload=True,
1996+
dev_tools_hot_reload_interval=500,
1997+
dev_tools_hot_reload_max_retry=30,
1998+
)
1999+
2000+
hot_reload_file = os.path.join(
2001+
os.path.dirname(__file__), 'test_assets', 'hot_reload.css')
2002+
2003+
self.wait_for_style_to_equal(
2004+
'#hot-reload-content', 'background-color', 'rgba(0, 0, 255, 1)'
2005+
)
2006+
2007+
with open(hot_reload_file, 'r+') as f:
2008+
old_content = f.read()
2009+
f.truncate(0)
2010+
f.seek(0)
2011+
f.write(textwrap.dedent('''
2012+
#hot-reload-content {
2013+
background-color: red;
2014+
}
2015+
'''))
2016+
try:
2017+
self.wait_for_style_to_equal(
2018+
'#hot-reload-content', 'background-color', 'rgba(255, 0, 0, 1)'
2019+
)
2020+
finally:
2021+
with open(hot_reload_file, 'w') as f:
2022+
f.write(old_content)
2023+

0 commit comments

Comments
 (0)