Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Sajid Alam <[email protected]>
  • Loading branch information
SajidAlamQB committed Nov 6, 2024
1 parent e253ada commit ca2480e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions package/tests/test_launchers/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from kedro_viz.launchers.utils import (
_check_viz_up,
_find_available_port,
_find_kedro_project,
_is_project,
_start_browser,
Expand Down Expand Up @@ -99,3 +100,20 @@ def test_toml_bad_encoding(self, mocker):
def test_find_kedro_project(project_dir, is_project_found, expected, mocker):
mocker.patch("kedro_viz.launchers.utils._is_project", return_value=is_project_found)
assert _find_kedro_project(Path(project_dir)) == expected


def test_find_available_port_all_ports_occupied(mocker):
mocker.patch("kedro_viz.launchers.utils._is_port_in_use", return_value=True)
mock_display_message = mocker.patch("kedro_viz.launchers.utils.display_cli_message")

# Check for SystemExit when all ports are occupied
with pytest.raises(SystemExit) as exit_exception:
_find_available_port("127.0.0.1", 4141, max_attempts=5)
assert exit_exception.value.code == 1

mock_display_message.assert_any_call(
"Error: All ports in the range 4141-4145 are in use.", "red"
)
mock_display_message.assert_any_call(
"Please specify a different port using the '--port' option.", "red"
)

0 comments on commit ca2480e

Please sign in to comment.