Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/IntegrationTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ def tearDown(s):
s.server_process.terminate()
time.sleep(2)

def startServer(s, dash):
def startServer(s, dash, **kwargs):
def run():
dash.scripts.config.serve_locally = True
dash.run_server(
kws = dict(
port=8050,
debug=False,
processes=4,
threaded=False
)
kws.update(kwargs)
dash.run_server(**kws)

# Run on a separate process so that it doesn't block
s.server_process = multiprocessing.Process(target=run)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_assets/hot_reload.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#hot-reload-content {
background-color: blue;
}
60 changes: 60 additions & 0 deletions tests/test_render.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import textwrap

from dash import Dash
from dash.dependencies import Input, Output, State, Event
import dash
Expand Down Expand Up @@ -45,6 +48,24 @@ def wait_for_text_to_equal(self, selector, assertion_text):

raise exception

def wait_for_style_to_equal(self, selector, style, assertion_style,
timeout=20):
start = time.time()
exception = Exception('Time ran out, {} on {} not found'.format(
assertion_style, selector))
while time.time() < start + timeout:
element = self.wait_for_element_by_css_selector(selector)
try:
self.assertEqual(assertion_style,
element.value_of_css_property(style))
except Exception as e:
exception = e
else:
return
time.sleep(0.25)

raise exception

def request_queue_assertions(
self, check_rejected=True, expected_length=None):
request_queue = self.driver.execute_script(
Expand Down Expand Up @@ -1961,3 +1982,42 @@ def render_content(tab):
)[0].click()

self.wait_for_text_to_equal('#graph2_info', json.dumps(graph_2_expected_clickdata))

def test_hot_reload(self):
app = dash.Dash(__name__, assets_folder='tests/test_assets')

app.layout = html.Div([
html.H3('Hot reload')
], id='hot-reload-content')

self.startServer(
app,
dev_tools_hot_reload=True,
dev_tools_hot_reload_interval=500,
dev_tools_hot_reload_max_retry=30,
)

hot_reload_file = os.path.join(
os.path.dirname(__file__), 'test_assets', 'hot_reload.css')

self.wait_for_style_to_equal(
'#hot-reload-content', 'background-color', 'rgba(0, 0, 255, 1)'
)

with open(hot_reload_file, 'r+') as f:
old_content = f.read()
f.truncate(0)
f.seek(0)
f.write(textwrap.dedent('''
#hot-reload-content {
background-color: red;
}
'''))
try:
self.wait_for_style_to_equal(
'#hot-reload-content', 'background-color', 'rgba(255, 0, 0, 1)'
)
finally:
with open(hot_reload_file, 'w') as f:
f.write(old_content)