Refactor code for improved readability and consistency
CI / lint-test-build (push) Failing after 12s
CI / lint-test-build (push) Failing after 12s
- Consolidated multiline string formatting into single-line for SQL queries in multiple files. - Adjusted argument formatting in function calls for better alignment and readability. - Removed unnecessary line breaks and improved spacing in various sections of the codebase. - Updated test cases to maintain consistency in formatting and improve clarity.
This commit is contained in:
+6
-12
@@ -191,8 +191,7 @@ async def test_dashboard_page_and_fragment_and_sse(tmp_path) -> None:
|
||||
assert "trade-open" in overview.text
|
||||
|
||||
assert overview_stream.status_code == 200
|
||||
assert overview_stream.headers["content-type"].startswith(
|
||||
"text/event-stream")
|
||||
assert overview_stream.headers["content-type"].startswith("text/event-stream")
|
||||
assert "event: overview" in overview_stream.text
|
||||
assert "trade-open" in overview_stream.text
|
||||
|
||||
@@ -262,8 +261,7 @@ async def test_dashboard_controls_update_runtime_state_and_config(tmp_path) -> N
|
||||
assert app.state.settings.max_trade_capital_usd == 300.0
|
||||
assert app.state.settings.max_concurrent_trades == 4
|
||||
assert app.state.settings.paper_trading_mode is True
|
||||
assert app.state.dashboard_controls.tradable_pairs == [
|
||||
"BTC/USD", "ETH/BTC"]
|
||||
assert app.state.dashboard_controls.tradable_pairs == ["BTC/USD", "ETH/BTC"]
|
||||
assert app.state.dashboard_controls.strategy_mode == "paper"
|
||||
assert app.state.dashboard_controls.strategy_profit_threshold == 0.0025
|
||||
assert app.state.dashboard_controls.strategy_max_depth_levels == 7
|
||||
@@ -275,14 +273,10 @@ async def test_dashboard_controls_update_runtime_state_and_config(tmp_path) -> N
|
||||
assert audit_recent.status_code == 200
|
||||
entries = audit_recent.json()["entries"]
|
||||
assert len(entries) >= 4
|
||||
assert any(entry["event_type"] ==
|
||||
"dashboard.control.stop" for entry in entries)
|
||||
assert any(entry["event_type"] ==
|
||||
"dashboard.control.start" for entry in entries)
|
||||
assert any(entry["event_type"] ==
|
||||
"dashboard.control.kill_switch" for entry in entries)
|
||||
assert any(entry["event_type"] ==
|
||||
"dashboard.control.config" for entry in entries)
|
||||
assert any(entry["event_type"] == "dashboard.control.stop" for entry in entries)
|
||||
assert any(entry["event_type"] == "dashboard.control.start" for entry in entries)
|
||||
assert any(entry["event_type"] == "dashboard.control.kill_switch" for entry in entries)
|
||||
assert any(entry["event_type"] == "dashboard.control.config" for entry in entries)
|
||||
|
||||
|
||||
async def test_dashboard_controls_emit_alerts(tmp_path) -> None:
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_end_to_end_config_workflow():
|
||||
assert service.get_last_updated_at() is None
|
||||
|
||||
# Test setting a value
|
||||
with patch('arbitrade.config.service.ConfigSettingRepository') as mock_repo_class:
|
||||
with patch("arbitrade.config.service.ConfigSettingRepository") as mock_repo_class:
|
||||
mock_repo_instance = Mock()
|
||||
mock_repo_class.return_value = mock_repo_instance
|
||||
|
||||
|
||||
@@ -6,10 +6,13 @@ from unittest.mock import Mock, patch
|
||||
from arbitrade.storage.repositories import (
|
||||
ConfigSettingRepository,
|
||||
ConfigPairingRepository,
|
||||
ConfigPairFeeRepository,
|
||||
ConfigBacktestingDefaultsRepository
|
||||
ConfigBacktestingDefaultsRepository,
|
||||
)
|
||||
from arbitrade.config.service import (
|
||||
ConfigSetting,
|
||||
ConfigPairing,
|
||||
ConfigBacktestingDefaults,
|
||||
)
|
||||
from arbitrade.config.service import ConfigSetting, ConfigPairing, ConfigPairFee, ConfigBacktestingDefaults
|
||||
from arbitrade.storage.db import DuckDBStore
|
||||
|
||||
|
||||
@@ -31,13 +34,20 @@ def test_config_setting_repository_create_setting(mock_store):
|
||||
repo = ConfigSettingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
# Mock the return value
|
||||
mock_cursor.fetchone.return_value = [
|
||||
"test_key", "test_section", "test_value", "str", False, False, "2023-01-01T00:00:00", "test_user"
|
||||
"test_key",
|
||||
"test_section",
|
||||
"test_value",
|
||||
"str",
|
||||
False,
|
||||
False,
|
||||
"2023-01-01T00:00:00",
|
||||
"test_user",
|
||||
]
|
||||
|
||||
# Create setting
|
||||
@@ -48,7 +58,7 @@ def test_config_setting_repository_create_setting(mock_store):
|
||||
value_type="str",
|
||||
is_secret=False,
|
||||
is_runtime_reloadable=False,
|
||||
updated_by="test_user"
|
||||
updated_by="test_user",
|
||||
)
|
||||
|
||||
result = repo.create_setting(setting)
|
||||
@@ -67,13 +77,20 @@ def test_config_setting_repository_get_setting(mock_store):
|
||||
repo = ConfigSettingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
# Mock the return value
|
||||
mock_cursor.fetchone.return_value = [
|
||||
"test_key", "test_section", "test_value", "str", False, False, "2023-01-01T00:00:00", "test_user"
|
||||
"test_key",
|
||||
"test_section",
|
||||
"test_value",
|
||||
"str",
|
||||
False,
|
||||
False,
|
||||
"2023-01-01T00:00:00",
|
||||
"test_user",
|
||||
]
|
||||
|
||||
# Get setting
|
||||
@@ -93,13 +110,20 @@ def test_config_setting_repository_update_setting(mock_store):
|
||||
repo = ConfigSettingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
# Mock the return value
|
||||
mock_cursor.fetchone.return_value = [
|
||||
"test_key", "test_section", "updated_value", "str", False, False, "2023-01-01T00:00:00", "test_user"
|
||||
"test_key",
|
||||
"test_section",
|
||||
"updated_value",
|
||||
"str",
|
||||
False,
|
||||
False,
|
||||
"2023-01-01T00:00:00",
|
||||
"test_user",
|
||||
]
|
||||
|
||||
# Update setting
|
||||
@@ -110,7 +134,7 @@ def test_config_setting_repository_update_setting(mock_store):
|
||||
value_type="str",
|
||||
is_secret=False,
|
||||
is_runtime_reloadable=False,
|
||||
updated_by="test_user"
|
||||
updated_by="test_user",
|
||||
)
|
||||
|
||||
result = repo.update_setting("test_key", setting)
|
||||
@@ -129,16 +153,32 @@ def test_config_setting_repository_list_settings(mock_store):
|
||||
repo = ConfigSettingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
# Mock the return value
|
||||
mock_cursor.fetchall.return_value = [
|
||||
["test_key1", "test_section", "test_value1", "str",
|
||||
False, False, "2023-01-01T00:00:00", "test_user"],
|
||||
["test_key2", "test_section", "test_value2", "str",
|
||||
False, False, "2023-01-01T00:00:00", "test_user"]
|
||||
[
|
||||
"test_key1",
|
||||
"test_section",
|
||||
"test_value1",
|
||||
"str",
|
||||
False,
|
||||
False,
|
||||
"2023-01-01T00:00:00",
|
||||
"test_user",
|
||||
],
|
||||
[
|
||||
"test_key2",
|
||||
"test_section",
|
||||
"test_value2",
|
||||
"str",
|
||||
False,
|
||||
False,
|
||||
"2023-01-01T00:00:00",
|
||||
"test_user",
|
||||
],
|
||||
]
|
||||
|
||||
# List settings
|
||||
@@ -156,7 +196,7 @@ def test_config_setting_repository_get_latest_updated_at(mock_store):
|
||||
repo = ConfigSettingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
@@ -182,22 +222,24 @@ def test_config_pairing_repository_create_pairing(mock_store):
|
||||
repo = ConfigPairingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
# Mock the return value
|
||||
mock_cursor.fetchone.return_value = [
|
||||
1, "BTC", "USD", True, "Kraken", "2023-01-01T00:00:00", "2023-01-01T00:00:00"
|
||||
1,
|
||||
"BTC",
|
||||
"USD",
|
||||
True,
|
||||
"Kraken",
|
||||
"2023-01-01T00:00:00",
|
||||
"2023-01-01T00:00:00",
|
||||
]
|
||||
|
||||
# Create pairing
|
||||
pairing = ConfigPairing(
|
||||
base_asset="BTC",
|
||||
quote_asset="USD",
|
||||
enabled=True,
|
||||
source="Kraken"
|
||||
)
|
||||
base_asset="BTC", quote_asset="USD", enabled=True, source="Kraken")
|
||||
|
||||
result = repo.create_pairing(pairing)
|
||||
|
||||
@@ -214,13 +256,19 @@ def test_config_pairing_repository_get_pairing(mock_store):
|
||||
repo = ConfigPairingRepository(mock_store)
|
||||
|
||||
# Mock database connection
|
||||
with patch.object(mock_store, 'connect') as mock_connect:
|
||||
with patch.object(mock_store, "connect") as mock_connect:
|
||||
mock_cursor = Mock()
|
||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||
|
||||
# Mock the return value
|
||||
mock_cursor.fetchone.return_value = [
|
||||
1, "BTC", "USD", True, "Kraken", "2023-01-01T00:00:00", "2023-01-01T00:00:00"
|
||||
1,
|
||||
"BTC",
|
||||
"USD",
|
||||
True,
|
||||
"Kraken",
|
||||
"2023-01-01T00:00:00",
|
||||
"2023-01-01T00:00:00",
|
||||
]
|
||||
|
||||
# Get pairing
|
||||
@@ -234,12 +282,6 @@ def test_config_pairing_repository_get_pairing(mock_store):
|
||||
assert result.source == "Kraken"
|
||||
|
||||
|
||||
def test_config_pair_fee_repository_initialization(mock_store):
|
||||
"""Test ConfigPairFeeRepository initialization."""
|
||||
repo = ConfigPairFeeRepository(mock_store)
|
||||
assert repo._store == mock_store
|
||||
|
||||
|
||||
def test_config_backtesting_defaults_repository_initialization(mock_store):
|
||||
"""Test ConfigBacktestingDefaultsRepository initialization."""
|
||||
repo = ConfigBacktestingDefaultsRepository(mock_store)
|
||||
|
||||
@@ -31,9 +31,7 @@ def mock_audit_repo():
|
||||
return audit_repo
|
||||
|
||||
|
||||
def test_configuration_service_initialization(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_initialization(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test that ConfigurationService initializes correctly."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
@@ -46,9 +44,7 @@ def test_configuration_service_initialization(
|
||||
assert isinstance(service._loaded_settings, dict)
|
||||
|
||||
|
||||
def test_configuration_service_get_setting(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_get_setting(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test getting configuration settings."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
@@ -65,15 +61,13 @@ def test_configuration_service_get_setting(
|
||||
assert result == "default"
|
||||
|
||||
|
||||
def test_configuration_service_set_setting(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_set_setting(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test setting configuration settings."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
|
||||
# Mock the repository
|
||||
with patch('arbitrade.config.service.ConfigSettingRepository') as mock_repo_class:
|
||||
with patch("arbitrade.config.service.ConfigSettingRepository") as mock_repo_class:
|
||||
mock_repo_instance = Mock()
|
||||
mock_repo_class.return_value = mock_repo_instance
|
||||
|
||||
@@ -90,9 +84,7 @@ def test_configuration_service_set_setting(
|
||||
mock_repo_instance.create_setting.assert_called_once()
|
||||
|
||||
|
||||
def test_configuration_service_hot_reload_detection(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_hot_reload_detection(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test hot-reload detection functionality."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
@@ -101,27 +93,26 @@ def test_configuration_service_hot_reload_detection(
|
||||
assert service.is_config_outdated() is False
|
||||
|
||||
# Test with mock repository that returns a timestamp
|
||||
with patch('arbitrade.config.service.ConfigSettingRepository') as mock_repo_class:
|
||||
with patch("arbitrade.config.service.ConfigSettingRepository") as mock_repo_class:
|
||||
mock_repo_instance = Mock()
|
||||
mock_repo_class.return_value = mock_repo_instance
|
||||
|
||||
# Mock the latest updated at timestamp
|
||||
from datetime import datetime
|
||||
|
||||
mock_repo_instance.get_latest_updated_at.return_value = datetime.now()
|
||||
|
||||
# Should detect as outdated when timestamp exists
|
||||
assert service.is_config_outdated() is True
|
||||
|
||||
|
||||
def test_configuration_service_reload_if_changed(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_reload_if_changed(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test hot-reload functionality."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
|
||||
# Mock the repository
|
||||
with patch('arbitrade.config.service.ConfigSettingRepository') as mock_repo_class:
|
||||
with patch("arbitrade.config.service.ConfigSettingRepository") as mock_repo_class:
|
||||
mock_repo_instance = Mock()
|
||||
mock_repo_class.return_value = mock_repo_instance
|
||||
|
||||
@@ -135,6 +126,7 @@ def test_configuration_service_reload_if_changed(
|
||||
|
||||
# Mock the latest updated at timestamp to return a value
|
||||
from datetime import datetime
|
||||
|
||||
mock_repo_instance.get_latest_updated_at.return_value = datetime.now()
|
||||
|
||||
# Should reload when outdated
|
||||
@@ -143,9 +135,7 @@ def test_configuration_service_reload_if_changed(
|
||||
assert service.get_config_version() == 1
|
||||
|
||||
|
||||
def test_configuration_service_get_config_version(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_get_config_version(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test getting configuration version."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
@@ -154,7 +144,7 @@ def test_configuration_service_get_config_version(
|
||||
assert service.get_config_version() == 0
|
||||
|
||||
# After setting a value, version should increment
|
||||
with patch('arbitrade.config.service.ConfigSettingRepository') as mock_repo_class:
|
||||
with patch("arbitrade.config.service.ConfigSettingRepository") as mock_repo_class:
|
||||
mock_repo_instance = Mock()
|
||||
mock_repo_class.return_value = mock_repo_instance
|
||||
|
||||
@@ -166,9 +156,7 @@ def test_configuration_service_get_config_version(
|
||||
assert service.get_config_version() == 1
|
||||
|
||||
|
||||
def test_configuration_service_get_last_updated_at(
|
||||
mock_settings, mock_store, mock_audit_repo
|
||||
):
|
||||
def test_configuration_service_get_last_updated_at(mock_settings, mock_store, mock_audit_repo):
|
||||
"""Test getting last updated timestamp."""
|
||||
# Create service instance
|
||||
service = ConfigurationService(mock_settings, mock_store, mock_audit_repo)
|
||||
@@ -177,7 +165,7 @@ def test_configuration_service_get_last_updated_at(
|
||||
assert service.get_last_updated_at() is None
|
||||
|
||||
# After setting a value, should have timestamp
|
||||
with patch('arbitrade.config.service.ConfigSettingRepository') as mock_repo_class:
|
||||
with patch("arbitrade.config.service.ConfigSettingRepository") as mock_repo_class:
|
||||
mock_repo_instance = Mock()
|
||||
mock_repo_class.return_value = mock_repo_instance
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ def test_template_directory_resolves_to_existing_location() -> None:
|
||||
|
||||
|
||||
def test_template_exists_in_package_resources() -> None:
|
||||
template_path = resources.files("arbitrade").joinpath(
|
||||
"web", "templates", "dashboard.html"
|
||||
)
|
||||
template_path = resources.files("arbitrade").joinpath("web", "templates", "dashboard.html")
|
||||
|
||||
assert template_path.is_file()
|
||||
|
||||
Reference in New Issue
Block a user