"""Pytest configuration and fixtures""" import asyncio import pytest from unittest.mock import AsyncMock, MagicMock import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent / "src")) from sentiment_engine.schemas.payload import NormalizedPayload, SourceType, AssetMention, EngagementMetrics from sentiment_engine.schemas.processed import ProcessedItem, EntityExtraction, SentimentScores, EmotionScores, EventClassification, TemporalAnchor, CredibilityScore, EventType from sentiment_engine.schemas.output import AssetSentiment, MarketSentiment, IndustrySentiment, SentimentOutput, PumpDumpScore, VelocityMetrics, EventFlag @pytest.fixture def event_loop(): """Create event loop for async tests""" loop = asyncio.new_event_loop() yield loop loop.close() @pytest.fixture def sample_payload(): """Sample normalized payload""" return NormalizedPayload( source_id="rss:coindesk.com", source_type=SourceType.NEWS, source_credibility_base=0.85, ingest_ts=1724262300.0, publish_ts=1724262200.0, asset_mentions=[ AssetMention(asset_id="BTC", mention_span=(0, 3), confidence=0.9, source_text="BTC", mention_type="ticker"), AssetMention(asset_id="ETH", mention_span=(10, 13), confidence=0.9, source_text="ETH", mention_type="ticker"), ], raw_text="BTC surges to $65K as ETH follows with strong momentum. Market sentiment turns bullish.", title="Bitcoin Surges to $65K", url="https://coindesk.com/btc-surges", author="John Doe", engagement_metrics=EngagementMetrics(retweets=100, likes=500, replies=50), content_length=200, language="en", metadata={"feed_url": "https://coindesk.com/feed"} ) @pytest.fixture def sample_processed_item(sample_payload): """Sample processed item""" return ProcessedItem( payload_id="test_payload_1", source_id=sample_payload.source_id, source_type=sample_payload.source_type.value, ingest_ts=sample_payload.ingest_ts, publish_ts=sample_payload.publish_ts, entities=[ EntityExtraction(asset_id="BTC", mention_span=(0, 3), confidence=0.9, entity_type="ticker", canonical_name="BTC"), EntityExtraction(asset_id="ETH", mention_span=(10, 13), confidence=0.9, entity_type="ticker", canonical_name="ETH"), ], sentiment_per_asset={ "BTC": SentimentScores(polarity=0.7, confidence=0.85, positive_prob=0.8, negative_prob=0.1, neutral_prob=0.1), "ETH": SentimentScores(polarity=0.5, confidence=0.8, positive_prob=0.7, negative_prob=0.15, neutral_prob=0.15), }, emotions_per_asset={ "BTC": EmotionScores(joy=0.8, fear=0.1, anger=0.05, greed=0.7, sadness=0.05, intensity=0.75), "ETH": EmotionScores(joy=0.6, fear=0.15, anger=0.05, greed=0.5, sadness=0.05, intensity=0.6), }, events=[ EventClassification(event_type=EventType.LISTING, confidence=0.7, assets_involved=["BTC"], key_details={}, severity=0.5), ], temporal=TemporalAnchor(event_time=None, time_horizon="immediate", is_breaking=True, is_scheduled=False), credibility=CredibilityScore(source_base=0.85, content_quality=0.8, engagement_authenticity=0.7, cross_source_corroboration=0.6, historical_accuracy=0.8, composite=0.78), processed_ts=1724262305.0, processing_latency_ms=45.2, model_versions={"finbert": "1.0", "gemma": "3-4b"} ) @pytest.fixture def sample_asset_sentiment(): """Sample asset sentiment output""" return AssetSentiment( asset_id="BTC", fear_state=20.0, greed_state=80.0, sentiment_polarity=60.0, emotion_profile={"joy": 0.8, "fear": 0.1, "anger": 0.05, "greed": 0.7, "sadness": 0.05, "intensity": 0.75}, pump_dump=PumpDumpScore(asset_id="BTC", pump_score=75.0, dump_score=15.0, pump_confidence=0.8, dump_confidence=0.7, coordinating_sources=3, last_update_ts=1724262305.0), event_flags=[EventFlag(event_type="listing", asset_id="BTC", strength=60.0, confidence=0.7, first_seen_ts=1724262300.0, last_seen_ts=1724262305.0, source_count=2)], velocity=VelocityMetrics(hype_velocity=0.7, pub_velocity=0.5, velocity_direction="accelerating", window_minutes=15, source_count=3, unique_assets=1), last_update_ts=1724262305.0, contributing_sources=3, decay_factor=0.95 ) @pytest.fixture def sample_market_sentiment(sample_asset_sentiment): """Sample market sentiment output""" return MarketSentiment( fear_state=25.0, greed_state=75.0, sentiment_index=50.0, hype_velocity=65.0, pub_velocity=55.0, aggregate_pump_risk=75.0, aggregate_dump_risk=20.0, top_pump_assets=["BTC", "ETH", "SOL"], top_dump_assets=[], dominant_events=[], industry_breakdown={}, last_update_ts=1724262305.0, total_sources=10, total_assets=50 ) @pytest.fixture def sample_sentiment_output(sample_market_sentiment, sample_asset_sentiment): """Complete sentiment output""" industry = IndustrySentiment( industry="Smart Contract Platform", assets=["BTC", "ETH"], fear_state=22.0, greed_state=78.0, avg_polarity=55.0, pump_risk=75.0, dump_risk=15.0, dominant_events=[], asset_count=2, last_update_ts=1724262305.0 ) return SentimentOutput( timestamp=1724262305.0, market=sample_market_sentiment, industries={"Smart Contract Platform": industry}, assets={"BTC": sample_asset_sentiment, "ETH": sample_asset_sentiment} )