Skip to content

Commit

Permalink
Add macos 14 (#529)
Browse files Browse the repository at this point in the history
* First draft of the solution

* Fix more unit tests

* fix bugs

* Fix unit test
  • Loading branch information
Marinovsky authored Dec 23, 2024
1 parent 58b2c21 commit d47aead
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04, macos-13, windows-latest]
os: [ubuntu-22.04, ubuntu-20.04, macos-13, macos-14, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
Expand Down
10 changes: 10 additions & 0 deletions tests/commands/cloud/live/test_cloud_live_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from unittest import mock
from click.testing import CliRunner
import pytest
import sys
from lean.commands import lean
from lean.container import container
from lean.models.api import QCEmailNotificationMethod, QCWebhookNotificationMethod, QCSMSNotificationMethod, QCTelegramNotificationMethod
Expand Down Expand Up @@ -97,6 +98,9 @@ def test_cloud_live_deploy() -> None:
mock.ANY,
mock.ANY)

@pytest.mark.skipif(
sys.platform =="darwin", reason="MacOS does not support IB tests."
)
def test_cloud_live_deploy_with_ib_using_hybrid_datafeed() -> None:
create_fake_lean_cli_directory()

Expand Down Expand Up @@ -243,6 +247,9 @@ def test_cloud_live_deploy_with_notifications(notice_method: str, configs: str)
("Zerodha", "USD:100"),
("TDAmeritrade", "USD:100")])
def test_cloud_live_deploy_with_live_cash_balance(brokerage: str, cash: str) -> None:
if (brokerage == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()

cloud_project_manager = mock.Mock()
Expand Down Expand Up @@ -324,6 +331,9 @@ def test_cloud_live_deploy_with_live_cash_balance(brokerage: str, cash: str) ->
("TDAmeritrade", ""),
("TDAmeritrade", "A:A 2T:1:145.1")])
def test_cloud_live_deploy_with_live_holdings(brokerage: str, holdings: str) -> None:
if (brokerage == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()

cloud_project_manager = mock.Mock()
Expand Down
7 changes: 7 additions & 0 deletions tests/commands/data/test_download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import sys
from unittest import mock
from unittest.mock import MagicMock

Expand Down Expand Up @@ -135,6 +136,9 @@ def _create_lean_data_download(data_provider_name: str,
return CliRunner().invoke(lean, run_parameters)


@pytest.mark.skipif(
sys.platform =="darwin", reason="MacOS does not support IB tests."
)
@pytest.mark.parametrize("data_provider,market,is_crypto,security_type,ticker,data_provider_parameters",
[("Polygon", "NYSE", False, "Equity", ["AAPL"], ["--polygon-api-key", "123"]),
("Binance", "Binance", True, "CryptoFuture", ["BTCUSDT"],
Expand All @@ -146,6 +150,9 @@ def _create_lean_data_download(data_provider_name: str,
["--ib-user-name", "123", "--ib-account", "Individual", "--ib-password", "123"])])
def test_download_data_non_interactive(data_provider: str, market: str, is_crypto: bool, security_type: str,
ticker: List[str], data_provider_parameters: List[str]):
if (data_provider == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

run_data_download = _create_lean_data_download(
data_provider, "Trade", "Minute", security_type, ticker, "20240101", "20240202",
_get_data_provider_config(is_crypto), market, data_provider_parameters)
Expand Down
85 changes: 75 additions & 10 deletions tests/commands/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# limitations under the License.

import itertools
import sys
import json
from pathlib import Path
import traceback
Expand Down Expand Up @@ -95,6 +96,9 @@ def create_fake_binance_environment(name: str, live_mode: bool) -> None:

path.write_text(config, encoding="utf-8")

@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_correct_algorithm_file() -> None:
# TODO: currently it is not using the live-paper envrionment
create_fake_lean_cli_directory()
Expand All @@ -118,7 +122,9 @@ def test_live_calls_lean_runner_with_correct_algorithm_file() -> None:
{},
{})


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_extra_docker_config() -> None:
# TODO: currently it is not using the live-paper environment
create_fake_lean_cli_directory()
Expand Down Expand Up @@ -153,7 +159,9 @@ def test_live_calls_lean_runner_with_extra_docker_config() -> None:
},
{})


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_paths_to_mount() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand Down Expand Up @@ -197,7 +205,9 @@ def test_live_aborts_when_environment_has_live_mode_set_to_false() -> None:

container.lean_runner.run_lean.assert_not_called()


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_default_output_directory() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand All @@ -213,7 +223,9 @@ def test_live_calls_lean_runner_with_default_output_directory() -> None:
# This will raise an error if the output directory is not relative to Python Project/backtests
args[3].relative_to(Path("Python Project/live").resolve())


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_custom_output_directory() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand All @@ -232,7 +244,9 @@ def test_live_calls_lean_runner_with_custom_output_directory() -> None:
# This will raise an error if the output directory is not relative to Python Project/custom-backtests
args[3].relative_to(Path("Python Project/custom").resolve())


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_release_mode() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand All @@ -253,7 +267,9 @@ def test_live_calls_lean_runner_with_release_mode() -> None:
{},
{})


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_calls_lean_runner_with_detach() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand Down Expand Up @@ -466,6 +482,9 @@ def test_live_sets_dependent_configurations_from_modules_json_based_on_environme
}


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
@pytest.mark.parametrize("data_provider", data_providers_required_options.keys())
def test_live_calls_lean_runner_with_data_provider(data_provider: str) -> None:
create_fake_lean_cli_directory()
Expand Down Expand Up @@ -501,6 +520,9 @@ def test_live_calls_lean_runner_with_data_provider(data_provider: str) -> None:

@pytest.mark.parametrize("brokerage", brokerage_required_options.keys() - ["Paper Trading"])
def test_live_non_interactive_aborts_when_missing_brokerage_options(brokerage: str) -> None:
if (brokerage == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()

required_options = brokerage_required_options[brokerage].items()
Expand Down Expand Up @@ -540,6 +562,8 @@ def test_live_non_interactive_aborts_when_missing_brokerage_options(brokerage: s

@pytest.mark.parametrize("data_feed", data_feed_required_options.keys())
def test_live_non_interactive_aborts_when_missing_data_feed_options(data_feed: str) -> None:
if (data_feed == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")
create_fake_lean_cli_directory()

container.initialize(docker_manager=mock.Mock(), lean_runner=mock.Mock())
Expand Down Expand Up @@ -568,6 +592,9 @@ def test_live_non_interactive_aborts_when_missing_data_feed_options(data_feed: s
@pytest.mark.parametrize("brokerage,data_feed",
itertools.product(brokerage_required_options.keys(), data_feed_required_options.keys()))
def test_live_non_interactive_do_not_store_non_persistent_properties_in_lean_config(brokerage: str, data_feed: str) -> None:
if ((brokerage == "Interactive Brokers" or data_feed == "Interactive Brokers") and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()
lean_runner = container.lean_runner

Expand Down Expand Up @@ -611,6 +638,9 @@ def test_live_non_interactive_do_not_store_non_persistent_properties_in_lean_con
@pytest.mark.parametrize("brokerage,data_feed",
itertools.product(brokerage_required_options.keys(), data_feed_required_options.keys()))
def test_live_non_interactive_calls_run_lean_when_all_options_given(brokerage: str, data_feed: str) -> None:
if ((brokerage == "Interactive Brokers" or data_feed == "Interactive Brokers") and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()
lean_runner = container.lean_runner

Expand Down Expand Up @@ -648,6 +678,9 @@ def test_live_non_interactive_calls_run_lean_when_all_options_given(brokerage: s
@pytest.mark.parametrize("brokerage,data_feed1,data_feed2",[(brokerage, *data_feeds) for brokerage, data_feeds in
itertools.product(brokerage_required_options.keys(), itertools.combinations(data_feed_required_options.keys(), 2))])
def test_live_non_interactive_calls_run_lean_when_all_options_given_with_multiple_data_feeds(brokerage: str, data_feed1: str, data_feed2: str) -> None:
if ((brokerage == "Interactive Brokers" or data_feed1 == "Interactive Brokers" or data_feed2 == "Interactive Brokers") and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()
lean_runner = container.lean_runner

Expand Down Expand Up @@ -689,6 +722,9 @@ def test_live_non_interactive_calls_run_lean_when_all_options_given_with_multipl

@pytest.mark.parametrize("brokerage", brokerage_required_options.keys() - ["Paper Trading"])
def test_live_non_interactive_falls_back_to_lean_config_for_brokerage_settings(brokerage: str) -> None:
if (brokerage == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()

required_options = brokerage_required_options[brokerage].items()
Expand Down Expand Up @@ -748,6 +784,9 @@ def test_live_non_interactive_falls_back_to_lean_config_for_brokerage_settings(b

@pytest.mark.parametrize("data_feed", data_feed_required_options.keys())
def test_live_non_interactive_falls_back_to_lean_config_for_data_feed_settings(data_feed: str) -> None:
if (data_feed == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()

required_options = data_feed_required_options[data_feed].items()
Expand Down Expand Up @@ -796,6 +835,9 @@ def test_live_non_interactive_falls_back_to_lean_config_for_data_feed_settings(d

@pytest.mark.parametrize("data_feed1,data_feed2", itertools.combinations(data_feed_required_options.keys(), 2))
def test_live_non_interactive_falls_back_to_lean_config_for_multiple_data_feed_settings(data_feed1: str, data_feed2: str) -> None:
if ((data_feed1 == "Interactive Brokers" or data_feed2 == "Interactive Brokers") and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()

required_options = list(data_feed_required_options[data_feed1].items()) + list(data_feed_required_options[data_feed2].items())
Expand Down Expand Up @@ -844,7 +886,9 @@ def test_live_non_interactive_falls_back_to_lean_config_for_multiple_data_feed_s
{},
{})


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_forces_update_when_update_option_given() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand All @@ -865,7 +909,9 @@ def test_live_forces_update_when_update_option_given() -> None:
{},
{})


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_passes_custom_image_to_lean_runner_when_set_in_config() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand All @@ -887,7 +933,9 @@ def test_live_passes_custom_image_to_lean_runner_when_set_in_config() -> None:
{},
{})


@pytest.mark.skipif(
sys.platform == "darwin", reason="MacOS does not support IB tests."
)
def test_live_passes_custom_image_to_lean_runner_when_given_as_option() -> None:
create_fake_lean_cli_directory()
create_fake_environment("live-paper", True)
Expand All @@ -910,7 +958,9 @@ def test_live_passes_custom_image_to_lean_runner_when_given_as_option() -> None:
{},
{})


@pytest.mark.skipif(
sys.platform =="darwin", reason="MacOS does not support IB tests."
)
@pytest.mark.parametrize("python_venv", ["Custom-venv",
"/Custom-venv",
None])
Expand Down Expand Up @@ -962,6 +1012,9 @@ def test_live_passes_custom_python_venv_to_lean_runner_when_given_as_option(pyth
("TDAmeritrade", ""),
("TDAmeritrade", "USD:100")])
def test_live_passes_live_cash_balance_to_lean_runner_when_given_as_option(brokerage: str, cash: str) -> None:
if (brokerage == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()
lean_runner= container.lean_runner

Expand Down Expand Up @@ -1026,6 +1079,9 @@ def test_live_passes_live_cash_balance_to_lean_runner_when_given_as_option(broke
("TDAmeritrade", ""),
("TDAmeritrade", "A:A 2T:1:145.1")])
def test_live_passes_live_holdings_to_lean_runner_when_given_as_option(brokerage: str, holdings: str) -> None:
if (brokerage == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

create_fake_lean_cli_directory()
lean_runner= container.lean_runner

Expand Down Expand Up @@ -1182,6 +1238,9 @@ def create_lean_option(brokerage_name: str, data_provider_live_name: str, data_p
("Tradier", "IEX", "AlphaVantage", "185", "333", "334"),
("Paper Trading", "IEX", "Local", None, "333", "222")])
def test_live_deploy_with_different_brokerage_and_different_live_data_provider_and_historical_data_provider(brokerage_name: str, data_provider_live_name: str, data_provider_historical_name: str, brokerage_product_id: str, data_provider_live_product_id: str, data_provider_historical_id: str) -> None:
if (brokerage_name == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

api_client = mock.MagicMock()
create_lean_option(brokerage_name, data_provider_live_name, data_provider_historical_name, api_client)

Expand Down Expand Up @@ -1211,6 +1270,9 @@ def test_live_deploy_with_different_brokerage_and_different_live_data_provider_a
[("Interactive Brokers", "IEX", "181", "333"),
("Tradier", "IEX", "185", "333")])
def test_live_non_interactive_deploy_with_different_brokerage_and_different_live_data_provider(brokerage_name: str, data_provider_live_name: str, brokerage_product_id: str, data_provider_live_product_id: str) -> None:
if (brokerage_name == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

api_client = mock.MagicMock()
create_lean_option(brokerage_name, data_provider_live_name, None, api_client)

Expand All @@ -1229,6 +1291,9 @@ def test_live_non_interactive_deploy_with_different_brokerage_and_different_live
("Interactive Brokers", "Interactive Brokers", "181"),
("Tradier", "Tradier", "185")])
def test_live_non_interactive_deploy_with_different_brokerage_with_the_same_live_data_provider(brokerage_name: str, data_provider_live_name: str, brokerage_product_id: str) -> None:
if (brokerage_name == "Interactive Brokers" and sys.platform == "darwin"):
pytest.skip("MacOS does not support IB tests")

api_client = mock.MagicMock()
create_lean_option(brokerage_name, data_provider_live_name, None, api_client)

Expand Down

0 comments on commit d47aead

Please sign in to comment.