Skip to content

Commit dbc018f

Browse files
authored
Fix Logging with --verbose for container.data_downloader.update_database_files() (#555)
* Initial solution * Solve review comments * Handle double callback logic * Add log bufffer logic * Fix unit test
1 parent 75b89bb commit dbc018f

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

lean/click.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def __init__(self,
183183
self.context_settings["allow_extra_args"] = allow_unknown_options
184184

185185
def invoke(self, ctx: Context):
186+
container.data_downloader.update_database_files()
186187
if self._requires_lean_config:
187188
lean_config_manager = container.lean_config_manager
188189
try:

lean/container.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,4 @@ def manage_docker_image(self, image: Optional[str], update: bool, no_update: boo
211211
return engine_image, container_module_version, project_config
212212

213213

214-
container = Container()
215-
container.data_downloader.update_database_files()
214+
container = Container()

tests/commands/test_live.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,23 +1240,25 @@ def test_live_deploy_with_different_brokerage_and_different_live_data_provider_a
12401240
api_client = mock.MagicMock()
12411241
create_lean_option(brokerage_name, data_provider_live_name, data_provider_historical_name, api_client)
12421242

1243+
# Filter method calls to include only 'modules.list_files' calls
1244+
filtered_calls = [call for call in api_client.method_calls if call[0] == 'modules.list_files']
12431245
is_exists = []
12441246
if brokerage_product_id is None and data_provider_historical_name != "Local":
1245-
assert len(api_client.method_calls) == 2
1246-
for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, data_provider_historical_id]):
1247+
assert len(api_client.method_calls) == 3
1248+
for m_c, id in zip(filtered_calls, [data_provider_live_product_id, data_provider_historical_id]):
12471249
if id in m_c[1]:
12481250
is_exists.append(True)
12491251
assert is_exists
12501252
assert len(is_exists) == 1
12511253
elif brokerage_product_id is None and data_provider_historical_name == "Local":
1252-
assert len(api_client.method_calls) == 1
1253-
if int(data_provider_live_product_id) in api_client.method_calls[0][1]:
1254+
assert len(api_client.method_calls) == 2
1255+
if int(data_provider_live_product_id) in filtered_calls[0][1]:
12541256
is_exists.append(True)
12551257
assert is_exists
12561258
assert len(is_exists) == 1
12571259
else:
1258-
assert len(api_client.method_calls) == 3
1259-
for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, data_provider_historical_id, brokerage_product_id]):
1260+
assert len(api_client.method_calls) == 4
1261+
for m_c, id in zip(filtered_calls, [data_provider_live_product_id, data_provider_historical_id, brokerage_product_id]):
12601262
if id in f"{m_c[1]}":
12611263
is_exists.append(True)
12621264
assert is_exists
@@ -1272,12 +1274,14 @@ def test_live_non_interactive_deploy_with_different_brokerage_and_different_live
12721274
api_client = mock.MagicMock()
12731275
create_lean_option(brokerage_name, data_provider_live_name, None, api_client)
12741276

1275-
assert len(api_client.method_calls) == 2
1277+
assert len(api_client.method_calls) == 3
1278+
1279+
# Filter method calls to include only 'modules.list_files' calls
1280+
filtered_calls = [call for call in api_client.method_calls if call[0] == 'modules.list_files']
12761281
is_exists = []
1277-
for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, brokerage_product_id]):
1282+
for m_c, id in zip(filtered_calls, [data_provider_live_product_id, brokerage_product_id]):
12781283
if id in m_c[1]:
12791284
is_exists.append(True)
1280-
12811285
assert is_exists
12821286
assert len(is_exists) == 2
12831287

@@ -1309,7 +1313,7 @@ def test_live_non_interactive_deploy_paper_brokerage_different_live_data_provide
13091313
api_client = mock.MagicMock()
13101314
create_lean_option(brokerage_name, data_provider_live_name, None, api_client)
13111315

1312-
assert len(api_client.method_calls) == 1
1316+
assert len(api_client.method_calls) == 2
13131317
for m_c in api_client.method_calls:
13141318
if data_provider_live_product_id in str(m_c[1]):
13151319
is_exist = True

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def initialize_container(docker_manager_to_use=None, lean_runner_to_use=None, ap
3434
api_client.organizations.get_all.return_value = [
3535
QCMinimalOrganization(id="abc", name="abc", type="type", ownerName="You", members=1, preferred=True)
3636
]
37+
38+
# Configure download_public_file to return bytes
39+
mock_csv_content = b"symbol,property\nAAPL,value\n"
40+
mock_json_content = b'{"market": "hours"}'
41+
api_client.data.download_public_file = mock.MagicMock(side_effect=[mock_csv_content, mock_json_content])
42+
3743
if api_client_to_use:
3844
api_client = api_client_to_use
3945

0 commit comments

Comments
 (0)