Skip to content

Commit

Permalink
Missed renaming of data-queue-handler (#420)
Browse files Browse the repository at this point in the history
* fix: missed data-provider-live error
PR: #416

* feat: validate raise error test

* feat: develop rename function utility
  • Loading branch information
Romazes authored Feb 16, 2024
1 parent d1034be commit 0363261
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lean/commands/live/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down
34 changes: 34 additions & 0 deletions lean/components/util/name_rename.py
Original file line number Diff line number Diff line change
@@ -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


15 changes: 15 additions & 0 deletions tests/commands/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 0363261

Please sign in to comment.