Skip to content

Commit 8df65e1

Browse files
authored
test: add tests for #123 (#176)
* test: add tests for #123 * 🙈 skip test when not on linux * 🧹 rename test
1 parent 1c55cf2 commit 8df65e1

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/test_figure_resampler.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import datetime
77
import multiprocessing
8+
import subprocess
89
import time
910
from typing import List
1011

@@ -901,6 +902,33 @@ def test_stop_server_inline_persistent():
901902
proc.terminate()
902903

903904

905+
def test_showdash_not_hanging_when_port_in_use():
906+
if not_on_linux():
907+
pytest.skip("This test is currently only supported on linux")
908+
909+
port = 8032
910+
911+
start_fig = "from plotly_resampler import FigureResampler; "
912+
start_fig += (
913+
f"FigureResampler().show_dash(mode='external', port={port}, debug=False)"
914+
)
915+
916+
# Start the first figure in another python interpreter
917+
p1 = subprocess.Popen(["python", "-c", start_fig])
918+
# Wait a little bit
919+
time.sleep(3)
920+
921+
# Start the second figure in the current python interpreter
922+
with pytest.raises(SystemExit):
923+
# Start the second figure
924+
FigureResampler().show_dash(mode="external", port=port)
925+
# Wait a little bit
926+
time.sleep(3)
927+
928+
# Stop the first figure
929+
p1.kill()
930+
931+
904932
def test_manual_jupyterdashpersistentinline():
905933
# Manually call the JupyterDashPersistentInline its method
906934
# This requires some gimmicky stuff to mimmick the behaviour of a jupyter notebook.
@@ -1336,7 +1364,7 @@ def check_data(fr: FigureResampler, min_v=0, max_v=nb_datapoints - 1):
13361364

13371365
if not_on_linux():
13381366
# TODO: eventually we should run this test on Windows & MacOS too
1339-
return
1367+
pytest.skip("This test is currently only run on Linux")
13401368

13411369
f_pr.stop_server()
13421370
proc = multiprocessing.Process(target=f_pr.show_dash, kwargs=dict(mode="external"))
@@ -1424,7 +1452,7 @@ def check_data(fr: FigureResampler, min_v=0, max_v=nb_datapoints - 1):
14241452

14251453
if not_on_linux():
14261454
# TODO: eventually we should run this test on Windows & MacOS too
1427-
return
1455+
pytest.skip("This test is currently only run on Linux")
14281456

14291457
f_pr.stop_server()
14301458
proc = multiprocessing.Process(target=f_pr.show_dash, kwargs=dict(mode="external"))

0 commit comments

Comments
 (0)