From 89ae7dbbeebfd9220566a65e895983be149c8fe9 Mon Sep 17 00:00:00 2001 From: rashidakanchwala Date: Thu, 9 Jan 2025 11:52:42 +0000 Subject: [PATCH 1/2] done Signed-off-by: rashidakanchwala --- package/kedro_viz/launchers/cli/run.py | 12 +++++- .../tests/test_launchers/test_cli/test_run.py | 40 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/package/kedro_viz/launchers/cli/run.py b/package/kedro_viz/launchers/cli/run.py index 466d7f7aa..f491d21b4 100644 --- a/package/kedro_viz/launchers/cli/run.py +++ b/package/kedro_viz/launchers/cli/run.py @@ -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, @@ -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. If you spot missing functionality, " + "try `kedro viz run --include-hooks`." + ) + + display_cli_message(hooks_message, "yellow") + if port in _VIZ_PROCESSES and _VIZ_PROCESSES[port].is_alive(): _VIZ_PROCESSES[port].terminate() diff --git a/package/tests/test_launchers/test_cli/test_run.py b/package/tests/test_launchers/test_cli/test_run.py index ccf579b0f..fdb2343ed 100644 --- a/package/tests/test_launchers/test_cli/test_run.py +++ b/package/tests/test_launchers/test_cli/test_run.py @@ -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 @@ -259,6 +259,44 @@ 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. If you spot missing functionality, try `kedro viz run --include-hooks`." + 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 ): From 6c0b6c077e8305899a4ff86191cf29c7076f86bd Mon Sep 17 00:00:00 2001 From: rashidakanchwala Date: Fri, 10 Jan 2025 13:49:46 +0000 Subject: [PATCH 2/2] fixed messaging based on reviews" Signed-off-by: rashidakanchwala --- package/kedro_viz/launchers/cli/run.py | 4 ++-- package/tests/test_launchers/test_cli/test_run.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package/kedro_viz/launchers/cli/run.py b/package/kedro_viz/launchers/cli/run.py index f491d21b4..4f73de8b6 100644 --- a/package/kedro_viz/launchers/cli/run.py +++ b/package/kedro_viz/launchers/cli/run.py @@ -159,8 +159,8 @@ def run( # noqa: PLR0915 hooks_message = "INFO: Running Kedro-Viz with hooks." else: hooks_message = ( - "INFO: Running Kedro-Viz without hooks. If you spot missing functionality, " - "try `kedro viz run --include-hooks`." + "INFO: Running Kedro-Viz without hooks. " + "Try `kedro viz run --include-hooks` to include hook functionality." ) display_cli_message(hooks_message, "yellow") diff --git a/package/tests/test_launchers/test_cli/test_run.py b/package/tests/test_launchers/test_cli/test_run.py index fdb2343ed..c080f5239 100644 --- a/package/tests/test_launchers/test_cli/test_run.py +++ b/package/tests/test_launchers/test_cli/test_run.py @@ -292,7 +292,8 @@ def test_kedro_viz_command_logs_hooks_message( runner.invoke(main.viz_cli, ["viz", "run"]) assert any( - "INFO: Running Kedro-Viz without hooks. If you spot missing functionality, try `kedro viz run --include-hooks`." + "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."