Add ReputationRadar community contribution (demo replaced by link)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
if str(PROJECT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
@@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
|
||||
from services import llm
|
||||
from services.utils import ServiceWarning
|
||||
|
||||
|
||||
def test_llm_fallback_uses_vader():
|
||||
service = llm.LLMService(api_key=None)
|
||||
results = service.classify_sentiment_batch(
|
||||
["I absolutely love this product!", "This is the worst experience ever."]
|
||||
)
|
||||
assert results[0].label == "positive"
|
||||
assert results[1].label == "negative"
|
||||
|
||||
|
||||
def test_summary_requires_openai_key():
|
||||
service = llm.LLMService(api_key=None)
|
||||
with pytest.raises(ServiceWarning):
|
||||
service.summarize_overall([{"label": "positive", "text": "Example"}])
|
||||
35
community-contributions/Reputation_Radar/tests/test_utils.py
Normal file
35
community-contributions/Reputation_Radar/tests/test_utils.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import datetime as dt
|
||||
|
||||
from services import utils
|
||||
|
||||
|
||||
def test_normalize_items_deduplicates():
|
||||
ts = dt.datetime(2025, 1, 1, tzinfo=dt.timezone.utc)
|
||||
items = [
|
||||
utils.NormalizedItem(
|
||||
source="reddit",
|
||||
id="1",
|
||||
url="https://example.com/a",
|
||||
author="alice",
|
||||
timestamp=ts,
|
||||
text="ReputationRadar is great!",
|
||||
meta={},
|
||||
),
|
||||
utils.NormalizedItem(
|
||||
source="reddit",
|
||||
id="2",
|
||||
url="https://example.com/a",
|
||||
author="bob",
|
||||
timestamp=ts,
|
||||
text="ReputationRadar is great!",
|
||||
meta={},
|
||||
),
|
||||
]
|
||||
cleaned = utils.normalize_items(items)
|
||||
assert len(cleaned) == 1
|
||||
|
||||
|
||||
def test_sanitize_text_removes_html():
|
||||
raw = "<p>Hello <strong>world</strong> <a href='https://example.com'>link</a></p>"
|
||||
cleaned = utils.sanitize_text(raw)
|
||||
assert cleaned == "Hello world link"
|
||||
Reference in New Issue
Block a user