Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Console Output to Indicate Hook Usage in Kedro-Viz #2235

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion package/kedro_viz/launchers/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
is_flag=True,
help="An experimental flag to open Kedro-Viz without Kedro project dependencies",
)
def run(
def run( # noqa: PLR0915
host,
port,
browser,
Expand Down Expand Up @@ -155,6 +155,16 @@ def run(
port = _find_available_port(host, port)

try:
if include_hooks:
hooks_message = "INFO: Running Kedro-Viz with hooks."
else:
hooks_message = (
"INFO: Running Kedro-Viz without hooks. "
"Try `kedro viz run --include-hooks` to include hook functionality."
)

display_cli_message(hooks_message, "yellow")

if port in _VIZ_PROCESSES and _VIZ_PROCESSES[port].is_alive():
_VIZ_PROCESSES[port].terminate()

Expand Down
41 changes: 40 additions & 1 deletion package/tests/test_launchers/test_cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def mock_click_echo(mocker):

@pytest.fixture
def mock_project_path(mocker):
mock_path = "/tmp/project_path"
mock_path = Path("/tmp/project_path")
mocker.patch("pathlib.Path.cwd", return_value=mock_path)
return mock_path

Expand Down Expand Up @@ -259,6 +259,45 @@ def test_kedro_viz_command_should_log_project_not_found(

mock_click_echo.assert_has_calls(mock_click_echo_calls)

def test_kedro_viz_command_logs_hooks_message(
self, mocker, mock_project_path, mock_click_echo
):
"""
Test that Kedro-Viz logs the correct message when
the `--include-hooks` flag is used or omitted.
"""
# Mock server setup and readiness checks
mocker.patch("kedro_viz.server.run_server")
mocker.patch(
"kedro_viz.launchers.utils._wait_for.__defaults__", (True, 1, True, 1)
)
mocker.patch(
"kedro_viz.launchers.utils._find_kedro_project",
return_value=mock_project_path,
)

runner = CliRunner()

# Test with --include-hooks
with runner.isolated_filesystem():
runner.invoke(main.viz_cli, ["viz", "run", "--include-hooks"])

assert any(
"INFO: Running Kedro-Viz with hooks." in call.args[0]
for call in mock_click_echo.mock_calls
), "Expected message about running with hooks not found."

# Test without --include-hooks
with runner.isolated_filesystem():
runner.invoke(main.viz_cli, ["viz", "run"])

assert any(
"INFO: Running Kedro-Viz without hooks. "
"Try `kedro viz run --include-hooks` to include hook functionality."
in call.args[0]
for call in mock_click_echo.mock_calls
), "Expected message about running without hooks not found."

def test_kedro_viz_command_should_log_outdated_version(
self, mocker, mock_http_response, mock_click_echo, mock_project_path
):
Expand Down
Loading