Skip to content

Commit 22ed22a

Browse files
authored
Fix CI (#575)
* Fix failing CI Click's latest version 8.2.1 requires specifying proper input for tests using prompt * Minor fixes * Minor change * Minor change * Minor change * Minor change
1 parent 14072d6 commit 22ed22a

7 files changed

Lines changed: 49 additions & 17 deletions

File tree

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ pytest>=7.1.2,<8
88
pyfakefs>=5.4.1,<6
99
responses~=0.21
1010
lxml-stubs==0.4.0
11+
# Match pandas version to use same as Lean (2.1.4). Except that 2.1.* is only supported on Python 3.9+.
12+
pandas==2.1.4;python_version>='3.9'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_stubs_version_range() -> str:
5757
"joblib>=1.1.0",
5858
"setuptools",
5959
f"quantconnect-stubs{get_stubs_version_range()}",
60-
"cryptography>=41.0.4,<43.0.0",
60+
"cryptography>=41.0.4",
6161
]
6262

6363
setup(

tests/commands/cloud/test_optimize.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_cloud_optimize_runs_optimization_by_project_id() -> None:
9999
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
100100
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
101101

102-
result = CliRunner().invoke(lean, ["cloud", "optimize", "1"])
102+
result = CliRunner().invoke(lean, ["cloud", "optimize", "1"], input="\n")
103103

104104
assert result.exit_code == 0
105105

@@ -125,7 +125,7 @@ def test_cloud_optimize_runs_optimization_by_project_name() -> None:
125125
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
126126
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
127127

128-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"])
128+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"], input="\n")
129129

130130
assert result.exit_code == 0
131131

@@ -152,7 +152,7 @@ def test_cloud_optimize_uses_given_name() -> None:
152152
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
153153
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
154154

155-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project", "--name", "My Name"])
155+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project", "--name", "My Name"], input="\n")
156156

157157
assert result.exit_code == 0
158158

@@ -181,7 +181,7 @@ def test_cloud_optimize_pushes_nothing_when_project_does_not_exist_locally() ->
181181
push_manager_to_use=push_manager)
182182
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
183183

184-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project", "--push"])
184+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project", "--push"], input="\n")
185185

186186
assert result.exit_code == 0
187187

@@ -204,7 +204,7 @@ def test_cloud_optimize_passes_given_config_to_cloud_runner() -> None:
204204
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
205205
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
206206

207-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project", "--name", "My Name"])
207+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project", "--name", "My Name"], input="\n")
208208

209209
assert result.exit_code == 0
210210

@@ -252,7 +252,7 @@ def test_cloud_optimize_displays_optimal_backtest_results(target: str,
252252
extremum=extremum,
253253
)
254254

255-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"])
255+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"], input="\n")
256256

257257
assert result.exit_code == 0
258258

@@ -280,7 +280,7 @@ def test_cloud_optimize_does_not_display_backtest_results_when_none_succeed() ->
280280
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
281281
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
282282

283-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"])
283+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"], input="\n")
284284

285285
assert result.exit_code == 0
286286

@@ -306,7 +306,7 @@ def test_cloud_optimize_does_not_display_backtest_results_when_none_meet_constra
306306
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
307307
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
308308

309-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"])
309+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"], input="\n")
310310

311311
assert result.exit_code == 0
312312

@@ -332,7 +332,7 @@ def run_optimization(*args, **kwargs):
332332
container = initialize_container(cloud_runner_to_use=cloud_runner, api_client_to_use=api_client)
333333
container.optimizer_config_manager = _get_optimizer_config_manager_mock()
334334

335-
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"])
335+
result = CliRunner().invoke(lean, ["cloud", "optimize", "My Project"], input="\n")
336336

337337
assert result.exit_code != 0
338338

tests/commands/data/test_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _create_lean_data_download(data_provider_name: str,
133133
if extra_run_command:
134134
run_parameters += extra_run_command
135135

136-
return CliRunner().invoke(lean, run_parameters)
136+
return CliRunner().invoke(lean, run_parameters, input="\n")
137137

138138

139139
@pytest.mark.skipif(

tests/commands/test_init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_init_prompts_for_organization_if_option_not_passed() -> None:
164164
organization = _get_test_organization()
165165

166166
with mock.patch.object(Logger, 'prompt_list', return_value=organization.id) as mock_prompt_list:
167-
result = CliRunner().invoke(lean, ["init"])
167+
result = CliRunner().invoke(lean, ["init"], input="\n")
168168

169169
assert result.exit_code == 0
170170

@@ -178,7 +178,8 @@ def test_init_uses_organization_given_as_option(use_name: bool) -> None:
178178

179179
with mock.patch.object(Logger, 'prompt_list', return_value=None) as mock_prompt_list:
180180
result = CliRunner().invoke(lean,
181-
["init", "--organization", organization.name if use_name else organization.id])
181+
["init", "--organization", organization.name if use_name else organization.id],
182+
input="\n")
182183

183184
assert result.exit_code == 0
184185

tests/commands/test_live.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ def test_live_non_interactive_do_not_store_non_persistent_properties_in_lean_con
611611
result = CliRunner().invoke(lean, ["live", "Python Project",
612612
"--brokerage", brokerage,
613613
"--data-provider-live", data_feed,
614-
*options])
614+
*options],
615+
input="\n")
615616

616617
traceback.print_exception(*result.exc_info)
617618

@@ -656,7 +657,8 @@ def test_live_non_interactive_calls_run_lean_when_all_options_given(brokerage: s
656657
result = CliRunner().invoke(lean, ["live", "Python Project",
657658
"--brokerage", brokerage,
658659
"--data-provider-live", data_feed,
659-
*options])
660+
*options],
661+
input="\n")
660662

661663
traceback.print_exception(*result.exc_info)
662664

@@ -702,7 +704,8 @@ def test_live_non_interactive_calls_run_lean_when_all_options_given_with_multipl
702704
"--brokerage", brokerage,
703705
"--data-provider-live", data_feed1,
704706
"--data-provider-live", data_feed2,
705-
*options])
707+
*options],
708+
input="\n")
706709

707710
traceback.print_exception(*result.exc_info)
708711

@@ -873,7 +876,8 @@ def test_live_non_interactive_falls_back_to_lean_config_for_multiple_data_feed_s
873876
"--data-provider-live", data_feed1,
874877
"--data-provider-live", data_feed2,
875878
"--live-cash-balance", "USD:100",
876-
*options])
879+
*options],
880+
input="\n\n")
877881

878882
assert result.exit_code == 0
879883

tests/test_helpers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ def setup_mock_api_client_and_responses() -> APIClient:
122122
APIClient: A mock API client for testing.
123123
"""
124124
api_client = APIClient(mock.Mock(), HTTPClient(mock.Mock()), user_id="123", api_token="abc")
125+
126+
responses.add(
127+
responses.GET,
128+
"https://raw.githubusercontent.com/QuantConnect/Lean/master/Data/symbol-properties/symbol-properties-database.csv",
129+
body="",
130+
status=200
131+
)
132+
133+
responses.add(
134+
responses.GET,
135+
"https://raw.githubusercontent.com/QuantConnect/Lean/master/Data/market-hours/market-hours-database.json",
136+
body="",
137+
status=200
138+
)
139+
140+
responses.add(
141+
responses.POST,
142+
f"{API_BASE_URL}modules/list",
143+
json={
144+
"files": [],
145+
"success": "true"
146+
},
147+
status=200
148+
)
149+
125150
responses.add(
126151
responses.POST,
127152
f"{API_BASE_URL}live/auth0/read",

0 commit comments

Comments
 (0)