summaryrefslogtreecommitdiff
path: root/shared/tests
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 15:54:55 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 15:54:55 +0900
commitbf4afbc0a3cc4e847ef01840365fd6a6ae9c142f (patch)
treec8634b3b21534f550e2d255d98c4a068a1b567d0 /shared/tests
parentec8b6fea5a4a710df4b2ae18f3f399d165c8ffd4 (diff)
style: auto-fix lint violations from enhanced ruff rules
Diffstat (limited to 'shared/tests')
-rw-r--r--shared/tests/test_alpaca.py4
-rw-r--r--shared/tests/test_broker.py5
-rw-r--r--shared/tests/test_db.py21
-rw-r--r--shared/tests/test_db_news.py13
-rw-r--r--shared/tests/test_events.py10
-rw-r--r--shared/tests/test_models.py13
-rw-r--r--shared/tests/test_news_events.py6
-rw-r--r--shared/tests/test_notifier.py2
-rw-r--r--shared/tests/test_resilience.py1
-rw-r--r--shared/tests/test_sa_news_models.py2
-rw-r--r--shared/tests/test_sentiment_aggregator.py16
-rw-r--r--shared/tests/test_sentiment_models.py14
12 files changed, 57 insertions, 50 deletions
diff --git a/shared/tests/test_alpaca.py b/shared/tests/test_alpaca.py
index 080b7c4..55a2b24 100644
--- a/shared/tests/test_alpaca.py
+++ b/shared/tests/test_alpaca.py
@@ -1,7 +1,9 @@
"""Tests for Alpaca API client."""
-import pytest
from unittest.mock import AsyncMock, MagicMock
+
+import pytest
+
from shared.alpaca import AlpacaClient
diff --git a/shared/tests/test_broker.py b/shared/tests/test_broker.py
index eb1582d..5636611 100644
--- a/shared/tests/test_broker.py
+++ b/shared/tests/test_broker.py
@@ -1,10 +1,11 @@
"""Tests for the Redis broker."""
-import pytest
import json
-import redis
from unittest.mock import AsyncMock, patch
+import pytest
+import redis
+
@pytest.mark.asyncio
async def test_broker_publish():
diff --git a/shared/tests/test_db.py b/shared/tests/test_db.py
index 439a66e..b44a713 100644
--- a/shared/tests/test_db.py
+++ b/shared/tests/test_db.py
@@ -1,10 +1,11 @@
"""Tests for the SQLAlchemy async database layer."""
-import pytest
+from datetime import UTC, datetime
from decimal import Decimal
-from datetime import datetime, timezone
from unittest.mock import AsyncMock, MagicMock, patch
+import pytest
+
def make_candle():
from shared.models import Candle
@@ -12,7 +13,7 @@ def make_candle():
return Candle(
symbol="AAPL",
timeframe="1m",
- open_time=datetime(2024, 1, 1, tzinfo=timezone.utc),
+ open_time=datetime(2024, 1, 1, tzinfo=UTC),
open=Decimal("50000"),
high=Decimal("51000"),
low=Decimal("49500"),
@@ -22,7 +23,7 @@ def make_candle():
def make_signal():
- from shared.models import Signal, OrderSide
+ from shared.models import OrderSide, Signal
return Signal(
id="sig-1",
@@ -32,12 +33,12 @@ def make_signal():
price=Decimal("50000"),
quantity=Decimal("0.1"),
reason="Golden cross",
- created_at=datetime(2024, 1, 1, tzinfo=timezone.utc),
+ created_at=datetime(2024, 1, 1, tzinfo=UTC),
)
def make_order():
- from shared.models import Order, OrderSide, OrderType, OrderStatus
+ from shared.models import Order, OrderSide, OrderStatus, OrderType
return Order(
id="ord-1",
@@ -48,7 +49,7 @@ def make_order():
price=Decimal("50000"),
quantity=Decimal("0.1"),
status=OrderStatus.PENDING,
- created_at=datetime(2024, 1, 1, tzinfo=timezone.utc),
+ created_at=datetime(2024, 1, 1, tzinfo=UTC),
)
@@ -259,7 +260,7 @@ class TestUpdateOrderStatus:
db._session_factory = MagicMock(return_value=mock_session)
- filled = datetime(2024, 1, 2, tzinfo=timezone.utc)
+ filled = datetime(2024, 1, 2, tzinfo=UTC)
await db.update_order_status("ord-1", OrderStatus.FILLED, filled)
mock_session.execute.assert_awaited_once()
@@ -278,7 +279,7 @@ class TestGetCandles:
mock_row._mapping = {
"symbol": "AAPL",
"timeframe": "1m",
- "open_time": datetime(2024, 1, 1, tzinfo=timezone.utc),
+ "open_time": datetime(2024, 1, 1, tzinfo=UTC),
"open": Decimal("50000"),
"high": Decimal("51000"),
"low": Decimal("49500"),
@@ -444,7 +445,7 @@ class TestGetPortfolioSnapshots:
mock_row.total_value = Decimal("10000")
mock_row.realized_pnl = Decimal("0")
mock_row.unrealized_pnl = Decimal("500")
- mock_row.snapshot_at = datetime(2024, 1, 1, tzinfo=timezone.utc)
+ mock_row.snapshot_at = datetime(2024, 1, 1, tzinfo=UTC)
mock_result = MagicMock()
mock_result.scalars.return_value.all.return_value = [mock_row]
diff --git a/shared/tests/test_db_news.py b/shared/tests/test_db_news.py
index a2c9140..c184bed 100644
--- a/shared/tests/test_db_news.py
+++ b/shared/tests/test_db_news.py
@@ -1,11 +1,12 @@
"""Tests for database news/sentiment methods. Uses in-memory SQLite."""
+from datetime import UTC, date, datetime
+
import pytest
-from datetime import datetime, date, timezone
from shared.db import Database
-from shared.models import NewsItem, NewsCategory
-from shared.sentiment_models import SymbolScore, MarketSentiment
+from shared.models import NewsCategory, NewsItem
+from shared.sentiment_models import MarketSentiment, SymbolScore
@pytest.fixture
@@ -20,7 +21,7 @@ async def test_insert_and_get_news_items(db):
item = NewsItem(
source="finnhub",
headline="AAPL earnings beat",
- published_at=datetime(2026, 4, 2, 12, 0, tzinfo=timezone.utc),
+ published_at=datetime(2026, 4, 2, 12, 0, tzinfo=UTC),
sentiment=0.8,
category=NewsCategory.EARNINGS,
symbols=["AAPL"],
@@ -40,7 +41,7 @@ async def test_upsert_symbol_score(db):
policy_score=0.0,
filing_score=0.2,
composite=0.3,
- updated_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ updated_at=datetime(2026, 4, 2, tzinfo=UTC),
)
await db.upsert_symbol_score(score)
scores = await db.get_top_symbol_scores(limit=5)
@@ -55,7 +56,7 @@ async def test_upsert_market_sentiment(db):
vix=18.2,
fed_stance="neutral",
market_regime="neutral",
- updated_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ updated_at=datetime(2026, 4, 2, tzinfo=UTC),
)
await db.upsert_market_sentiment(ms)
result = await db.get_latest_market_sentiment()
diff --git a/shared/tests/test_events.py b/shared/tests/test_events.py
index 6077d93..1ccd904 100644
--- a/shared/tests/test_events.py
+++ b/shared/tests/test_events.py
@@ -1,7 +1,7 @@
"""Tests for shared event types."""
+from datetime import UTC, datetime
from decimal import Decimal
-from datetime import datetime, timezone
def make_candle():
@@ -10,7 +10,7 @@ def make_candle():
return Candle(
symbol="AAPL",
timeframe="1m",
- open_time=datetime(2024, 1, 1, tzinfo=timezone.utc),
+ open_time=datetime(2024, 1, 1, tzinfo=UTC),
open=Decimal("50000"),
high=Decimal("51000"),
low=Decimal("49500"),
@@ -20,7 +20,7 @@ def make_candle():
def make_signal():
- from shared.models import Signal, OrderSide
+ from shared.models import OrderSide, Signal
return Signal(
strategy="test",
@@ -59,7 +59,7 @@ def test_candle_event_deserialize():
def test_signal_event_serialize():
"""Test SignalEvent serializes to dict correctly."""
- from shared.events import SignalEvent, EventType
+ from shared.events import EventType, SignalEvent
signal = make_signal()
event = SignalEvent(data=signal)
@@ -71,7 +71,7 @@ def test_signal_event_serialize():
def test_event_from_dict_dispatch():
"""Test Event.from_dict dispatches to correct class."""
- from shared.events import Event, CandleEvent, SignalEvent
+ from shared.events import CandleEvent, Event, SignalEvent
candle = make_candle()
event = CandleEvent(data=candle)
diff --git a/shared/tests/test_models.py b/shared/tests/test_models.py
index 21f9831..40bb791 100644
--- a/shared/tests/test_models.py
+++ b/shared/tests/test_models.py
@@ -1,8 +1,8 @@
"""Tests for shared models and settings."""
import os
+from datetime import UTC, datetime
from decimal import Decimal
-from datetime import datetime, timezone
from unittest.mock import patch
@@ -28,7 +28,7 @@ def test_candle_creation():
"""Test Candle model creation."""
from shared.models import Candle
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
candle = Candle(
symbol="AAPL",
timeframe="1m",
@@ -50,7 +50,7 @@ def test_candle_creation():
def test_signal_creation():
"""Test Signal model creation."""
- from shared.models import Signal, OrderSide
+ from shared.models import OrderSide, Signal
signal = Signal(
strategy="rsi_strategy",
@@ -72,9 +72,10 @@ def test_signal_creation():
def test_order_creation():
"""Test Order model creation with defaults."""
- from shared.models import Order, OrderSide, OrderType, OrderStatus
import uuid
+ from shared.models import Order, OrderSide, OrderStatus, OrderType
+
signal_id = str(uuid.uuid4())
order = Order(
signal_id=signal_id,
@@ -93,7 +94,7 @@ def test_order_creation():
def test_signal_conviction_default():
"""Test Signal defaults for conviction, stop_loss, take_profit."""
- from shared.models import Signal, OrderSide
+ from shared.models import OrderSide, Signal
signal = Signal(
strategy="rsi",
@@ -110,7 +111,7 @@ def test_signal_conviction_default():
def test_signal_with_stops():
"""Test Signal with explicit conviction, stop_loss, take_profit."""
- from shared.models import Signal, OrderSide
+ from shared.models import OrderSide, Signal
signal = Signal(
strategy="rsi",
diff --git a/shared/tests/test_news_events.py b/shared/tests/test_news_events.py
index 384796a..f748d8a 100644
--- a/shared/tests/test_news_events.py
+++ b/shared/tests/test_news_events.py
@@ -1,16 +1,16 @@
"""Tests for NewsEvent."""
-from datetime import datetime, timezone
+from datetime import UTC, datetime
+from shared.events import Event, EventType, NewsEvent
from shared.models import NewsCategory, NewsItem
-from shared.events import NewsEvent, EventType, Event
def test_news_event_to_dict():
item = NewsItem(
source="finnhub",
headline="Test",
- published_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ published_at=datetime(2026, 4, 2, tzinfo=UTC),
sentiment=0.5,
category=NewsCategory.MACRO,
)
diff --git a/shared/tests/test_notifier.py b/shared/tests/test_notifier.py
index 6c81369..cc98a56 100644
--- a/shared/tests/test_notifier.py
+++ b/shared/tests/test_notifier.py
@@ -6,7 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
-from shared.models import Signal, Order, OrderSide, OrderType, OrderStatus, Position
+from shared.models import Order, OrderSide, OrderStatus, OrderType, Position, Signal
from shared.notifier import TelegramNotifier
diff --git a/shared/tests/test_resilience.py b/shared/tests/test_resilience.py
index 5ed4ac3..e0781af 100644
--- a/shared/tests/test_resilience.py
+++ b/shared/tests/test_resilience.py
@@ -6,7 +6,6 @@ import pytest
from shared.resilience import CircuitBreaker, async_timeout, retry_async
-
# --- retry_async tests ---
diff --git a/shared/tests/test_sa_news_models.py b/shared/tests/test_sa_news_models.py
index 91e6d4a..dc2d026 100644
--- a/shared/tests/test_sa_news_models.py
+++ b/shared/tests/test_sa_news_models.py
@@ -1,6 +1,6 @@
"""Tests for news-related SQLAlchemy models."""
-from shared.sa_models import NewsItemRow, SymbolScoreRow, MarketSentimentRow, StockSelectionRow
+from shared.sa_models import MarketSentimentRow, NewsItemRow, StockSelectionRow, SymbolScoreRow
def test_news_item_row_tablename():
diff --git a/shared/tests/test_sentiment_aggregator.py b/shared/tests/test_sentiment_aggregator.py
index a99c711..9193785 100644
--- a/shared/tests/test_sentiment_aggregator.py
+++ b/shared/tests/test_sentiment_aggregator.py
@@ -1,7 +1,9 @@
"""Tests for sentiment aggregator."""
+from datetime import UTC, datetime, timedelta
+
import pytest
-from datetime import datetime, timezone, timedelta
+
from shared.sentiment import SentimentAggregator
@@ -12,25 +14,25 @@ def aggregator():
def test_freshness_decay_recent():
a = SentimentAggregator()
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
assert a._freshness_decay(now, now) == 1.0
def test_freshness_decay_3_hours():
a = SentimentAggregator()
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
assert a._freshness_decay(now - timedelta(hours=3), now) == 0.7
def test_freshness_decay_12_hours():
a = SentimentAggregator()
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
assert a._freshness_decay(now - timedelta(hours=12), now) == 0.3
def test_freshness_decay_old():
a = SentimentAggregator()
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
assert a._freshness_decay(now - timedelta(days=2), now) == 0.0
@@ -44,7 +46,7 @@ def test_compute_composite():
def test_aggregate_news_by_symbol(aggregator):
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
news_items = [
{"symbols": ["AAPL"], "sentiment": 0.8, "category": "earnings", "published_at": now},
{
@@ -64,7 +66,7 @@ def test_aggregate_news_by_symbol(aggregator):
def test_aggregate_empty(aggregator):
- now = datetime.now(timezone.utc)
+ now = datetime.now(UTC)
assert aggregator.aggregate([], now) == {}
diff --git a/shared/tests/test_sentiment_models.py b/shared/tests/test_sentiment_models.py
index 25fc371..e00ffa6 100644
--- a/shared/tests/test_sentiment_models.py
+++ b/shared/tests/test_sentiment_models.py
@@ -1,16 +1,16 @@
"""Tests for news and sentiment models."""
-from datetime import datetime, timezone
+from datetime import UTC, datetime
from shared.models import NewsCategory, NewsItem, OrderSide
-from shared.sentiment_models import SymbolScore, MarketSentiment, SelectedStock, Candidate
+from shared.sentiment_models import Candidate, MarketSentiment, SelectedStock, SymbolScore
def test_news_item_defaults():
item = NewsItem(
source="finnhub",
headline="Test headline",
- published_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ published_at=datetime(2026, 4, 2, tzinfo=UTC),
sentiment=0.5,
category=NewsCategory.MACRO,
)
@@ -25,7 +25,7 @@ def test_news_item_with_symbols():
item = NewsItem(
source="rss",
headline="AAPL earnings beat",
- published_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ published_at=datetime(2026, 4, 2, tzinfo=UTC),
sentiment=0.8,
category=NewsCategory.EARNINGS,
symbols=["AAPL"],
@@ -52,7 +52,7 @@ def test_symbol_score():
policy_score=0.0,
filing_score=0.2,
composite=0.3,
- updated_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ updated_at=datetime(2026, 4, 2, tzinfo=UTC),
)
assert score.symbol == "AAPL"
assert score.composite == 0.3
@@ -65,7 +65,7 @@ def test_market_sentiment():
vix=32.5,
fed_stance="hawkish",
market_regime="risk_off",
- updated_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ updated_at=datetime(2026, 4, 2, tzinfo=UTC),
)
assert ms.market_regime == "risk_off"
assert ms.vix == 32.5
@@ -77,7 +77,7 @@ def test_market_sentiment_no_vix():
fear_greed_label="Neutral",
fed_stance="neutral",
market_regime="neutral",
- updated_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
+ updated_at=datetime(2026, 4, 2, tzinfo=UTC),
)
assert ms.vix is None