def _get_image_name(self, option: Option, default: str, override: Optional[str]) -> DockerImage: """Returns the image to use. :param option: the CLI option that configures the image type :param override: the image name to use, overriding any defaults or previously configured options :param default: the default image to use when the option is not set and no override is given :return: the image to use """ if override is not None: image = override else: image = option.get_value(default) return DockerImage.parse(image)
import pytest from click.testing import CliRunner from dependency_injector import providers from lean.commands import lean from lean.components.config.storage import Storage from lean.constants import DEFAULT_ENGINE_IMAGE from lean.container import container from lean.models.docker import DockerImage from lean.models.optimizer import (OptimizationConstraint, OptimizationExtremum, OptimizationParameter, OptimizationTarget) from tests.test_helpers import create_fake_lean_cli_directory ENGINE_IMAGE = DockerImage.parse(DEFAULT_ENGINE_IMAGE) @pytest.fixture(autouse=True) def update_manager_mock() -> mock.Mock: """A pytest fixture which mocks the update manager before every test.""" update_manager = mock.Mock() container.update_manager.override(providers.Object(update_manager)) return update_manager @pytest.fixture(autouse=True) def optimizer_config_manager_mock() -> mock.Mock: """A pytest fixture which mocks the optimizer config manager before every test.""" optimizer_config_manager = mock.Mock() optimizer_config_manager.configure_strategy.return_value = "QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy"
def test_get_research_image_returns_default_image_when_nothing_configured( ) -> None: cli_config_manager = CLIConfigManager(create_storage(), create_storage()) assert cli_config_manager.get_research_image() == DockerImage.parse( DEFAULT_RESEARCH_IMAGE)
def test_docker_image_name_parse_parses_value(value: str, name: str, tag: str) -> None: result = DockerImage.parse(value) assert result.name == name assert result.tag == tag
import json from pathlib import Path from typing import Optional from unittest import mock import pytest from click.testing import CliRunner from dependency_injector import providers from lean.commands import lean from lean.constants import DEFAULT_RESEARCH_IMAGE from lean.container import container from lean.models.docker import DockerImage from tests.test_helpers import create_fake_lean_cli_directory RESEARCH_IMAGE = DockerImage.parse(DEFAULT_RESEARCH_IMAGE) @pytest.fixture(autouse=True) def update_manager_mock() -> mock.Mock: """A pytest fixture which mocks the update manager before every test.""" update_manager = mock.Mock() container.update_manager.override(providers.Object(update_manager)) return update_manager def test_research_runs_research_container() -> None: create_fake_lean_cli_directory() docker_manager = mock.Mock() container.docker_manager.override(providers.Object(docker_manager))