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
@@ -75,9 +75,7 @@ class TestDiscordChannel:
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_success(self, sample_alert: FormattedAlert) -> None:
|
||||
"""Test successful Discord message send."""
|
||||
channel = DiscordChannel(
|
||||
webhook_url="https://discord.com/api/webhooks/123/abc"
|
||||
)
|
||||
channel = DiscordChannel(webhook_url="https://discord.com/api/webhooks/123/abc")
|
||||
|
||||
with patch("httpx.AsyncClient") as mock_client_class:
|
||||
mock_response = MagicMock()
|
||||
@@ -310,9 +308,7 @@ class TestAlertDispatcher:
|
||||
mock_telegram_channel: MagicMock,
|
||||
) -> None:
|
||||
"""Test dispatcher initialization."""
|
||||
dispatcher = AlertDispatcher(
|
||||
channels=[mock_discord_channel, mock_telegram_channel]
|
||||
)
|
||||
dispatcher = AlertDispatcher(channels=[mock_discord_channel, mock_telegram_channel])
|
||||
assert len(dispatcher.channels) == 2
|
||||
assert "discord" in dispatcher._circuit_state
|
||||
assert "telegram" in dispatcher._circuit_state
|
||||
@@ -325,9 +321,7 @@ class TestAlertDispatcher:
|
||||
mock_telegram_channel: MagicMock,
|
||||
) -> None:
|
||||
"""Test successful dispatch to all channels."""
|
||||
dispatcher = AlertDispatcher(
|
||||
channels=[mock_discord_channel, mock_telegram_channel]
|
||||
)
|
||||
dispatcher = AlertDispatcher(channels=[mock_discord_channel, mock_telegram_channel])
|
||||
|
||||
result = await dispatcher.dispatch(sample_alert)
|
||||
|
||||
@@ -345,9 +339,7 @@ class TestAlertDispatcher:
|
||||
"""Test dispatch with one channel failing."""
|
||||
mock_telegram_channel.send.return_value = False
|
||||
|
||||
dispatcher = AlertDispatcher(
|
||||
channels=[mock_discord_channel, mock_telegram_channel]
|
||||
)
|
||||
dispatcher = AlertDispatcher(channels=[mock_discord_channel, mock_telegram_channel])
|
||||
|
||||
result = await dispatcher.dispatch(sample_alert)
|
||||
|
||||
@@ -357,9 +349,7 @@ class TestAlertDispatcher:
|
||||
assert result.channel_results["telegram"] is False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dispatch_no_channels(
|
||||
self, sample_alert: FormattedAlert
|
||||
) -> None:
|
||||
async def test_dispatch_no_channels(self, sample_alert: FormattedAlert) -> None:
|
||||
"""Test dispatch with no channels configured."""
|
||||
dispatcher = AlertDispatcher(channels=[])
|
||||
|
||||
@@ -435,9 +425,7 @@ class TestAlertDispatcher:
|
||||
# Now succeed
|
||||
mock_discord_channel.send.return_value = True
|
||||
# Force half-open by resetting last_failure to past
|
||||
dispatcher._circuit_state["discord"].last_failure_time = datetime(
|
||||
2020, 1, 1, tzinfo=UTC
|
||||
)
|
||||
dispatcher._circuit_state["discord"].last_failure_time = datetime(2020, 1, 1, tzinfo=UTC)
|
||||
|
||||
result = await dispatcher.dispatch(sample_alert)
|
||||
|
||||
@@ -465,9 +453,7 @@ class TestAlertDispatcher:
|
||||
mock_telegram_channel: MagicMock,
|
||||
) -> None:
|
||||
"""Test getting circuit status."""
|
||||
dispatcher = AlertDispatcher(
|
||||
channels=[mock_discord_channel, mock_telegram_channel]
|
||||
)
|
||||
dispatcher = AlertDispatcher(channels=[mock_discord_channel, mock_telegram_channel])
|
||||
|
||||
status = dispatcher.get_circuit_status()
|
||||
|
||||
|
||||
@@ -284,17 +284,13 @@ class TestAlertFormatterInit:
|
||||
class TestAlertFormatterFormat:
|
||||
"""Tests for AlertFormatter.format method."""
|
||||
|
||||
def test_format_returns_formatted_alert(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_format_returns_formatted_alert(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that format returns a FormattedAlert."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert isinstance(result, FormattedAlert)
|
||||
|
||||
def test_format_includes_all_fields(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_format_includes_all_fields(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that all fields are populated."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -306,26 +302,20 @@ class TestAlertFormatterFormat:
|
||||
assert result.plain_text != ""
|
||||
assert result.links != {}
|
||||
|
||||
def test_format_title_includes_risk_level(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_format_title_includes_risk_level(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that title includes risk level."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert "HIGH" in result.title
|
||||
|
||||
def test_format_includes_wallet_link(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_format_includes_wallet_link(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that wallet explorer link is included."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert "wallet" in result.links
|
||||
assert "polygonscan.com" in result.links["wallet"]
|
||||
|
||||
def test_format_includes_market_link(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_format_includes_market_link(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that market link is included when slug available."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -336,9 +326,7 @@ class TestAlertFormatterFormat:
|
||||
class TestDiscordEmbed:
|
||||
"""Tests for Discord embed format."""
|
||||
|
||||
def test_embed_has_required_fields(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_embed_has_required_fields(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that embed has required Discord fields."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -349,17 +337,13 @@ class TestDiscordEmbed:
|
||||
assert "fields" in embed
|
||||
assert "footer" in embed
|
||||
|
||||
def test_embed_color_reflects_risk(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_embed_color_reflects_risk(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that embed color matches risk level."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert result.discord_embed["color"] == COLOR_HIGH_RISK
|
||||
|
||||
def test_embed_includes_wallet_field(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_embed_includes_wallet_field(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that embed includes wallet field."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -369,9 +353,7 @@ class TestDiscordEmbed:
|
||||
assert wallet_field is not None
|
||||
assert "0x1234" in wallet_field["value"]
|
||||
|
||||
def test_embed_includes_wallet_age(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_embed_includes_wallet_age(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that wallet age is shown when fresh wallet signal present."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -380,9 +362,7 @@ class TestDiscordEmbed:
|
||||
wallet_field = next((f for f in fields if f["name"] == "Wallet"), None)
|
||||
assert "Age:" in wallet_field["value"]
|
||||
|
||||
def test_embed_includes_trade_details(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_embed_includes_trade_details(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that trade details are in embed."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -393,9 +373,7 @@ class TestDiscordEmbed:
|
||||
assert "BUY" in trade_field["value"]
|
||||
assert "Yes" in trade_field["value"]
|
||||
|
||||
def test_embed_includes_signals_field(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_embed_includes_signals_field(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that signals are listed in embed."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -405,9 +383,7 @@ class TestDiscordEmbed:
|
||||
assert signals_field is not None
|
||||
assert "Fresh Wallet" in signals_field["value"]
|
||||
|
||||
def test_detailed_embed_includes_confidence(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_detailed_embed_includes_confidence(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that detailed mode includes confidence breakdown."""
|
||||
formatter = AlertFormatter(verbosity="detailed")
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -420,34 +396,26 @@ class TestDiscordEmbed:
|
||||
class TestTelegramMarkdown:
|
||||
"""Tests for Telegram markdown format."""
|
||||
|
||||
def test_telegram_includes_header(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_telegram_includes_header(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that Telegram message has header."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert "*Suspicious Activity Detected*" in result.telegram_markdown
|
||||
|
||||
def test_telegram_includes_wallet(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_telegram_includes_wallet(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that Telegram message includes wallet."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert "`0x1234...5678`" in result.telegram_markdown
|
||||
|
||||
def test_telegram_includes_risk_score(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_telegram_includes_risk_score(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that Telegram message includes risk score."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
assert "0.82" in result.telegram_markdown
|
||||
assert "HIGH" in result.telegram_markdown
|
||||
|
||||
def test_telegram_includes_links(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_telegram_includes_links(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that Telegram message includes links."""
|
||||
formatter = AlertFormatter()
|
||||
result = formatter.format(high_risk_assessment)
|
||||
@@ -489,9 +457,7 @@ class TestPlainText:
|
||||
class TestCompactVerbosity:
|
||||
"""Tests for compact verbosity mode."""
|
||||
|
||||
def test_compact_body_is_shorter(
|
||||
self, high_risk_assessment: RiskAssessment
|
||||
) -> None:
|
||||
def test_compact_body_is_shorter(self, high_risk_assessment: RiskAssessment) -> None:
|
||||
"""Test that compact mode produces shorter body."""
|
||||
detailed_formatter = AlertFormatter(verbosity="detailed")
|
||||
compact_formatter = AlertFormatter(verbosity="compact")
|
||||
|
||||
Reference in New Issue
Block a user