From 036326149d5d4494016d7e9e739310f79e963ed9 Mon Sep 17 00:00:00 2001 From: Roman Yavnikov <45608740+Romazes@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:41:54 +0200 Subject: [PATCH] Missed renaming of data-queue-handler (#420) * fix: missed data-provider-live error PR: #416 * feat: validate raise error test * feat: develop rename function utility --- lean/commands/live/deploy.py | 5 +++-- lean/components/util/name_rename.py | 34 +++++++++++++++++++++++++++++ tests/commands/test_live.py | 15 +++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 lean/components/util/name_rename.py diff --git a/lean/commands/live/deploy.py b/lean/commands/live/deploy.py index 5ae1c916..0e7d61c0 100644 --- a/lean/commands/live/deploy.py +++ b/lean/commands/live/deploy.py @@ -15,6 +15,7 @@ from typing import Any, Dict, List, Optional, Tuple from click import option, argument, Choice from lean.click import LeanCommand, PathParameter, ensure_options +from lean.components.util.name_rename import rename_internal_config_to_user_friendly_format from lean.constants import DEFAULT_ENGINE_IMAGE from lean.container import container from lean.models.brokerages.local import all_local_brokerages, local_brokerage_data_feeds, all_local_data_feeds @@ -49,7 +50,7 @@ def _get_configurable_modules_from_environment(lean_config: Dict[str, Any], envi environment = lean_config["environments"][environment_name] for key in ["live-mode-brokerage", "data-queue-handler"]: if key not in environment: - raise MoreInfoError(f"The '{environment_name}' environment does not specify a {key}", + raise MoreInfoError(f"The '{environment_name}' environment does not specify a {rename_internal_config_to_user_friendly_format(key)}", "https://www.lean.io/docs/v2/lean-cli/live-trading/algorithm-control") brokerage = environment["live-mode-brokerage"] @@ -343,7 +344,7 @@ def deploy(project: Path, lean_environment = lean_config["environments"][environment_name] for key in ["live-mode-brokerage", "data-queue-handler"]: if key not in lean_environment: - raise MoreInfoError(f"The '{environment_name}' environment does not specify a {key}", + raise MoreInfoError(f"The '{environment_name}' environment does not specify a {rename_internal_config_to_user_friendly_format(key)}", "https://www.lean.io/docs/v2/lean-cli/live-trading/algorithm-control") brokerage = lean_environment["live-mode-brokerage"] diff --git a/lean/components/util/name_rename.py b/lean/components/util/name_rename.py new file mode 100644 index 00000000..3c4b4428 --- /dev/null +++ b/lean/components/util/name_rename.py @@ -0,0 +1,34 @@ +# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. +# Lean CLI v1.0. Copyright 2021 QuantConnect Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +def rename_internal_config_to_user_friendly_format(key: str) -> str: + """ + Function to rename a string if it matches a specific key. + + Parameters: + key (str): The input string. + + Returns: + str: The renamed string if it matches the specific key and passes the validation, + otherwise returns the original string. + """ + if key is None or len(key) == 0: + raise ValueError("Input string is null or empty") + + # Check if the input string matches the specific key + if key == "data-queue-handler": + return "data-provider-live" + else: + return key + + \ No newline at end of file diff --git a/tests/commands/test_live.py b/tests/commands/test_live.py index c418abdb..c914c0d3 100644 --- a/tests/commands/test_live.py +++ b/tests/commands/test_live.py @@ -521,6 +521,21 @@ def test_live_non_interactive_aborts_when_missing_data_feed_options(data_feed: s container.lean_runner.run_lean.assert_not_called() +def test_live_non_interactive_raise_error_when_missing_data_provider_live_options() -> None: + create_fake_lean_cli_directory() + + container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock()) + + result = CliRunner().invoke(lean, ["live", "deploy" , "--brokerage", "Paper Trading", "Python Project"]) + + error_msg = str(result.exc_info[1]).split() + + assert "data-provider-live" in error_msg + assert "data-queue-handler" not in error_msg + + assert result.exit_code != 0 + + @pytest.mark.parametrize("brokerage,data_feed", itertools.product(brokerage_required_options.keys(), data_feed_required_options.keys()))