Skip to content

Commit 57c0ea4

Browse files
committed
Fix tests with dynamic port.
1 parent 77984d1 commit 57c0ea4

File tree

7 files changed

+64
-26
lines changed

7 files changed

+64
-26
lines changed

components/dash-core-components/tests/integration/link/test_absolute_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def extras(t):
4949
dcc.Link(
5050
children="Absolute Path",
5151
id="link1",
52-
href=dash_dcc.server.url + "/extra/eseehc",
52+
href="/extra/eseehc",
5353
refresh=True,
5454
),
5555
dcc.Location(id="url", refresh=False),

components/dash-core-components/tests/integration/link/test_link_event.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def display_page(pathname):
9393
dash_dcc.wait_for_text_to_equal("#page-content", "You are on page /test-link")
9494

9595
wait.until(
96-
lambda: test_link.get_attribute("href") == "http://localhost:8050/test-link", 3
96+
lambda: test_link.get_attribute("href")
97+
== "http://localhost:{}/test-link".format(dash_dcc.server.port),
98+
3,
9799
)
98100
wait.until(lambda: call_count.value == 2, 3)
99101

components/dash-core-components/tests/integration/location/test_location_callback.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def update_pathname(n_clicks, current_pathname):
9393
# Check that link updates pathname
9494
dash_dcc.find_element("#test-link").click()
9595
until(
96-
lambda: dash_dcc.driver.current_url.replace("http://localhost:8050", "")
96+
lambda: dash_dcc.driver.current_url.replace(
97+
"http://localhost:{}".format(dash_dcc.server.port), ""
98+
)
9799
== "/test/pathname",
98100
3,
99101
)

tests/integration/callbacks/test_basic_callback.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,18 @@ def test_cbsc008_wildcard_prop_callbacks(dash_duo):
400400
)
401401

402402
input_call_count = Value("i", 0)
403+
percy_enabled = Value("b", False)
404+
405+
def snapshot(name):
406+
percy_enabled.value = os.getenv("PERCY_ENABLE", "") != ""
407+
dash_duo.percy_snapshot(name=name)
408+
percy_enabled.value = False
403409

404410
@app.callback(Output("output-1", "data-cb"), [Input("input", "value")])
405411
def update_data(value):
406412
with lock:
407-
input_call_count.value += 1
413+
if not percy_enabled.value:
414+
input_call_count.value += 1
408415
return value
409416

410417
@app.callback(Output("output-1", "children"), [Input("output-1", "data-cb")])
@@ -413,7 +420,7 @@ def update_text(data):
413420

414421
dash_duo.start_server(app)
415422
dash_duo.wait_for_text_to_equal("#output-1", "initial value")
416-
dash_duo.percy_snapshot(name="wildcard-callback-1")
423+
snapshot("wildcard-callback-1")
417424

418425
input1 = dash_duo.find_element("#input")
419426
dash_duo.clear_input(input1)
@@ -423,7 +430,7 @@ def update_text(data):
423430
input1.send_keys(key)
424431

425432
dash_duo.wait_for_text_to_equal("#output-1", "hello world")
426-
dash_duo.percy_snapshot(name="wildcard-callback-2")
433+
snapshot("wildcard-callback-2")
427434

428435
# an initial call, one for clearing the input
429436
# and one for each hello world character
@@ -612,6 +619,13 @@ def test_cbsc014_multiple_properties_update_at_same_time_on_same_component(dash_
612619
timestamp_1 = Value("d", -5)
613620
timestamp_2 = Value("d", -5)
614621

622+
percy_enabled = Value("b")
623+
624+
def snapshot(name):
625+
percy_enabled.value = os.getenv("PERCY_ENABLE", "") != ""
626+
dash_duo.percy_snapshot(name=name)
627+
percy_enabled.value = False
628+
615629
app = Dash(__name__)
616630
app.layout = html.Div(
617631
[
@@ -629,9 +643,10 @@ def test_cbsc014_multiple_properties_update_at_same_time_on_same_component(dash_
629643
Input("button-2", "n_clicks_timestamp"),
630644
)
631645
def update_output(n1, t1, n2, t2):
632-
call_count.value += 1
633-
timestamp_1.value = t1
634-
timestamp_2.value = t2
646+
if not percy_enabled.value:
647+
call_count.value += 1
648+
timestamp_1.value = t1
649+
timestamp_2.value = t2
635650
return "{}, {}".format(n1, n2)
636651

637652
dash_duo.start_server(app)
@@ -640,22 +655,22 @@ def update_output(n1, t1, n2, t2):
640655
assert timestamp_1.value == -1
641656
assert timestamp_2.value == -1
642657
assert call_count.value == 1
643-
dash_duo.percy_snapshot("Dash button-1 initialization 1")
658+
snapshot("Dash button-1 initialization 1")
644659

645660
dash_duo.find_element("#button-1").click()
646661
dash_duo.wait_for_text_to_equal("#container", "1, 0")
647662
assert timestamp_1.value > ((time.time() - (24 * 60 * 60)) * 1000)
648663
assert timestamp_2.value == -1
649664
assert call_count.value == 2
650-
dash_duo.percy_snapshot("Dash button-1 click")
665+
snapshot("Dash button-1 click")
651666
prev_timestamp_1 = timestamp_1.value
652667

653668
dash_duo.find_element("#button-2").click()
654669
dash_duo.wait_for_text_to_equal("#container", "1, 1")
655670
assert timestamp_1.value == prev_timestamp_1
656671
assert timestamp_2.value > ((time.time() - 24 * 60 * 60) * 1000)
657672
assert call_count.value == 3
658-
dash_duo.percy_snapshot("Dash button-2 click")
673+
snapshot("Dash button-2 click")
659674
prev_timestamp_2 = timestamp_2.value
660675

661676
dash_duo.find_element("#button-2").click()
@@ -664,7 +679,7 @@ def update_output(n1, t1, n2, t2):
664679
assert timestamp_2.value > prev_timestamp_2
665680
assert timestamp_2.value > timestamp_1.value
666681
assert call_count.value == 4
667-
dash_duo.percy_snapshot("Dash button-2 click again")
682+
snapshot("Dash button-2 click again")
668683

669684

670685
def test_cbsc015_input_output_callback(dash_duo):

tests/integration/callbacks/test_layout_paths_with_callbacks.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ def test_cblp001_radio_buttons_callbacks_generating_children(dash_duo):
1010
with open(os.path.join(os.path.dirname(__file__), "state_path.json")) as fp:
1111
EXPECTED_PATHS = json.load(fp)
1212

13+
percy_enabled = Value("b")
14+
15+
def snapshot(name):
16+
percy_enabled.value = os.getenv("PERCY_ENABLE", "") != ""
17+
dash_duo.percy_snapshot(name=name)
18+
percy_enabled.value = False
19+
1320
app = Dash(__name__)
1421
app.layout = html.Div(
1522
[
@@ -96,14 +103,16 @@ def test_cblp001_radio_buttons_callbacks_generating_children(dash_duo):
96103

97104
@app.callback(Output("body", "children"), [Input("toc", "value")])
98105
def display_chapter(toc_value):
99-
call_counts["body"].value += 1
106+
if not percy_enabled.value:
107+
call_counts["body"].value += 1
100108
return chapters[toc_value]
101109

102110
app.config.suppress_callback_exceptions = True
103111

104112
def generate_graph_callback(counterId):
105113
def callback(value):
106-
call_counts[counterId].value += 1
114+
if not percy_enabled.value:
115+
call_counts[counterId].value += 1
107116
return {
108117
"data": [
109118
{
@@ -124,7 +133,8 @@ def callback(value):
124133

125134
def generate_label_callback(id_):
126135
def update_label(value):
127-
call_counts[id_].value += 1
136+
if not percy_enabled.value:
137+
call_counts[id_].value += 1
128138
return value
129139

130140
return update_label
@@ -187,7 +197,7 @@ def check_call_counts(chapters, count):
187197

188198
assert dash_duo.redux_state_paths == EXPECTED_PATHS["chapter1"]
189199
check_chapter("chapter1")
190-
dash_duo.percy_snapshot(name="chapter-1")
200+
snapshot(name="chapter-1")
191201

192202
dash_duo.find_elements('input[type="radio"]')[1].click() # switch chapters
193203

@@ -198,7 +208,7 @@ def check_call_counts(chapters, count):
198208

199209
assert dash_duo.redux_state_paths == EXPECTED_PATHS["chapter2"]
200210
check_chapter("chapter2")
201-
dash_duo.percy_snapshot(name="chapter-2")
211+
snapshot(name="chapter-2")
202212

203213
# switch to 3
204214
dash_duo.find_elements('input[type="radio"]')[2].click()
@@ -210,11 +220,11 @@ def check_call_counts(chapters, count):
210220

211221
assert dash_duo.redux_state_paths == EXPECTED_PATHS["chapter3"]
212222
check_chapter("chapter3")
213-
dash_duo.percy_snapshot(name="chapter-3")
223+
snapshot(name="chapter-3")
214224

215225
dash_duo.find_elements('input[type="radio"]')[3].click() # switch to 4
216226
dash_duo.wait_for_text_to_equal("#body", "Just a string")
217-
dash_duo.percy_snapshot(name="chapter-4")
227+
snapshot(name="chapter-4")
218228

219229
paths = dash_duo.redux_state_paths
220230
assert paths["objs"] == {}
@@ -234,4 +244,4 @@ def check_call_counts(chapters, count):
234244
lambda: dash_duo.redux_state_paths == EXPECTED_PATHS["chapter1"], TIMEOUT
235245
)
236246
check_chapter("chapter1")
237-
dash_duo.percy_snapshot(name="chapter-1-again")
247+
snapshot(name="chapter-1-again")

tests/integration/renderer/test_dependencies.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from multiprocessing import Value
23

34
from dash import Dash, html, dcc, Input, Output
@@ -10,10 +11,17 @@ def test_rddp001_dependencies_on_components_that_dont_exist(dash_duo):
1011
)
1112

1213
output_1_call_count = Value("i", 0)
14+
percy_enabled = Value("b")
15+
16+
def snapshot(name):
17+
percy_enabled.value = os.getenv("PERCY_ENABLE", "") != ""
18+
dash_duo.percy_snapshot(name=name)
19+
percy_enabled.value = False
1320

1421
@app.callback(Output("output-1", "children"), [Input("input", "value")])
1522
def update_output(value):
16-
output_1_call_count.value += 1
23+
if not percy_enabled.value:
24+
output_1_call_count.value += 1
1725
return value
1826

1927
# callback for component that doesn't yet exist in the dom
@@ -23,14 +31,15 @@ def update_output(value):
2331

2432
@app.callback(Output("output-2", "children"), [Input("input", "value")])
2533
def update_output_2(value):
26-
output_2_call_count.value += 1
34+
if not percy_enabled.value:
35+
output_2_call_count.value += 1
2736
return value
2837

2938
dash_duo.start_server(app)
3039

3140
assert dash_duo.find_element("#output-1").text == "initial value"
3241
assert output_1_call_count.value == 1 and output_2_call_count.value == 0
33-
dash_duo.percy_snapshot(name="dependencies")
42+
snapshot("dependencies")
3443

3544
dash_duo.find_element("#input").send_keys("a")
3645
assert dash_duo.find_element("#output-1").text == "initial valuea"

tests/integration/test_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ def test_inin025_url_base_pathname(dash_br, dash_thread_server):
266266

267267
dash_thread_server(app)
268268

269-
dash_br.server_url = "http://localhost:8050/app1/"
269+
dash_br.server_url = "http://localhost:{}/app1/".format(dash_thread_server.port)
270270
dash_br.wait_for_text_to_equal("#out", "The first")
271271

272-
dash_br.server_url = "http://localhost:8050/app2/"
272+
dash_br.server_url = "http://localhost:{}/app2/".format(dash_thread_server.port)
273273
dash_br.wait_for_text_to_equal("#out", "The second")
274274

275275

0 commit comments

Comments
 (0)