Skip to content

Commit 6d145bd

Browse files
committed
chore: align lint formatting and shrink long test lines
1 parent eead102 commit 6d145bd

7 files changed

Lines changed: 71 additions & 11 deletions

File tree

app/services/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,44 @@
4545
update_position,
4646
)
4747
from .scheduler import ensure_refresh_state, init_scheduler
48+
49+
__all__ = [
50+
"init_registry",
51+
"Orchestrator",
52+
"SnapshotRecord",
53+
"create_orchestrator",
54+
"init_orchestrator",
55+
"PortfolioCreateData",
56+
"PortfolioDTO",
57+
"PortfolioListResult",
58+
"PortfolioUpdateData",
59+
"create_portfolio",
60+
"delete_portfolio",
61+
"get_portfolio",
62+
"list_portfolios",
63+
"update_portfolio",
64+
"CurrencyExposure",
65+
"PortfolioDailyPnLResult",
66+
"PortfolioExposureResult",
67+
"PortfolioValueResult",
68+
"PortfolioValueSeriesPoint",
69+
"PortfolioValueSeriesResult",
70+
"PortfolioWhatIfResult",
71+
"calculate_currency_exposure",
72+
"calculate_daily_pnl",
73+
"calculate_portfolio_value",
74+
"calculate_portfolio_value_series",
75+
"simulate_currency_shock",
76+
"PositionCreateData",
77+
"PositionDTO",
78+
"PositionListParams",
79+
"PositionListResult",
80+
"PositionUpdateData",
81+
"create_position",
82+
"delete_position",
83+
"get_position",
84+
"list_positions",
85+
"update_position",
86+
"ensure_refresh_state",
87+
"init_scheduler",
88+
]

app/services/portfolio_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _rates_for_timestamps(
170170
rates = grouped.setdefault(normalized_ts, {})
171171
rates[normalize_currency(target_code)] = rate
172172

173-
for normalized_ts, rates in grouped.items():
173+
for _timestamp, rates in grouped.items():
174174
if rates:
175175
rates[base_code] = Decimal("1")
176176

app/services/position_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def _normalize_side(
239239

240240

241241
def _raise_integrity_error(exc: IntegrityError) -> None:
242-
message = str(getattr(exc, "orig", exc))
243242
raise APIError("Unable to process position request.", status_code=400) from exc
244243

245244

tests/e2e/providers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass
88
from datetime import UTC, datetime
99
from decimal import Decimal
10+
1011
from app.providers import (
1112
BaseRateProvider,
1213
ProviderError,

tests/test_backfill.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ def test_run_backfill_persists_history(client, monkeypatch, history_series):
5151
original_codes = registry.codes
5252
registry.codes = {"USD", "EUR"}
5353

54-
persisted = []
55-
monkeypatch.setattr("app.services.backfill.persist_snapshot", lambda snapshot: persisted.append(snapshot))
54+
persisted: list = []
55+
56+
def _capture_snapshot(snapshot):
57+
persisted.append(snapshot)
58+
59+
monkeypatch.setattr("app.services.backfill.persist_snapshot", _capture_snapshot)
5660

5761
try:
5862
with app.app_context():

tests/test_rate_store.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ def test_persist_snapshot_normalizes_timestamp_to_utc(app):
2828

2929
persist_snapshot(snapshot)
3030

31+
query = text(
32+
"SELECT timestamp FROM fx_rates "
33+
"WHERE base_currency_code = :base "
34+
"AND target_currency_code = :target "
35+
"AND source = :source"
36+
)
3137
raw_value = session.execute(
32-
text(
33-
"SELECT timestamp FROM fx_rates WHERE base_currency_code=:base AND target_currency_code=:target AND source=:source"
34-
),
38+
query,
3539
{"base": "USD", "target": "EUR", "source": "mock"},
3640
).scalar_one()
3741

tests/test_rates_refresh.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,22 @@ def snapshot():
3232
)
3333

3434

35+
def _increment_persist_counter(counter):
36+
def _increment(_snapshot):
37+
counter["persist"] += 1
38+
39+
return _increment
40+
41+
42+
def _raise_should_not_persist(_snapshot):
43+
raise RuntimeError("should not persist")
44+
45+
3546
def test_manual_refresh_returns_accepted(client, snapshot, monkeypatch):
3647
calls = {"persist": 0}
3748
monkeypatch.setattr(
3849
"app.rates.routes.persist_snapshot",
39-
lambda snapshot: calls.__setitem__("persist", calls["persist"] + 1),
50+
_increment_persist_counter(calls),
4051
)
4152

4253
app = client.application
@@ -61,7 +72,7 @@ def test_manual_refresh_returns_accepted(client, snapshot, monkeypatch):
6172
def test_manual_refresh_throttles_requests(client, snapshot, monkeypatch):
6273
monkeypatch.setattr(
6374
"app.rates.routes.persist_snapshot",
64-
lambda snapshot: (_ for _ in ()).throw(RuntimeError("should not persist")),
75+
_raise_should_not_persist,
6576
)
6677

6778
app = client.application
@@ -77,7 +88,7 @@ def test_manual_refresh_throttles_requests(client, snapshot, monkeypatch):
7788

7889

7990
def test_manual_refresh_reports_provider_error(client, monkeypatch):
80-
monkeypatch.setattr("app.rates.routes.persist_snapshot", lambda snapshot: None)
91+
monkeypatch.setattr("app.rates.routes.persist_snapshot", lambda _snapshot: None)
8192

8293
app = client.application
8394
app.extensions["fx_orchestrator"] = DummyOrchestrator(error=ProviderError("primary down"))
@@ -94,7 +105,7 @@ def test_manual_refresh_respects_zero_throttle(client, snapshot, monkeypatch):
94105
calls = {"persist": 0}
95106
monkeypatch.setattr(
96107
"app.rates.routes.persist_snapshot",
97-
lambda snapshot: calls.__setitem__("persist", calls["persist"] + 1),
108+
_increment_persist_counter(calls),
98109
)
99110

100111
app = client.application

0 commit comments

Comments
 (0)