|
| 1 | +import os |
| 2 | +import textwrap |
| 3 | + |
1 | 4 | from dash import Dash
|
2 | 5 | from dash.dependencies import Input, Output, State, Event
|
3 | 6 | import dash
|
@@ -45,6 +48,24 @@ def wait_for_text_to_equal(self, selector, assertion_text):
|
45 | 48 |
|
46 | 49 | raise exception
|
47 | 50 |
|
| 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 | + |
48 | 69 | def request_queue_assertions(
|
49 | 70 | self, check_rejected=True, expected_length=None):
|
50 | 71 | request_queue = self.driver.execute_script(
|
@@ -1961,3 +1982,42 @@ def render_content(tab):
|
1961 | 1982 | )[0].click()
|
1962 | 1983 |
|
1963 | 1984 | 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