Skip to content

Commit

Permalink
Adds port env var tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenMatsuda committed Mar 19, 2020
1 parent 1bbe729 commit 5f72204
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dash/_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def load_dash_env_vars():
"DASH_SILENCE_ROUTES_LOGGING",
"DASH_PRUNE_ERRORS",
"DASH_COMPRESS",
"HOST",
"PORT",
)
}
)
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,11 @@ def g2(a):
@app.callback(Output("inner-div", "children"), [Input("inner-input", "value")])
def h(a):
return a


def test_inin_024_port_env_success(dash_duo):
app = Dash(__name__)
app.layout = html.Div("hi", "out")
dash_duo.start_server(app, port="12345")
assert dash_duo.server_url == "http://localhost:12345"
dash_duo.wait_for_text_to_equal("#out", "hi")
27 changes: 27 additions & 0 deletions tests/unit/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,30 @@ def test_strip_relative_path(prefix, partial_path, expected):
def test_invalid_strip_relative_path(prefix, partial_path):
with pytest.raises(_exc.UnsupportedRelativePath):
strip_relative_path(prefix, partial_path)


def test_port_env_fail_str(empty_environ):
app = Dash()
with pytest.raises(Exception) as excinfo:
app.run_server(port="garbage")
assert (
excinfo.exconly()
== "ValueError: Expecting an integer from 1 to 65535, found port='garbage'"
)


def test_port_env_fail_range(empty_environ):
app = Dash()
with pytest.raises(Exception) as excinfo:
app.run_server(port="0")
assert (
excinfo.exconly()
== "AssertionError: Expecting an integer from 1 to 65535, found port=0"
)

with pytest.raises(Exception) as excinfo:
app.run_server(port="65536")
assert (
excinfo.exconly()
== "AssertionError: Expecting an integer from 1 to 65535, found port=65536"
)

0 comments on commit 5f72204

Please sign in to comment.