fix: resolve linting and formatting issues for CI
- Use contextlib.suppress instead of try/except/pass (SIM105) - Prefix unused fixture arguments with underscore (ARG002) - Replace asyncio.TimeoutError with TimeoutError (UP041) - Apply ruff formatting to all files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
a15086688a
commit
1f4f1fa557
@@ -115,25 +115,23 @@ class TestClobClient:
|
||||
@pytest.fixture
|
||||
def mock_base_client(self) -> MagicMock:
|
||||
"""Create a mock base CLOB client."""
|
||||
with patch(
|
||||
"polymarket_insider_tracker.ingestor.clob_client.BaseClobClient"
|
||||
) as mock:
|
||||
with patch("polymarket_insider_tracker.ingestor.clob_client.BaseClobClient") as mock:
|
||||
yield mock.return_value
|
||||
|
||||
def test_init_defaults(self, mock_base_client: MagicMock) -> None:
|
||||
def test_init_defaults(self, _mock_base_client: MagicMock) -> None:
|
||||
"""Test client initialization with defaults."""
|
||||
client = ClobClient()
|
||||
|
||||
assert client._host == "https://clob.polymarket.com"
|
||||
assert client._max_retries == 3
|
||||
|
||||
def test_init_with_env_api_key(self, mock_base_client: MagicMock) -> None:
|
||||
def test_init_with_env_api_key(self, _mock_base_client: MagicMock) -> None:
|
||||
"""Test client reads API key from environment."""
|
||||
with patch.dict("os.environ", {"POLYMARKET_API_KEY": "test-key"}):
|
||||
client = ClobClient()
|
||||
assert client._api_key == "test-key"
|
||||
|
||||
def test_init_with_explicit_api_key(self, mock_base_client: MagicMock) -> None:
|
||||
def test_init_with_explicit_api_key(self, _mock_base_client: MagicMock) -> None:
|
||||
"""Test client uses explicitly provided API key."""
|
||||
client = ClobClient(api_key="explicit-key")
|
||||
assert client._api_key == "explicit-key"
|
||||
|
||||
@@ -448,9 +448,7 @@ class TestHealthMonitorHTTPEndpoints:
|
||||
assert data["status"] == "unhealthy"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_metrics_endpoint(
|
||||
self, monitor: HealthMonitor, app: web.Application
|
||||
) -> None:
|
||||
async def test_metrics_endpoint(self, monitor: HealthMonitor, app: web.Application) -> None:
|
||||
"""Test /metrics endpoint returns Prometheus format."""
|
||||
from aiohttp.test_utils import TestClient, TestServer
|
||||
|
||||
@@ -468,9 +466,7 @@ class TestHealthMonitorHTTPEndpoints:
|
||||
assert "polymarket_health_status" in text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ready_endpoint_ready(
|
||||
self, monitor: HealthMonitor, app: web.Application
|
||||
) -> None:
|
||||
async def test_ready_endpoint_ready(self, monitor: HealthMonitor, app: web.Application) -> None:
|
||||
"""Test /ready endpoint when ready."""
|
||||
from aiohttp.test_utils import TestClient, TestServer
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Tests for ingestor data models."""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from decimal import Decimal
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
@@ -75,7 +75,7 @@ class TestMarket:
|
||||
assert len(market.tokens) == 2
|
||||
assert market.tokens[0].outcome == "Yes"
|
||||
assert market.tokens[1].outcome == "No"
|
||||
assert market.end_date == datetime(2024, 12, 31, 23, 59, 59, tzinfo=timezone.utc)
|
||||
assert market.end_date == datetime(2024, 12, 31, 23, 59, 59, tzinfo=UTC)
|
||||
assert market.active is True
|
||||
assert market.closed is False
|
||||
|
||||
@@ -302,7 +302,7 @@ class TestTradeEvent:
|
||||
assert trade.outcome_index == 0
|
||||
assert trade.price == Decimal("0.65")
|
||||
assert trade.size == Decimal("100")
|
||||
assert trade.timestamp == datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
|
||||
assert trade.timestamp == datetime(2024, 1, 1, 0, 0, 0, tzinfo=UTC)
|
||||
assert trade.asset_id == "token123"
|
||||
assert trade.market_slug == "will-it-rain"
|
||||
assert trade.event_slug == "weather-markets"
|
||||
@@ -364,7 +364,7 @@ class TestTradeEvent:
|
||||
outcome_index=0,
|
||||
price=Decimal("0.5"),
|
||||
size=Decimal("10"),
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
timestamp=datetime.now(UTC),
|
||||
asset_id="",
|
||||
)
|
||||
sell_trade = TradeEvent(
|
||||
@@ -376,7 +376,7 @@ class TestTradeEvent:
|
||||
outcome_index=0,
|
||||
price=Decimal("0.5"),
|
||||
size=Decimal("10"),
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
timestamp=datetime.now(UTC),
|
||||
asset_id="",
|
||||
)
|
||||
|
||||
@@ -396,7 +396,7 @@ class TestTradeEvent:
|
||||
outcome_index=0,
|
||||
price=Decimal("0.65"),
|
||||
size=Decimal("100"),
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
timestamp=datetime.now(UTC),
|
||||
asset_id="",
|
||||
)
|
||||
|
||||
@@ -413,7 +413,7 @@ class TestTradeEvent:
|
||||
outcome_index=0,
|
||||
price=Decimal("0.5"),
|
||||
size=Decimal("10"),
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
timestamp=datetime.now(UTC),
|
||||
asset_id="token",
|
||||
)
|
||||
with pytest.raises(AttributeError):
|
||||
|
||||
@@ -80,19 +80,13 @@ class TestTradeStreamHandler:
|
||||
|
||||
assert handler._event_filter == "presidential-election-2024"
|
||||
|
||||
def test_build_subscription_message_no_filter(
|
||||
self, handler: TradeStreamHandler
|
||||
) -> None:
|
||||
def test_build_subscription_message_no_filter(self, handler: TradeStreamHandler) -> None:
|
||||
"""Test building subscription message without filters."""
|
||||
msg = handler._build_subscription_message()
|
||||
|
||||
assert msg == {
|
||||
"subscriptions": [{"topic": "activity", "type": "trades"}]
|
||||
}
|
||||
assert msg == {"subscriptions": [{"topic": "activity", "type": "trades"}]}
|
||||
|
||||
def test_build_subscription_message_with_event_filter(
|
||||
self, on_trade_mock: AsyncMock
|
||||
) -> None:
|
||||
def test_build_subscription_message_with_event_filter(self, on_trade_mock: AsyncMock) -> None:
|
||||
"""Test building subscription message with event filter."""
|
||||
handler = TradeStreamHandler(
|
||||
on_trade=on_trade_mock,
|
||||
@@ -100,13 +94,9 @@ class TestTradeStreamHandler:
|
||||
)
|
||||
msg = handler._build_subscription_message()
|
||||
|
||||
assert msg["subscriptions"][0]["filters"] == json.dumps(
|
||||
{"event_slug": "test-event"}
|
||||
)
|
||||
assert msg["subscriptions"][0]["filters"] == json.dumps({"event_slug": "test-event"})
|
||||
|
||||
def test_build_subscription_message_with_market_filter(
|
||||
self, on_trade_mock: AsyncMock
|
||||
) -> None:
|
||||
def test_build_subscription_message_with_market_filter(self, on_trade_mock: AsyncMock) -> None:
|
||||
"""Test building subscription message with market filter."""
|
||||
handler = TradeStreamHandler(
|
||||
on_trade=on_trade_mock,
|
||||
@@ -114,9 +104,7 @@ class TestTradeStreamHandler:
|
||||
)
|
||||
msg = handler._build_subscription_message()
|
||||
|
||||
assert msg["subscriptions"][0]["filters"] == json.dumps(
|
||||
{"market_slug": "test-market"}
|
||||
)
|
||||
assert msg["subscriptions"][0]["filters"] == json.dumps({"market_slug": "test-market"})
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_message_trade(
|
||||
@@ -235,7 +223,7 @@ class TestTradeStreamHandler:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_connect_sends_subscription(
|
||||
self, handler: TradeStreamHandler, on_state_change_mock: AsyncMock
|
||||
self, handler: TradeStreamHandler, _on_state_change_mock: AsyncMock
|
||||
) -> None:
|
||||
"""Test that connection sends subscription message."""
|
||||
mock_ws = AsyncMock()
|
||||
@@ -254,9 +242,7 @@ class TestTradeStreamHandler:
|
||||
assert sent_msg["subscriptions"][0]["type"] == "trades"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cleanup_closes_websocket(
|
||||
self, handler: TradeStreamHandler
|
||||
) -> None:
|
||||
async def test_cleanup_closes_websocket(self, handler: TradeStreamHandler) -> None:
|
||||
"""Test that cleanup closes the WebSocket."""
|
||||
mock_ws = AsyncMock()
|
||||
mock_ws.close = AsyncMock()
|
||||
@@ -333,7 +319,7 @@ class TestTradeStreamHandlerIntegration:
|
||||
# Run with timeout to prevent hanging
|
||||
try:
|
||||
await asyncio.wait_for(handler.start(), timeout=1.0)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
await handler.stop()
|
||||
|
||||
# Verify trade was received
|
||||
|
||||
Reference in New Issue
Block a user