Refactor code for improved readability and consistency
CI / lint-test-build (push) Successful in 54s

- Cleaned up multiline statements and removed unnecessary line breaks in various files.
- Ensured consistent formatting in function definitions and calls across the codebase.
- Updated docstrings and comments for clarity where applicable.
- Removed trailing newlines in module docstrings.
- Enhanced logging statements for better clarity in maintenance tasks.
This commit is contained in:
2026-06-07 21:59:09 +02:00
parent f221464daa
commit dc99f1604e
25 changed files with 409 additions and 324 deletions
+1 -2
View File
@@ -39,8 +39,7 @@ async def test_end_to_end_config_workflow():
# Mock the setting creation
mock_created_setting = Mock()
mock_created_setting.updated_at = "2023-01-01T00:00:00"
mock_repo_instance.create_setting = AsyncMock(
return_value=mock_created_setting)
mock_repo_instance.create_setting = AsyncMock(return_value=mock_created_setting)
mock_repo_instance.get_setting = AsyncMock(return_value=None)
mock_repo_instance.get_latest_updated_at = AsyncMock(return_value=None)
mock_repo_instance.list_settings = AsyncMock(return_value=[])
+3 -7
View File
@@ -136,10 +136,8 @@ async def test_config_setting_repository_list_settings(mock_store):
repo = ConfigSettingRepository(mock_store)
conn = await mock_store.pool.acquire().__aenter__()
row1 = _make_row({**SETTING_ROW, "key": "test_key1",
"value_json": "test_value1"})
row2 = _make_row({**SETTING_ROW, "key": "test_key2",
"value_json": "test_value2"})
row1 = _make_row({**SETTING_ROW, "key": "test_key1", "value_json": "test_value1"})
row2 = _make_row({**SETTING_ROW, "key": "test_key2", "value_json": "test_value2"})
conn.fetch = AsyncMock(return_value=[row1, row2])
result = await repo.list_settings()
@@ -176,9 +174,7 @@ async def test_config_pairing_repository_create_pairing(mock_store):
conn = await mock_store.pool.acquire().__aenter__()
conn.fetchrow = AsyncMock(return_value=_make_row(PAIRING_ROW))
pairing = ConfigPairing(
base_asset="BTC", quote_asset="USD", enabled=True, source="Kraken"
)
pairing = ConfigPairing(base_asset="BTC", quote_asset="USD", enabled=True, source="Kraken")
result = await repo.create_pairing(pairing)
+11 -12
View File
@@ -63,8 +63,7 @@ async def test_configuration_service_set_setting(mock_settings, mock_store, mock
mock_created_setting = Mock()
mock_created_setting.updated_at = "2023-01-01T00:00:00"
mock_repo_instance.create_setting = AsyncMock(
return_value=mock_created_setting)
mock_repo_instance.create_setting = AsyncMock(return_value=mock_created_setting)
mock_repo_instance.get_setting = AsyncMock(return_value=None)
await service.set_setting("test_key", "test_value", "test_user")
@@ -73,7 +72,9 @@ async def test_configuration_service_set_setting(mock_settings, mock_store, mock
@pytest.mark.asyncio
async def test_configuration_service_hot_reload_detection(mock_settings, mock_store, mock_audit_repo):
async def test_configuration_service_hot_reload_detection(
mock_settings, mock_store, mock_audit_repo
):
"""Test hot-reload detection functionality."""
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
@@ -86,8 +87,7 @@ async def test_configuration_service_hot_reload_detection(mock_settings, mock_st
from datetime import datetime
mock_repo_instance.get_latest_updated_at = AsyncMock(
return_value=datetime.now())
mock_repo_instance.get_latest_updated_at = AsyncMock(return_value=datetime.now())
assert await service.is_config_outdated() is True
@@ -105,8 +105,7 @@ async def test_configuration_service_reload_if_changed(mock_settings, mock_store
from datetime import datetime
mock_repo_instance.get_latest_updated_at = AsyncMock(
return_value=datetime.now())
mock_repo_instance.get_latest_updated_at = AsyncMock(return_value=datetime.now())
result = await service.reload_if_changed()
assert result is True
@@ -125,8 +124,7 @@ async def test_configuration_service_get_config_version(mock_settings, mock_stor
mock_created_setting = Mock()
mock_created_setting.updated_at = "2023-01-01T00:00:00"
mock_repo_instance.create_setting = AsyncMock(
return_value=mock_created_setting)
mock_repo_instance.create_setting = AsyncMock(return_value=mock_created_setting)
mock_repo_instance.get_setting = AsyncMock(return_value=None)
await service.set_setting("test_key", "test_value", "test_user")
@@ -134,7 +132,9 @@ async def test_configuration_service_get_config_version(mock_settings, mock_stor
@pytest.mark.asyncio
async def test_configuration_service_get_last_updated_at(mock_settings, mock_store, mock_audit_repo):
async def test_configuration_service_get_last_updated_at(
mock_settings, mock_store, mock_audit_repo
):
"""Test getting last updated timestamp."""
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
assert service.get_last_updated_at() is None
@@ -145,8 +145,7 @@ async def test_configuration_service_get_last_updated_at(mock_settings, mock_sto
mock_created_setting = Mock()
mock_created_setting.updated_at = "2023-01-01T00:00:00"
mock_repo_instance.create_setting = AsyncMock(
return_value=mock_created_setting)
mock_repo_instance.create_setting = AsyncMock(return_value=mock_created_setting)
mock_repo_instance.get_setting = AsyncMock(return_value=None)
await service.set_setting("test_key", "test_value", "test_user")
+3 -7
View File
@@ -49,9 +49,7 @@ def _mock_pg_store():
@pytest.fixture
def app():
"""Create a test app with a mocked PgStore and audit repository."""
a = create_app(
Settings(_env_file=None, APP_MODE="paper", paper_trading_mode=True)
)
a = create_app(Settings(_env_file=None, APP_MODE="paper", paper_trading_mode=True))
a.state.store = _mock_pg_store()
a.state.runtime_state_repository.insert = AsyncMock()
a.state.runtime_state_repository.latest = AsyncMock(return_value=None)
@@ -69,16 +67,14 @@ async def test_persist_runtime_snapshot_writes_record(app) -> None:
# Mock _open_trade_count → 0, _latest_balances → None
conn = await app.state.store.pool.acquire().__aenter__()
conn.fetchrow = AsyncMock(return_value=MagicMock(
**{"__getitem__": lambda s, k: 0}))
conn.fetchrow = AsyncMock(return_value=MagicMock(**{"__getitem__": lambda s, k: 0}))
snapshot = await persist_runtime_snapshot(app, note="unit-test")
assert snapshot is not None
assert snapshot.note == "unit-test"
app.state.runtime_state_repository.latest = AsyncMock(
return_value=snapshot)
app.state.runtime_state_repository.latest = AsyncMock(return_value=snapshot)
latest = await app.state.runtime_state_repository.latest()
assert latest is not None
assert latest.note == "unit-test"